json-schema-some
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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'
);

Package Sidebar

Install

npm i json-schema-some

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

5.88 kB

Total Files

5

Last publish

Collaborators

  • grantila