How to use string-template - 10 common examples

To help you get started, we’ve selected a few string-template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// to enable using sub routes in our controller we create
    // a new router. This router is a ChildRouter and will delegate
    // all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })
github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// to enable using sub routes in our controller we create
    // a new router. This router is a ChildRouter and will delegate
    // all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })

    controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// a new router. This router is a ChildRouter and will delegate
    // all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })

    controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
        model.get(opts.userId, function (err, user) {
github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })

    controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
        model.get(opts.userId, function (err, user) {
            if (err) {
github 715209 / nginx-obs-automatic-low-bitrate-switching / src / components / Chat.js View on Github external
obsinfo() {
        if (this.obsProps.streamStatus != null) {
            const { fps, kbitsPerSec } = this.obsProps.streamStatus;

            this.say(
                format(this.locale.obsinfo.success, {
                    currentScene: this.obsProps.currentScene,
                    fps: Math.round(fps),
                    bitrate: kbitsPerSec
                })
            );
        } else {
            this.say(this.locale.obsinfo.error);
        }
    }
github 715209 / nginx-obs-automatic-low-bitrate-switching / src / components / Chat.js View on Github external
async switch(sceneName) {
        if (sceneName == null) return this.say(this.locale.switch.error);

        const res = search(sceneName, this.obsProps.scenes, { keySelector: obj => obj.name });
        const scene = res.length > 0 ? res[0].name : sceneName;

        try {
            await this.obs.setCurrentScene({
                "scene-name": scene
            });

            this.say(
                format(this.locale.switch.success, {
                    scene
                })
            );
        } catch (e) {
            log.error(e);
            this.say(e.error);
        }
    }
github javascript-obfuscator / javascript-obfuscator / src / custom-nodes / debug-protection-nodes / DebugProtectionFunctionIntervalNode.ts View on Github external
protected getTemplate (): string {
        return format(DebugProtectionFunctionIntervalTemplate(), {
            debugProtectionFunctionName: this.debugProtectionFunctionName
        });
    }
}
github 715209 / nginx-obs-automatic-low-bitrate-switching / src / components / Chat.js View on Github external
config.twitchChat.alias.map((arr, index) => {
                    if (arr[0] == alias) {
                        config.twitchChat.alias.splice(index);
                        delete this.aliases[alias];
                        this.handleWriteToConfig();
                        this.say(
                            format(this.locale.alias.removed, {
                                alias: alias
                            })
                        );
                        exists = true;
                    }
                });
github 715209 / nginx-obs-automatic-low-bitrate-switching / src / components / Chat.js View on Github external
log.success(`Started recording`);
            } catch (error) {
                this.say(
                    format(`[REC] ${this.locale.rec.error}`, {
                        option: this.locale.rec.started
                    })
                );
            }
        } else {
            try {
                const res = await this.obs.StopRecording();
                if (res.status === "ok") this.say(`[REC] ${this.locale.rec.stopped}`);
                log.success(`Stopped recording`);
            } catch (error) {
                this.say(
                    format(` [REC] ${this.locale.rec.error}`, {
                        option: this.locale.rec.stopped
                    })
                );
            }
        }
    }
github javascript-obfuscator / javascript-obfuscator / src / custom-nodes / domain-lock-nodes / DomainLockNode.ts View on Github external
protected getTemplate (): string {
        const domainsString: string = this.options.domainLock.join(';');
        const [hiddenDomainsString, diff]: string[] = this.cryptUtils.hideString(
            domainsString,
            domainsString.length * 3
        );
        const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval
            ? this.getGlobalVariableTemplate()
            : GlobalVariableNoEvalTemplate();

        return format(DomainLockNodeTemplate(), {
            domainLockFunctionName: this.identifierNamesGenerator.generate(),
            diff: diff,
            domains: hiddenDomainsString,
            globalVariableTemplate,
            singleNodeCallControllerFunctionName: this.callsControllerFunctionName
        });
    }
}

string-template

A simple string template function based on named or indexed arguments

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular string-template functions