• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript traverse.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中traverse.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: coerceValues

function coerceValues(configData: any) {
    return traverse(configData).forEach(function(value: any) {
        if (this.isLeaf && !_.isUndefined(value)) {
            // Allow env vars to define boolean values
            if (value === 'true') {
                this.update(true);
            }
            else if (value === 'false') {
                this.update(false);
            }
            else if (value === 'undefined') {
                this.update(void 0);
            }
        }
    });
}
开发者ID:NickHeiner,项目名称:lambdascript,代码行数:16,代码来源:index.ts


示例2: if

napkin.addGenerator("text", (obj) => {

    var s = "";

    traverse(obj).forEach(function to_s(node) {

        if (Array.isArray(node)) {
            // this.post(function (child) {
            //    if (!child.isLast) s += ',';
            //});
            //this.after(function () { s += ']' });
        }
        else if (typeof node == 'object') {

            this.before(function () {
                if (node.node) {
                    s += Array(Math.floor(this.level/2)).join("\t") + node.node + "\n";
                }
            });

            //this.pre(function (x, key) {
            //    to_s(key);
            //    s += ':';
            //});

            //this.post(function (child) {
            //    if (!child.isLast) s += ',';
            //});

            //this.after(function () { s += '}' });
        }
        else if (typeof node == 'string') {
            //s += '"' + node.toString().replace(/"/g, '\\"') + '"';
        }
        else {
            s += node.toString();
        }


    });

    return s;

});
开发者ID:joeriks,项目名称:napkin,代码行数:44,代码来源:napkin-generator-text.ts


示例3: traverse

napkin.addGenerator("cs", (obj) => {

    var s = "";

    traverse(obj).forEach(function to_s(node) {

        if (typeof node == 'object') {

            this.before(function () {
                if (node.node) {

                    if (this.level == 1) {
                        s += "namespace " + node.node + " {\n";
                    }
                    if (this.level == 3) {
                        s += "\tpublic class " + node.node + " {\n";
                    }
                    if (this.level == 5) {
                        s += "\t\tpublic string " + node.node + " {get;set;}\n";
                    }

                    
                }
            });

            this.after(function () {
                if (this.level == 1) {
                    s += "}\n";
                }
                if (this.level == 3) {
                    s += "\t}\n";
                }
            });
        }

    });

    return s;

});
开发者ID:joeriks,项目名称:napkin,代码行数:40,代码来源:napkin-generator-cs.ts


示例4: getHighlightedCode

function getHighlightedCode(lscAst: ILambdaScriptAstNode, lambdaScriptCode: string) {
    const codeByLines = _str.lines(lambdaScriptCode),
        colorActions = traverse(lscAst)
            .reduce(function(colorActions: ILineColorAction[], astNode: ILambdaScriptAstNode) {
                const color = colorMap[astNode.type];

                if (color) {
                    const colorFn = chalk[color].bind(chalk),
                        locKey = alternateLocMap[astNode.type] || 'loc',

                        // I'm just using _.result to avoid TS7017
                        loc: ILoc = _.result(astNode, locKey);

                    /**
                     * Originally, I just colored as soon as I found a node. However, this does not work,
                     * because other coloring may have occurred on the line already, which will offset our
                     * column indices. And it is not sufficient just to drop all color from the line and
                     * see what the length difference is, because some of that color could be *after* our
                     * column indices and thus irrelevant. To solve this, we will gather all the colorings
                     * we want to do, and then apply them in sorted order. This makes the offset caclulation trivial.
                     */
                    return colorActions.concat({
                        // I don't know why but jison does not 0-index the line number.
                        lineIndex: loc.first_line - 1,
                        colStart: loc.first_column,
                        colEnd: loc.last_column,
                        colorFn: colorFn
                    });
                }

                return colorActions;
            }, []),

        coloredCode = _(colorActions)
            .sortByAll(['lineIndex', 'colStart'])
            .reduce(function(lines: string[], colorAction: ILineColorAction) {

                const linesClone = _.clone(lines),
                    lineToColor = linesClone[colorAction.lineIndex],

                    existingColorOffset = lineToColor.length - chalk.stripColor(lineToColor).length,

                    colStartWithOffset = colorAction.colStart + existingColorOffset,
                    colEndWithOffset = colorAction.colEnd + existingColorOffset;

                // One potential way to fail fast here would be to detect when we are coloring
                // over an existing highlight. I have yet to encounter a case where that was expected behavior.

                linesClone[colorAction.lineIndex] =
                    lineToColor.slice(0, colStartWithOffset) +
                    colorAction.colorFn(lineToColor.slice(colStartWithOffset, colEndWithOffset)) +
                    lineToColor.slice(colEndWithOffset);

                logger.debug({
                    original: lines[colorAction.lineIndex],
                    colored: linesClone[colorAction.lineIndex]
                }, 'Coloring line');

                return linesClone;
            }, codeByLines);

    return coloredCode.join(os.EOL);
}
开发者ID:NickHeiner,项目名称:lambdascript,代码行数:63,代码来源:get-highlighted-code.ts


示例5: runCommands

function runCommands(objectToParse: idocument): any {

    function cmd_include(filename, type) {

        var included = parseFile(filename, false);

        if (included) {
            var arr = [];
            for (var i = 0; i < included.length; i++) {

                var item = included[i];

                item["included"] = type;

                arr.push(item);

            }

            objectToParse.document = arr.concat(objectToParse.document);
        }

    }

    function cmd_map(filename) {

        var req = require("./" + filename);
        objectToParse = req(objectToParse);

    }

    function cmd_out(filename, type?) {

        if (!type) {
            type = path.extname(filename);
            if (type.indexOf(".") == 0)
                type = type.substring(1);
            else
                type = "text";
        }

        if (!objectToParse.processed) {

            objectToParse.processed = objectToParse.document.slice(0);
            //processAll(objectToParse.processed);

            var newChildArray = [];
            for (var ii in objectToParse.processed) {
                var node = objectToParse.processed[ii];
                if (!(node["included"] && node["included"] == "reference")) {
                    newChildArray.push(objectToParse.processed[ii]);
                } else {
                    console.log("excluded " + node.name);
                }
            }

            objectToParse.processed = newChildArray;

        }

        var formatted = generate(objectToParse.processed, type);

        fs.writeFileSync(filename, formatted);

    }

    traverse(objectToParse.document).forEach(function on_item(item) {
        if (item.name) {

            if (item.name.indexOf("/") == 0) {

                item.isCommand = true;

                if (item.name == "/out") {
                    cmd_out(item.attributes[0]);
                }
                if (item.name == "/reference") {
                    cmd_include(item.attributes[0], "reference");
                }
                if (item.name == "/include") {
                    cmd_include(item.attributes[0], "include");
                }
            }

        }
    });

    //if (objectToParse.commands) {

    //    var commands = objectToParse.commands.splice(0);

    //    for (var c in commands) {

    //        var cmd = commands[c];

    //        if (cmd.type == "include" || cmd.type == "reference") cmd_include(cmd.attributes[0].attr, cmd.type);

    //        if (cmd.type == "map") cmd_map(cmd.attributes[0].attr);

    //        if (cmd.type == "processall") processAll(objectToParse.model);

//.........这里部分代码省略.........
开发者ID:joeriks,项目名称:napkin,代码行数:101,代码来源:napkin.ts


示例6: assignStateDeep

function assignStateDeep(self, callback, stateList, parseFunc, newValue) {
  traverse(self.state).set(stateList, parseFunc(newValue));
  //setState
  self.setState(self.state, callback);
}
开发者ID:my-koop,项目名称:module.core,代码行数:5,代码来源:assignStateDeep.ts



注:本文中的traverse.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript tree.FilePath类代码示例发布时间:2022-05-25
下一篇:
TypeScript trash.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap