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

skhema

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skhema - npm Package Compare versions

Comparing version 2.4.1 to 2.5.0-schema-only-option-3536e75a128f7b79d13727d3a5562df48e6f9d00

4

CHANGELOG.md

@@ -7,2 +7,6 @@ # Change Log

## v2.5.0 - 2018-10-11
* Validate against just the schema if `options.schemaOnly` is true [Lucian Buzzo]
## v2.4.1 - 2018-10-09

@@ -9,0 +13,0 @@

22

lib/index.d.ts
import { JSONSchema6 } from 'json-schema';
export interface FilterOptions {
// force no additional properties
export interface MatchOptions {
// Custom formats to add validation for
customFormats?: {
[format: string]: (value: any) => boolean;
};
// Only validate the schema
schemaOnly?: boolean;
// Additional keywords to use (see https://github.com/epoberezkin/ajv-keywords)
keywords?: string[];
}
export interface FilterOptions extends MatchOptions {
// Force no additional properties
force: boolean;

@@ -10,11 +21,12 @@ }

export declare function isValid(schema: JSONSchema6, value: any): boolean;
export declare function isValid(schema: JSONSchema6, value: any, options?: MatchOptions): boolean;
export declare function match(schema: JSONSchema6, value: any): {
export declare function match(schema: JSONSchema6, value: any, options?: MatchOptions): {
valid: boolean;
errors: string[];
score: number;
};
export declare function validate(schema: JSONSchema6, value: any): void;
export declare function validate(schema: JSONSchema6, value: any, options?: MatchOptions): void;
export declare function filter<T = any>(schema: JSONSchema6, value: any, options?: FilterOptions): Partial<T> | null;

@@ -422,2 +422,4 @@ /*

* @param {customFormats} [options.customFormats={}] - custom formats
* @param {String[]} [options.keywords] - additional keywords to use (see https://github.com/epoberezkin/ajv-keywords)
* @param {Boolean} [options.schemaOnly=false] - Only validate the schema
* @returns {Object} results

@@ -471,3 +473,3 @@ *

const valid = ajv.validate('object', object)
const valid = options.schemaOnly ? true : ajv.validate('object', object)

@@ -496,2 +498,3 @@ return {

* @param {String[]} [options.keywords] - additional keywords to use (see https://github.com/epoberezkin/ajv-keywords)
* @param {Boolean} [options.schemaOnly=false] - Only validate the schema
* @returns {Boolean} whether the object matches the schema

@@ -521,4 +524,3 @@ *

* valid or if the object doesn't validate against the schema. If you just want
* to validate a schema, you don't need to pass an object as the second
* parameter.
* to validate a schema, you use the `schemaOnly` option.
*

@@ -530,2 +532,3 @@ * @param {Object} schema - JSON schema

* @param {String[]} [options.keywords] - additional keywords to use (see https://github.com/epoberezkin/ajv-keywords)
* @param {Boolean} [options.schemaOnly=false] - Only validate the schema
*

@@ -704,2 +707,3 @@ * @example

* @param {String[]} [options.keywords] - additional keywords to use (see https://github.com/epoberezkin/ajv-keywords)
* @param {Boolean} [options.schemaOnly=false] - Only validate the schema
* @returns {(Object|Null)} filtered object

@@ -706,0 +710,0 @@ *

{
"name": "skhema",
"version": "2.4.1",
"version": "2.5.0-schema-only-option-3536e75a128f7b79d13727d3a5562df48e6f9d00",
"description": "JSON Schema utility collection",

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

@@ -28,2 +28,3 @@ skhema

* [.IncompatibleSchemas](#module_skhema.IncompatibleSchemas) : <code>Error</code>
* [.scoreMatch(schema, object)](#module_skhema.scoreMatch) ⇒ <code>Number</code>
* [.match(schema, object, [options])](#module_skhema.match) ⇒ <code>Object</code>

@@ -49,2 +50,28 @@ * [.isValid(schema, object, [options])](#module_skhema.isValid) ⇒ <code>Boolean</code>

**Access**: public
<a name="module_skhema.scoreMatch"></a>
### skhema.scoreMatch(schema, object) ⇒ <code>Number</code>
Score a matching object and schema based on specificity. Only
works with values that are valid against the provided schema
**Kind**: static method of [<code>skhema</code>](#module_skhema)
**Summary**: Score a schema match by specificity
**Returns**: <code>Number</code> - score
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| schema | <code>Object</code> | JSON schema |
| object | <code>Object</code> | object |
**Example**
```js
const score = skhema.scoreMatch({
type: 'object'
}, {
foo: 'bar'
})
console.log(result) // -> 1
```
<a name="module_skhema.match"></a>

@@ -64,2 +91,4 @@

| [options.customFormats] | <code>customFormats</code> | <code>{}</code> | custom formats |
| [options.keywords] | <code>Array.&lt;String&gt;</code> | | additional keywords to use (see https://github.com/epoberezkin/ajv-keywords) |
| [options.schemaOnly] | <code>Boolean</code> | <code>false</code> | Only validate the schema |

@@ -98,2 +127,3 @@ **Example**

| [options.keywords] | <code>Array.&lt;String&gt;</code> | | additional keywords to use (see https://github.com/epoberezkin/ajv-keywords) |
| [options.schemaOnly] | <code>Boolean</code> | <code>false</code> | Only validate the schema |

@@ -115,4 +145,8 @@ **Example**

### skhema.validate(schema, object, [options])
The `.validate()` method will throw if the provided schema isn't
valid or if the object doesn't validate against the schema. If you just want
to validate a schema, you use the `schemaOnly` option.
**Kind**: static method of [<code>skhema</code>](#module_skhema)
**Summary**: Validate an object and throw if invalid
**Summary**: Validate an object and schema and throw if invalid
**Access**: public

@@ -127,2 +161,3 @@

| [options.keywords] | <code>Array.&lt;String&gt;</code> | | additional keywords to use (see https://github.com/epoberezkin/ajv-keywords) |
| [options.schemaOnly] | <code>Boolean</code> | <code>false</code> | Only validate the schema |

@@ -186,2 +221,3 @@ **Example**

| [options.keywords] | <code>Array.&lt;String&gt;</code> | | additional keywords to use (see https://github.com/epoberezkin/ajv-keywords) |
| [options.schemaOnly] | <code>Boolean</code> | <code>false</code> | Only validate the schema |

@@ -188,0 +224,0 @@ **Example**

@@ -251,6 +251,14 @@ /*

ava.test('.validate() should not throw if the schema is valid', (test) => {
ava.test('.validate() with options.schemaOnly should not throw if the schema is valid', (test) => {
test.notThrows(() => {
skhema.validate({
type: 'object'
type: 'object',
properties: {
foo: {
type: 'string'
}
},
require: [ 'foo' ]
}, null, {
schemaOnly: true
})

@@ -260,2 +268,19 @@ })

ava.test('.validate() with options.schemaOnly should throw if the schema is invalid', (test) => {
test.throws(() => {
skhema.validate({
type: 'object',
properties: {
foo: {
type: 'string',
enum: [ 'a', 'a' ]
}
},
require: [ 'foo' ]
}, null, {
schemaOnly: true
})
})
})
ava.test('.validate() should throw if there is a single error', (test) => {

@@ -262,0 +287,0 @@ test.throws(() => {

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