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


TypeScript Arr.cast方法代码示例

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


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

示例1: getParameterOption

    public getParameterOption(values: string | string[], defaultValue = false, onlyParams = false) {
        values = Arr.cast(values);

        const tokens = [...this.tokens];

        while (tokens.length) {
            const token = tokens.shift()!;

            if (onlyParams && "--" === token) {
                return false;
            }

            for (const value of values) {
                if (token === value) {
                    return tokens.shift();
                }

                // Options with values:
                //   For long options, test for '--option=' at beginning
                //   For short options, test for '-o' at beginning
                const leading = value.startsWith("--") ? value + "=" : value;
                if ("" !== leading && token.startsWith(leading)) {
                    return token.substr(leading.length);
                }
            }
        }

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

示例2: toString

    public toString() {
        const params: string[] = [];

        for (const [param, val] of this.parameters) {
            if (param && "-" === param[0]) {
                for (const v of Arr.cast(val)) {
                    if (v) {
                        params.push(param + "=" + this.escapeToken(v));
                    } else {
                        params.push(param);
                    }
                }
            } else {
                const value = Arr.cast(val)
                    .map((v) => this.escapeToken(v))
                    .join(" ");

                params.push(value);
            }
        }

        return params.join(" ");
    }
开发者ID:sirian,项目名称:node-component-console,代码行数:23,代码来源:RecordInput.ts

示例3: getParameterOption

    public getParameterOption(values: string | string[], defaultValue = false, onlyParams: boolean = false) {
        values = Arr.cast(values);

        for (const [k, v] of this.parameters) {
            if (onlyParams && (k === "--" || (Var.isNumber(k) && "--" === v))) {
                return false;
            }

            if (Var.isNumber(k)) {
                if (values.includes(v)) {
                    return true;
                }
            } else if (values.includes(k)) {
                return v;
            }
        }

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

示例4: hasParameterOption

    public hasParameterOption(values: string | string[], onlyParams: boolean = false): boolean {
        values = Arr.cast(values);

        for (let [k, v] of this.parameters) {
            if (!Var.isNumber(k)) {
                v = k;
            }

            if (onlyParams && "--" === v) {
                return false;
            }

            if (values.includes(v)) {
                return true;
            }
        }

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

示例5: hasParameterOption

    public hasParameterOption(values: string | string[], onlyParams = false) {
        values = Arr.cast(values);

        for (const token of this.tokens) {
            if (onlyParams && "--" === token) {
                return false;
            }

            for (const value of values) {
                // Options with values:
                //   For long options, test for '--option=' at beginning
                //   For short options, test for '-o' at beginning
                const leading = value.startsWith("--") ? value + "=" : value;

                if (token === value || ("" !== leading && token.startsWith(leading))) {
                    return true;
                }
            }
        }

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

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

示例7: writeText

    protected writeText(content: string | string[]) {
        const str = Arr.cast(content).map(Var.stringify).join("");
        this.write(str, true);

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

示例8: 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.Arr.cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。