json-schema-describes-subset
Version:
Tools for static JSON schema analysis, including functions to determine if one schema describes a subset of another or if a schema describes the empty set or to convert a schema to its disjunctive normal form (DNF).
28 lines • 831 B
JavaScript
import intersection from 'lodash/intersection.js';
import difference from 'lodash/difference.js';
export const allJSONSchemaTypes = [
'null',
'number',
/* no `'integer'` => will be represented as
* `{ type: 'number', multipleOf: 1 }` */
'string',
'boolean',
'array',
'object',
];
export function isJSONSchemaType(value) {
const validValues = allJSONSchemaTypes;
return validValues.includes(value);
}
/**
* Returns an array of the provided elements that are {@link JSONSchemaType}s.
* The elements of the returned array are unique.
*
*/
export function filterJSONSchemaTypes(strings) {
return intersection(allJSONSchemaTypes, strings);
}
export function getOtherJSONSchemaTypes(types) {
return difference(allJSONSchemaTypes, types);
}
//# sourceMappingURL=json-schema-type.js.map