當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.string.default類代碼示例

本文整理匯總了TypeScript中underscore.string.default的典型用法代碼示例。如果您正苦於以下問題:TypeScript string.default類的具體用法?TypeScript string.default怎麽用?TypeScript string.default使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了string.default類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: findRule

    export function findRule(name: string, rulesDirectory?: string) {
        var camelizedName = transformName(name);

        // first check for core rules
        var Rule = loadRule(CORE_RULES_DIRECTORY, camelizedName);
        if (Rule) {
            return Rule;
        }

        // then check for rules within the first level of rulesDirectory
        if (rulesDirectory) {
            Rule = loadRule(rulesDirectory, camelizedName);
            if (Rule) {
                return Rule;
            }
        }

        // finally check for rules within the first level of directories,
        // using dash prefixes as the sub-directory names
        if (rulesDirectory) {
            var subDirectory = _s.strLeft(rulesDirectory, "-");
            var ruleName = _s.strRight(rulesDirectory, "-");
            if (subDirectory !== rulesDirectory && ruleName !== rulesDirectory) {
                camelizedName = transformName(ruleName);
                Rule = loadRule(rulesDirectory, subDirectory, camelizedName);
                if (Rule) {
                    return Rule;
                }
            }
        }

        return undefined;
    }
開發者ID:CalvinFernandez,項目名稱:tslint,代碼行數:33,代碼來源:ruleLoader.ts

示例2: Date

        inquirer.prompt(prompts).then(answers => {
            if (!answers.moveon) {
                return;
            }

            let today = new Date(),
                year = today.getFullYear().toString();

            answers.appVersion = [
                'v0',
                year.slice(2),
                (today.getMonth() + 1) + padLeft(today.getDate())
            ].join('.');
            answers.appNameSlug = _.slugify(answers.appName);
            answers.appTitle = startCase(answers.appName).split(' ').join('');
            answers.appYear = year;

            gulp.src([
                `${__dirname}/../templates/common/**`,
                `${__dirname}/../templates/${answers.projectType}-package/**`
            ])
                .pipe(template(answers))
                .pipe(rename(file => {
                    if (file.basename[0] === '_') {
                        file.basename = '.' + file.basename.slice(1);
                    }
                }))
                .pipe(conflict('./'))
                .pipe(gulp.dest('./'))
                .on('end', () => {
                    this.log.info(`Successfully created LabShare ${answers.projectType} package...`);
                });
        });
開發者ID:LabShare,項目名稱:lsc,代碼行數:33,代碼來源:package.ts

示例3: transformName

 function transformName(name: string) {
     // camelize strips out leading and trailing underscores and dashes, so make sure they aren't passed to camelize
     // the regex matches the groups (leading underscores and dashes)(other characters)(trailing underscores and dashes)
     var nameMatch = name.match(/^([-_]*)(.*?)([-_]*)$/);
     if (nameMatch == null) {
         return name + "Rule";
     }
     return nameMatch[1] + _s.camelize(nameMatch[2]) + nameMatch[3] + "Rule";
 }
開發者ID:CalvinFernandez,項目名稱:tslint,代碼行數:9,代碼來源:ruleLoader.ts

示例4: findFormatter

    export function findFormatter(name: string, formattersDirectory?: string) {
        var camelizedName = _s.camelize(name + "Formatter");

        // first check for core formatters
        var Formatter = loadFormatter(CORE_FORMATTERS_DIRECTORY, camelizedName);
        if (Formatter) {
            return Formatter;
        }

        // then check for rules within the first level of rulesDirectory
        if (formattersDirectory) {
            Formatter = loadFormatter(formattersDirectory, camelizedName);
            if (Formatter) {
                return Formatter;
            }
        }

        // else try to resolve as module
        return loadFormatterModule(name);
    }
開發者ID:Bartvds,項目名稱:tslint,代碼行數:20,代碼來源:formatterLoader.ts

示例5: normalize

///<reference path='node/node.d.ts' />
var _: any = require('underscore');
var str: any = require('underscore.string');

// Mix in non-conflict functions to Underscore namespace if you want
_.mixin(str.exports());

function normalize(text: string): string {
    return _.trim(text.replace(/(\r\n)/g, '\n').replace(/(\r)/g, '\n'));
}

export function isCorrect(actual, expected) {
  console.log(normalize(expected));
  console.log(normalize(actual));
  return normalize(actual) === normalize(expected);
};
開發者ID:TakenokoChocoHolic,項目名稱:CodeTengoku,代碼行數:16,代碼來源:judge.ts

示例6: 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


注:本文中的underscore.string.default類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。