本文整理汇总了TypeScript中@angular-devkit/core.json.isJsonArray方法的典型用法代码示例。如果您正苦于以下问题:TypeScript json.isJsonArray方法的具体用法?TypeScript json.isJsonArray怎么用?TypeScript json.isJsonArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/core.json
的用法示例。
在下文中一共展示了json.isJsonArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parseJsonSchemaToSubCommandDescription
export async function parseJsonSchemaToSubCommandDescription(
name: string,
jsonPath: string,
registry: json.schema.SchemaRegistry,
schema: json.JsonObject,
logger: logging.Logger,
): Promise<SubCommandDescription> {
const options = await parseJsonSchemaToOptions(registry, schema);
const aliases: string[] = [];
if (json.isJsonArray(schema.$aliases)) {
schema.$aliases.forEach(value => {
if (typeof value == 'string') {
aliases.push(value);
}
});
}
if (json.isJsonArray(schema.aliases)) {
schema.aliases.forEach(value => {
if (typeof value == 'string') {
aliases.push(value);
}
});
}
if (typeof schema.alias == 'string') {
aliases.push(schema.alias);
}
let longDescription = '';
if (typeof schema.$longDescription == 'string' && schema.$longDescription) {
const ldPath = resolve(dirname(jsonPath), schema.$longDescription);
try {
longDescription = readFileSync(ldPath, 'utf-8');
} catch (e) {
logger.warn(`File ${ldPath} was not found while constructing the subcommand ${name}.`);
}
}
let usageNotes = '';
if (typeof schema.$usageNotes == 'string' && schema.$usageNotes) {
const unPath = resolve(dirname(jsonPath), schema.$usageNotes);
try {
usageNotes = readFileSync(unPath, 'utf-8');
} catch (e) {
logger.warn(`File ${unPath} was not found while constructing the subcommand ${name}.`);
}
}
const description = '' + (schema.description === undefined ? '' : schema.description);
return {
name,
description,
...(longDescription ? { longDescription } : {}),
...(usageNotes ? { usageNotes } : {}),
options,
aliases,
};
}
示例2: visitor
function visitor(
current: json.JsonObject | json.JsonArray,
pointer: json.schema.JsonPointer,
parentSchema?: json.JsonObject | json.JsonArray,
) {
if (!parentSchema) {
// Ignore root.
return;
} else if (pointer.split(/\/(?:properties|items|definitions)\//g).length > 2) {
// Ignore subitems (objects or arrays).
return;
} else if (json.isJsonArray(current)) {
return;
}
if (pointer.indexOf('/not/') != -1) {
// We don't support anyOf/not.
throw new Error('The "not" keyword is not supported in JSON Schema.');
}
const ptr = json.schema.parseJsonPointer(pointer);
const name = ptr[ptr.length - 1];
if (ptr[ptr.length - 2] != 'properties') {
// Skip any non-property items.
return;
}
const typeSet = json.schema.getTypesOfSchema(current);
if (typeSet.size == 0) {
throw new Error('Cannot find type of schema.');
}
// We only support number, string or boolean (or array of those), so remove everything else.
const types = [...typeSet].filter(x => {
switch (x) {
case 'boolean':
case 'number':
case 'string':
return true;
case 'array':
// Only include arrays if they're boolean, string or number.
if (json.isJsonObject(current.items)
&& typeof current.items.type == 'string'
&& ['boolean', 'number', 'string'].includes(current.items.type)) {
return true;
}
return false;
default:
return false;
}
}).map(x => _getEnumFromValue(x, OptionType, OptionType.String));
if (types.length == 0) {
// This means it's not usable on the command line. e.g. an Object.
return;
}
// Only keep enum values we support (booleans, numbers and strings).
const enumValues = (json.isJsonArray(current.enum) && current.enum || []).filter(x => {
switch (typeof x) {
case 'boolean':
case 'number':
case 'string':
return true;
default:
return false;
}
}) as Value[];
let defaultValue: string | number | boolean | undefined = undefined;
if (current.default !== undefined) {
switch (types[0]) {
case 'string':
if (typeof current.default == 'string') {
defaultValue = current.default;
}
break;
case 'number':
if (typeof current.default == 'number') {
defaultValue = current.default;
}
break;
case 'boolean':
if (typeof current.default == 'boolean') {
defaultValue = current.default;
}
break;
}
}
const type = types[0];
const $default = current.$default;
const $defaultIndex = (json.isJsonObject($default) && $default['$source'] == 'argv')
? $default['index'] : undefined;
//.........这里部分代码省略.........