本文整理汇总了TypeScript中@sirian/common.Var.isArray方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Var.isArray方法的具体用法?TypeScript Var.isArray怎么用?TypeScript Var.isArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@sirian/common.Var
的用法示例。
在下文中一共展示了Var.isArray方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: formatDefaultValue
protected formatDefaultValue(defaultValue: undefined | string | string[]) {
if (Var.isArray(defaultValue)) {
defaultValue = defaultValue.map((value) => Formatter.escape(value));
return JSON.stringify(defaultValue).replace(/\\\\/g, "\\");
} else {
return Formatter.escape(defaultValue);
}
}
示例2: addOptions
public addOptions(options: Record<string, Option> | Option[]) {
if (Var.isArray(options)) {
for (const option of options) {
this.addOption(option.getName(), option);
}
} else {
for (const [name, option] of KV.entries(options)) {
this.addOption(name, option);
}
}
return this;
}
示例3: describeArgument
public describeArgument(argument: Argument, options: IDescribeOptions = {}) {
const defaultValue = argument.getDefaultValue();
const desc = [
argument.getDescription(),
];
if (Var.isArray(defaultValue) || StrUtil.width(defaultValue)) {
desc.push(`<comment> [default: ${this.formatDefaultValue(defaultValue)}]</comment>`);
}
return [`<info>${argument.getName()}</info>`, desc.join("")];
}
示例4: addArguments
public addArguments(args: Record<string, Argument> | Argument[]) {
if (Var.isArray(args)) {
for (const argument of args) {
this.addArgument(argument.getName(), argument);
}
} else {
for (const [name, argument] of KV.entries(args)) {
this.addArgument(name, argument);
}
}
return this;
}
示例5:
public static values<T>(value: T): KVValues<T> {
if (Var.isNullable(value)) {
return [] as KVValues<T>;
}
if (Var.hasMethod(value, "values")) {
return [...value.values()] as KVValues<T>;
}
if (Var.isArray(value)) {
return [...value] as KVValues<T>;
}
return Obj.values(value) as KVValues<T>;
}
示例6: constructor
constructor(definition: Array<Argument | Option> | Partial<InputDefinitionInit> = {}) {
this.arguments = new Map();
this.options = new Map();
this.shortcuts = new Map();
if (Var.isArray(definition)) {
const args = definition.filter(Arg.InstanceOf(Argument));
this.setArguments(args);
const options = definition.filter(Arg.InstanceOf(Option));
this.setOptions(options);
} else {
this.setArguments(definition.arguments || {});
this.setOptions(definition.options || {});
}
}
示例7: normalizeDefaultValue
protected normalizeDefaultValue(defaultValue: any) {
if (this.isValueRequired() && undefined !== defaultValue) {
throw new LogicError("Cannot set a default value for required option");
}
if (this.isMultiple()) {
if (undefined === defaultValue) {
return [];
}
if (!Var.isArray(defaultValue)) {
throw new LogicError("A default value for an multiple option must be an array.");
}
}
return defaultValue;
}
示例8: parseShortcuts
public static parseShortcuts(shortcut?: string | string[]) {
if (Var.isNullable(shortcut)) {
return [];
}
const shortcuts = Var.isArray(shortcut) ? shortcut : shortcut.split("|");
const result = new Set<string>();
for (const str of shortcuts) {
result.add(str.replace(/^-+/, ""));
}
if (!result.size) {
throw new InvalidArgumentError("An option shortcut cannot be empty.");
}
return [...result];
}
示例9: getCompletions
public getCompletions(text: string) {
const options = this.options;
if (!options.autocomplete) {
const choices = this.getChoices();
const autocomplete = [];
if (!Var.isArray(choices)) {
const keys = KV.keys(choices);
autocomplete.push(...keys);
}
const values = KV.values(choices).map(Var.stringify);
autocomplete.push(...values);
options.autocomplete = autocomplete;
}
return super.getCompletions(text);
}
示例10: describeOption
public describeOption(option: Option, options: IDescribeOptions = {}) {
const defaultValue = option.getDefault();
const desc = [option.getDescription()];
if (option.acceptValue() && undefined !== defaultValue && (!Var.isArray(defaultValue) || defaultValue.length)) {
desc.push(`<comment> [default: ${this.formatDefaultValue(defaultValue)}]</comment>`);
}
const synopsis = option.getSynopsis();
const allowedValues = option.getAllowedValues();
if (allowedValues.length) {
const str = allowedValues.map(Var.stringify).join(", ");
desc.push(` (Allowed values: <comment>${str}</comment>)`);
}
return [
`<info>${synopsis}</info>`,
desc.join(""),
];
}