当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Var.stringify方法代码示例

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


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

示例1: normalize

    public normalize(selected: string) {
        const choices = this.getChoices();

        const strChoice = Var.stringify(selected);

        for (const [key, choice] of KV.entries(choices)) {
            if (Var.stringify(key) === strChoice) {
                return choice;
            }
        }

        const values = new Set<T>();

        for (const choice of KV.values(choices)) {
            if (Var.stringify(choice) === strChoice) {
                values.add(choice);
            }
        }

        switch (values.size) {
            case 0:
                throw new InvalidArgumentError(`Value "${strChoice}" is invalid`);
            case 1:
                return [...values][0];
            default:
                throw new InvalidArgumentError(`Value "${strChoice}" is ambiguous`);
        }
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:28,代码来源:ChoiceQuestion.ts

示例2: constructor

 constructor(init: IParameterInit<T>) {
     this.name = Var.stringify(init.name);
     this.description = Var.stringify(init.description);
     this.defaultValue = init.defaultValue;
     this.normalizer = init.normalizer;
     this.validator = init.validator;
     this.multiple = !!init.multiple;
     this.allowedValues = init.allowedValues || [];
 }
开发者ID:sirian,项目名称:node-component-console,代码行数:9,代码来源:Parameter.ts

示例3: getCommandAliasesText

    protected getCommandAliasesText(definition: CommandDefinition) {
        const aliases = definition.getAliases();

        if (!aliases.length) {
            return "";
        }

        const text = aliases.join("|");
        return Var.stringify(`[${text}]`);
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:10,代码来源:TextDescriptor.ts

示例4: constructor

    constructor(...args: any[]) {
        const init = Option.resolveArgs<T>(args);

        super(init);

        this.name = Var.stringify(this.name).replace(/^-+/, "");
        this.shortcuts = Option.parseShortcuts(init.shortcut);
        this.required = Boolean(init.required);
        this.valueRequired = Boolean(init.valueRequired) || this.required;
        this.default = init.default;
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:11,代码来源:Option.ts

示例5: splitByWidth

    public static splitByWidth(str: string, width: number) {
        str = Var.stringify(str);
        if (this.width(str) <= width) {
            return [str];
        }

        const graphemes = Unicode.getGraphemes(str);

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

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

示例7: getCompletions

    public getCompletions(text: string): string[] {
        const values = this.options.autocomplete;

        if (!values) {
            return [];
        }

        const set = new Set<string>();
        for (const value of values) {
            const str = Var.stringify(value);
            if (str.startsWith(text)) {
                set.add(str);
            }
        }

        return [...set];
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:17,代码来源:AbstractQuestion.ts

示例8: write

    public write(messages: string | string[] = [], init: Partial<IOutputWriteOptions> = {}) {
        const options = {
            type: OutputType.NORMAL,
            verbosity: OutputVerbosity.NORMAL,
            newline: 0,
            ...init,
        };

        messages = Arr.cast(messages);

        if (options.verbosity > this.getVerbosity()) {
            return this;
        }

        const formatter = this.getFormatter();

        for (let message of messages) {
            message = Var.stringify(message);

            switch (options.type) {
                case OutputType.PLAIN:
                    message = StrUtil.stripTags(formatter.decorate(message));
                    break;
                case OutputType.RAW:
                    break;
                case OutputType.NORMAL:
                default:
                    message = formatter.decorate(message);
                    break;
            }
            this.doWrite(message);

            this.newLine(options.newline);
        }

        return this;
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:37,代码来源:Output.ts

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

示例10: setName

 public setName(name: string) {
     this.name = Var.stringify(name);
     return this;
 }
开发者ID:sirian,项目名称:node-component-console,代码行数:4,代码来源:Parameter.ts


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