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

TypeScript common.Str类代码示例

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

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



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

示例1: getProcessedHelp

    public getProcessedHelp() {
        const tokens = {
            "%name%": this.name,
        };

        return Str.replace(this.help, tokens);
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:7,代码来源:CommandDefinition.ts


示例2: getSynopsis

    public getSynopsis() {
        const messages = [super.getSynopsis()];

        const choices = this.getChoices();

        const keys: any[] = KV.keys(choices); // todo: remove any[], typescript issue at keys.map
        const widths = keys.map((key: any) => StrUtil.width(key));

        const width = Math.max(...widths);

        for (const [key, value] of KV.entries(choices)) {
            const k = Var.stringify(key);
            messages.push(`  [<comment>${Str.padLeft(k, width)}</comment>] ${value}`);
        }
        return messages.join("\n");
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:16,代码来源:ChoiceQuestion.ts


示例3: getNames

    public getNames(ns: string = "") {
        const commands = new XSet<string>();

        const names = [...this.commands.keys()];
        if (this.commandLoader) {
            names.push(...this.commandLoader.getNames());
        }

        for (const name of names) {
            if (!ns || ns === this.extractNamespace(name, Str.substringCount(ns, ":") + 1)) {
                commands.add(name);
            }
        }

        return commands.toArray();
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:16,代码来源:Application.ts


示例4: renderError

    public renderError(e: Error) {
        const stack = ErrorStackParser.parse(e);

        const output = this.errorOutput;

        let len = 0;
        let title = "";

        const message = Var.stringify(e.message).trim();

        if ("" === message || output.isVerbose()) {
            title = `  [${e.name || e.constructor.name}]  `;
            len = StrUtil.width(title);
        }

        const width = output.getWidth();
        const lines: Array<[string, number]> = [];

        if (message) {
            for (const line of message.split(/\r?\n/)) {
                for (const chunk of StrUtil.splitByWidth(line, width - 4)) {
                    const lineLength = StrUtil.width(chunk) + 4;
                    lines.push([chunk, lineLength]);
                    if (lineLength > len) {
                        len = lineLength;
                    }
                }
            }
        }

        const messages = [];

        const emptyLine = `<error>${StrUtil.spaces(len)}</error>`;

        messages.push(emptyLine);

        if ("" === message || output.isVerbose()) {
            messages.push(`<error>${Str.padRight(title, len)}</error>`);
        }

        for (const [line, lineLength] of lines) {
            messages.push(`<error>  ${Formatter.escape(line)}  ${StrUtil.spaces(len - lineLength)}</error>`);
        }

        messages.push(emptyLine);
        messages.push("");

        if (output.isVerbose() && stack.length) {
            messages.push("<comment>Error trace:</comment>");

            for (const frame of stack) {
                const fn = frame.functionName || "{anonymous}";
                const args = (frame.args || []).join(", ");
                const file = frame.fileName || "";
                const line = frame.lineNumber;
                const col = frame.columnNumber;

                messages.push(
                    Formatter.format(`  %s(%s) at <info>%s</info> <comment>%d:%d</comment>`, fn, args, file, line, col),
                );
            }
            messages.push("");
            messages.push("");
        }

        output.writeln(messages, {verbosity: OutputVerbosity.QUIET});
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:67,代码来源:IO.ts


示例5:

 .map((a) => Str.padRight(a.join(""), width, " "));
开发者ID:sirian,项目名称:node-component-console,代码行数:1,代码来源:StrUtil.ts


示例6: find

    public async find(name: string) {
        const commands = this.commands;
        const commandNames = [...commands.keys()];
        if (this.commandLoader) {
            commandNames.push(...this.commandLoader.getNames());
        }

        const expr = name.replace(/([^:]+|)/, (text) => Rgx.escape(text) + "[^:]*");

        const re = new RegExp("^" + expr);
        const rei = new RegExp("^" + expr, "i");
        let found = commandNames.filter((c) => re.test(c));

        if (!found.length) {
            found.push(...commandNames.filter((c) => rei.test(c)));
        }

        // if no found matched or we just matched namespaces
        if (!found.length || !found.filter((c) => rei.test(c)).length) {
            if (name.includes(":")) {
                // check if a namespace exists and contains found
                const pos = name.indexOf(":");
                this.findNamespace(name.substr(0, pos));
            }

            let message = `Command "${name}" is not defined.`;

            const alternatives = this.findAlternatives(name, commandNames);
            if (alternatives.length) {
                if (1 === alternatives.length) {
                    message += "\n\nDid you mean this?\n    ";
                } else {
                    message += "\n\nDid you mean one of these?\n    ";
                }
                message += alternatives.join("\n    ");
            }

            throw new CommandNotFoundError(message, alternatives);
        }

        const aliases = new Map();

        // filter out aliases for found which are already on the list
        if (found.length > 1) {
            const filteredCommands = new Set<string>();

            for (const nameOrAlias of found) {
                let commandName = nameOrAlias;

                if (commands.has(nameOrAlias)) {
                    const command = commands.get(nameOrAlias)!;
                    commandName = command.getDefinition().getName();
                }

                aliases.set(nameOrAlias, commandName);

                if (commandName === nameOrAlias || !found.includes(commandName)) {
                    filteredCommands.add(nameOrAlias);
                }
            }

            found = [...filteredCommands];
        }

        const exact = found.includes(name) || aliases.has(name);

        if (found.length > 1 && !exact) {
            const widths = found.map((abbr) => StrUtil.width(abbr));
            const maxLen = Math.max(...widths);

            const abbrevs = [];
            for (const cmdName of found) {
                const command = await this.getCommand(cmdName);

                const description = command.getDefinition().getDescription();
                const abbr = sprintf("%s %s", Str.padRight(cmdName, maxLen), description);
                abbrevs.push(abbr);
            }

            const suggestions = this.getAbbreviationSuggestions(abbrevs);

            throw new CommandNotFoundError(
                `Command "${name}" is ambiguous.\nDid you mean one of these?\n${suggestions}`,
                found,
            );
        }

        return this.getCommand(exact ? name : found[0]);
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:89,代码来源:Application.ts


示例7: render

    public render(messages: string | string[]) {
        messages = Arr.cast(messages);
        const options = this.options;

        const padding = options.padding || [];
        const padTop = padding.length > 0 ? padding[0] : 0;
        const padRight = padding.length > 1 ? padding[1] : padTop;
        const padBottom = padding.length > 2 ? padding[2] : padTop;
        const padLeft = padding.length > 3 ? padding[3] : padRight;

        const lines: string[] = [];
        const output = this.output;
        const formatter = output.getFormatter();

        const type = Var.stringify(options.type);
        const typeWidth = type ? StrUtil.width(type) + 1 : 0;

        const maxMessageWidth = Math.max(
            options.minWidth,
            ...messages.map((msg) => formatter.widthWithoutDecoration(msg)),
        );

        const maxWidth = Math.min(
            output.getWidth(),
            options.maxWidth,
            maxMessageWidth + typeWidth + padRight + padLeft,
        );

        const chunkWidth = maxWidth - typeWidth - padLeft - padRight;

        for (const message of messages) {
            const chunks = StrUtil.splitByWidth(message, chunkWidth);

            for (const chunk of chunks) {
                const prefix = 0 === lines.length ? type : "";

                const parts = [
                    StrUtil.spaces(padLeft),
                    Str.padRight(prefix, typeWidth),
                    Str.padRight(chunk, chunkWidth),
                    StrUtil.spaces(padRight),
                ];

                lines.push(parts.join(""));
            }
        }

        const emptyLine = StrUtil.spaces(maxWidth);

        if (output.isDecorated()) {
            for (let i = 0; i < padTop; i++) {
                lines.unshift(emptyLine);
            }
            for (let i = 0; i < padBottom; i++) {
                lines.push(emptyLine);
            }
        }

        for (const line of lines) {
            const text = Formatter.formatText(line, options.style);

            output.writeln(text);
        }
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:64,代码来源:Block.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript common.Var类代码示例发布时间:2022-05-28
下一篇:
TypeScript common.Obj类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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