1.0.0 • Published 3 years ago

json-schema-some v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

npm version downloads build status coverage status Language grade: JavaScript Node.JS version

json-schema-some

Array.prototype.some for JSON Schema.

This package uses json-schema-traverse and exports a function some. This function gets an object as argument, and is expected to return a boolean. If it returns true, some returns true, otherwise false.

The argument the callback gets is an object containing the arguments array provided in the callback to traverse in json-schema-traverse. Check that documentation for further information. The object form is:

interface CallbackArgument
{
	schema: SchemaObject;
	jsonPtr: string;
	rootSchema: SchemaObject;
	parentJsonPtr?: string;
	parentKeyword?: string;
	parentSchema?: SchemaObject;
	keyIndex?: string | number;
}

where SchemaObject is a valid JSON Schema object.

Example

import { some } from 'json-schema-some'

// Returns true if any schema object in the schemaObject tree is of type
// 'object', with 'properties' and a property called 'firstName'
const hasFirstName = some( schemaObject, ( { parentKeyword, keyIndex } ) =>
  parentKeyword === 'properties' && keyIndex === 'firstName'
);