New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-library

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-library - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "json-schema-library",
"version": "1.0.0",
"version": "1.0.1",
"description": "Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -33,22 +33,19 @@ # json-schema-library

| method | parameter | description
| ----------------- | ------------------------------------- | -------------------------------------
| constructor | schema | pass the root schema in the constructor
| get rootSchema | | or pass the root schema as property like
| set rootSchema | rootSchema | `instance.rootSchema = require("./json-schema.json")`
| each | schema, data, callback, pointer = "#" | Iterates over the data, passing value and its schema
| step | key, schema, data, pointer = "#" | step into a json-schema by the given key (property or index)
| validate | schema, data, pointer = "#" | return a list of errors found validating the data
| isValid | schema, data, pointer = "#" | returns true if the data is validated by the json-schema
| resolveOneOf | schema, data, pointer = "#" | returns the oneOf-schema for the passed data
| resolveRef | schema | resolves a $ref on a given schema-object
| getSchema | schema, data, pointer = "#" | returns the json schema of the given data-json-pointer
| getTemplate | schema, data | returns a template object based of the given json-schema
| method | parameter | description
| ----------------- | --------------------------------- | -------------------------------------------------------------
| constructor | schema | pass the root schema in the constructor or add it on rootSchema
| each | schema, data, callback, [pointer] | Iterates over the data, passing value and its schema
| step | key, schema, data, [pointer] | step into a json-schema by the given key (property or index)
| validate | schema, data, [pointer] | return a list of errors found validating the data
| isValid | schema, data, [pointer] | returns true if the data is validated by the json-schema
| resolveOneOf | schema, data, [pointer] | returns the oneOf-schema for the passed data
| resolveRef | schema | resolves a $ref on a given schema-object
| getSchema | schema, data, [pointer] | returns the json schema of the given data-json-pointer
| getTemplate | schema, data | returns a template object based of the given json-schema
#### examples
#### Examples
##### getSchema(core, schema, pointer, data)
return the json 'schema' matching 'data' at 'pointer'. Should be modified to use a step/next-function, which is already
Returns the json 'schema' matching 'data' at 'pointer'. Should be modified to use a step/next-function, which is already
within the logic (advance VS retrieve from root -> support both)

@@ -70,8 +67,9 @@

##### getTemplate(core, schema, data, rootSchema = schema)
return data which is valid to the given json-schema. Additionally, a data object may be given, which will be
Returns data which is valid to the given json-schema. Additionally, a data object may be given, which will be
extended by any missing items or properties.
```js
const baseData = getTemplate(
const Core = require("json-schema-library").cores.Draft04;
const core = new Core();
const baseData = core.getTemplate(
{ type: "object", properties: { target: { type: "string", default: "v" } } },

@@ -82,20 +80,18 @@ { other: true }

##### validate(data, schema, step)
##### validate(core, data, schema, step)
Validate data and get a list of validation errors
returns a list of validation errors
```js
const core = new require("json-schema-library").core.draft04(rootSchema),
const baseSchema = core.validate({ type: "number" }, "");
// returns false
// alternatively use core.validate({ type: "number" }, "")
const Core = require("json-schema-library").cores.Draft04;
const core = new Core(rootSchema);
const errors = core.validate({ type: "number" }, "");
// returns [TypeError]
```
##### isValid(data, schema, step)
##### isValid(core, data, schema, step)
Return true if the given schema validates the data
returns true if the given schema validates the data
```js
const core = new require("json-schema-library").core.draft04(rootSchema),
const Core = require("json-schema-library").cores.Draft04;
const core = new Core(rootSchema);
const baseSchema = core.isValid({ type: "number" }, "");

@@ -105,8 +101,8 @@ // returns false

##### step(key, schema, data, rootSchema = schema)
##### step(core, key, schema, data, rootSchema = schema)
Get the child schema of a property or index
returns the child schema found at the given key
```js
const core = new require("json-schema-library").core.draft04(rootSchema),
const Core = require("json-schema-library").cores.Draft04;
const core = new Core(rootSchema);
const baseSchema = core.step(

@@ -117,12 +113,10 @@ { type: "object", properties: { target: {type: "string"}} },

); // returns {type: "string"}
// alternatively use core.step({ type: "object", properties: { target: {type: "string"}} }, { target: "value" }, "target")
```
##### each(data, schema, callback)
##### each(core, data, schema, callback)
Iterate over each item (object, array and value), passing each value and its corresponding schema
calls the callback on each item (object, array and value), passing the current schema and its data
```js
const rootSchema = {
const Core = require("json-schema-library").cores.Draft04;
const core = new Core({
type: "array",

@@ -133,8 +127,7 @@ items: [

]
};
const core = new require("json-schema-library").core.draft04(rootSchema),
});
core.each(core.rootSchema, [5, "nine"], (schema, value, pointer) => {
// 1. schema = { type: "array", items: [...] }, data = [5, "nine"], pointer = #
// 2. schema = { type: "number" }, data = 5, pointer = #/0
// 3. schema = { type: "string" }, data = "nine", pointer = #/1
// 1. schema = { type: "array", items: [...] }, data = [5, "nine"], pointer = #
// 2. schema = { type: "number" }, data = 5, pointer = #/0
// 3. schema = { type: "string" }, data = "nine", pointer = #/1
});

@@ -147,5 +140,4 @@ ```

#### SchemaService(schema)
Retrieve the json-schema at the given json-pointer
binds the schema to getSchema.
```js

@@ -157,5 +149,4 @@ const schemaService = new SchemaService(rootSchema); // default core 'draft04'

#### createSchemaOf(data)
Creates a json-schema for the given input-data.
returns a json schema which is valid against data.
```js

@@ -162,0 +153,0 @@ const baseSchema = getTemplate({ target: "" });

@@ -7,2 +7,3 @@ # Tasks

- [ ] -- Features -- Improve validation maps to add & hook (!) custom entries
- [ ] -- Features -- Helper to find a json- and json-schema-pointer

@@ -9,0 +10,0 @@ **Milestone** add remaining draft04 features

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc