Socket
Socket
Sign inDemoInstall

schema-utils

Package Overview
Dependencies
8
Maintainers
5
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

5

declarations/index.d.ts

@@ -1,2 +0,3 @@

export const validate: typeof import('./validate').validate;
export const ValidationError: typeof import('./ValidationError').default;
import { validate } from "./validate";
import { ValidationError } from "./validate";
export { validate, ValidationError };

8

declarations/keywords/absolutePath.d.ts
export default addAbsolutePathKeyword;
export type Ajv = import('ajv').Ajv;
export type ValidateFunction = import('ajv').ValidateFunction;
export type SchemaUtilErrorObject = import('ajv').ErrorObject & {
children?: import('ajv').ErrorObject[] | undefined;
};
export type Ajv = import("ajv").Ajv;
export type ValidateFunction = import("ajv").ValidateFunction;
export type SchemaUtilErrorObject = import("../validate").SchemaUtilErrorObject;
/**

@@ -8,0 +6,0 @@ *

export function stringHints(schema: Schema, logic: boolean): string[];
export function numberHints(schema: Schema, logic: boolean): string[];
export type Schema =
| (import('json-schema').JSONSchema4 & import('../validate').Extend)
| (import('json-schema').JSONSchema6 & import('../validate').Extend)
| (import('json-schema').JSONSchema7 & import('../validate').Extend);
export type Schema = import("../validate").Schema;

@@ -17,5 +17,5 @@ export = Range;

static getOperator(
side: 'left' | 'right',
side: "left" | "right",
exclusive: boolean
): '>' | '>=' | '<' | '<=';
): ">" | ">=" | "<" | "<=";
/**

@@ -55,10 +55,7 @@ * @param {number} value

*/
static getRangeValue(
values: Array<[number, boolean]>,
logic: boolean
): [number, boolean];
static getRangeValue(values: Array<RangeValue>, logic: boolean): RangeValue;
/** @type {Array<RangeValue>} */
_left: Array<[number, boolean]>;
_left: Array<RangeValue>;
/** @type {Array<RangeValue>} */
_right: Array<[number, boolean]>;
_right: Array<RangeValue>;
/**

@@ -84,2 +81,2 @@ * @param {number} value

type RangeValue = [number, boolean];
type RangeValueCallback = (rangeValue: [number, boolean]) => boolean;
type RangeValueCallback = (rangeValue: RangeValue) => boolean;

@@ -1,5 +0,5 @@

export type JSONSchema4 = import('json-schema').JSONSchema4;
export type JSONSchema6 = import('json-schema').JSONSchema6;
export type JSONSchema7 = import('json-schema').JSONSchema7;
export type ErrorObject = import('ajv').ErrorObject;
export type JSONSchema4 = import("json-schema").JSONSchema4;
export type JSONSchema6 = import("json-schema").JSONSchema6;
export type JSONSchema7 = import("json-schema").JSONSchema7;
export type ErrorObject = import("ajv").ErrorObject;
export type Extend = {

@@ -10,9 +10,7 @@ formatMinimum?: number | undefined;

formatExclusiveMaximum?: boolean | undefined;
link?: string | undefined;
};
export type Schema =
| (import('json-schema').JSONSchema4 & Extend)
| (import('json-schema').JSONSchema6 & Extend)
| (import('json-schema').JSONSchema7 & Extend);
export type SchemaUtilErrorObject = import('ajv').ErrorObject & {
children?: import('ajv').ErrorObject[] | undefined;
export type Schema = (JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend;
export type SchemaUtilErrorObject = ErrorObject & {
children?: Array<ErrorObject>;
};

@@ -39,3 +37,3 @@ export type PostFormatter = (

): void;
import ValidationError from './ValidationError';
import ValidationError from "./ValidationError";
export { ValidationError };
export default ValidationError;
export type JSONSchema6 = import('json-schema').JSONSchema6;
export type JSONSchema7 = import('json-schema').JSONSchema7;
export type Schema =
| (import('json-schema').JSONSchema4 & import('./validate').Extend)
| (import('json-schema').JSONSchema6 & import('./validate').Extend)
| (import('json-schema').JSONSchema7 & import('./validate').Extend);
export type ValidationErrorConfiguration = {
name?: string | undefined;
baseDataPath?: string | undefined;
postFormatter?: import('./validate').PostFormatter | undefined;
};
export type PostFormatter = (
formattedError: string,
error: import('ajv').ErrorObject & {
children?: import('ajv').ErrorObject[] | undefined;
}
) => string;
export type SchemaUtilErrorObject = import('ajv').ErrorObject & {
children?: import('ajv').ErrorObject[] | undefined;
};
export type SPECIFICITY = number;
export type JSONSchema6 = import("json-schema").JSONSchema6;
export type JSONSchema7 = import("json-schema").JSONSchema7;
export type Schema = import("./validate").Schema;
export type ValidationErrorConfiguration =
import("./validate").ValidationErrorConfiguration;
export type PostFormatter = import("./validate").PostFormatter;
export type SchemaUtilErrorObject = import("./validate").SchemaUtilErrorObject;
declare class ValidationError extends Error {

@@ -24,0 +10,0 @@ /**

@@ -6,3 +6,3 @@ "use strict";

ValidationError
} = require('./validate');
} = require("./validate");

@@ -9,0 +9,0 @@ module.exports = {

@@ -28,3 +28,3 @@ "use strict";

schemaPath: undefined,
keyword: 'absolutePath',
keyword: "absolutePath",
params: {

@@ -57,5 +57,5 @@ absolutePath: data

function addAbsolutePathKeyword(ajv) {
ajv.addKeyword('absolutePath', {
ajv.addKeyword("absolutePath", {
errors: true,
type: 'string',
type: "string",

@@ -66,3 +66,3 @@ compile(schema, parentSchema) {

let passes = true;
const isExclamationMarkPresent = data.includes('!');
const isExclamationMarkPresent = data.includes("!");

@@ -69,0 +69,0 @@ if (isExclamationMarkPresent) {

"use strict";
const Range = require('./Range');
const Range = require("./Range");
/** @typedef {import("../validate").Schema} Schema */

@@ -15,3 +15,3 @@

const hints = [];
let type = 'string';
let type = "string";
const currentSchema = { ...schema

@@ -32,17 +32,17 @@ };

if (typeof currentSchema.minLength === 'number') {
if (typeof currentSchema.minLength === "number") {
if (currentSchema.minLength === 1) {
type = 'non-empty string';
type = "non-empty string";
} else {
const length = Math.max(currentSchema.minLength - 1, 0);
hints.push(`should be longer than ${length} character${length > 1 ? 's' : ''}`);
hints.push(`should be longer than ${length} character${length > 1 ? "s" : ""}`);
}
}
if (typeof currentSchema.maxLength === 'number') {
if (typeof currentSchema.maxLength === "number") {
if (currentSchema.maxLength === 0) {
type = 'empty string';
type = "empty string";
} else {
const length = currentSchema.maxLength + 1;
hints.push(`should be shorter than ${length} character${length > 1 ? 's' : ''}`);
hints.push(`should be shorter than ${length} character${length > 1 ? "s" : ""}`);
}

@@ -52,15 +52,15 @@ }

if (currentSchema.pattern) {
hints.push(`should${logic ? '' : ' not'} match pattern ${JSON.stringify(currentSchema.pattern)}`);
hints.push(`should${logic ? "" : " not"} match pattern ${JSON.stringify(currentSchema.pattern)}`);
}
if (currentSchema.format) {
hints.push(`should${logic ? '' : ' not'} match format ${JSON.stringify(currentSchema.format)}`);
hints.push(`should${logic ? "" : " not"} match format ${JSON.stringify(currentSchema.format)}`);
}
if (currentSchema.formatMinimum) {
hints.push(`should be ${currentSchema.formatExclusiveMinimum ? '>' : '>='} ${JSON.stringify(currentSchema.formatMinimum)}`);
hints.push(`should be ${currentSchema.formatExclusiveMinimum ? ">" : ">="} ${JSON.stringify(currentSchema.formatMinimum)}`);
}
if (currentSchema.formatMaximum) {
hints.push(`should be ${currentSchema.formatExclusiveMaximum ? '<' : '<='} ${JSON.stringify(currentSchema.formatMaximum)}`);
hints.push(`should be ${currentSchema.formatExclusiveMaximum ? "<" : "<="} ${JSON.stringify(currentSchema.formatMaximum)}`);
}

@@ -78,18 +78,18 @@

module.exports.numberHints = function numberHints(schema, logic) {
const hints = [schema.type === 'integer' ? 'integer' : 'number'];
const hints = [schema.type === "integer" ? "integer" : "number"];
const range = new Range();
if (typeof schema.minimum === 'number') {
if (typeof schema.minimum === "number") {
range.left(schema.minimum);
}
if (typeof schema.exclusiveMinimum === 'number') {
if (typeof schema.exclusiveMinimum === "number") {
range.left(schema.exclusiveMinimum, true);
}
if (typeof schema.maximum === 'number') {
if (typeof schema.maximum === "number") {
range.right(schema.maximum);
}
if (typeof schema.exclusiveMaximum === 'number') {
if (typeof schema.exclusiveMaximum === "number") {
range.right(schema.exclusiveMaximum, true);

@@ -104,4 +104,4 @@ }

if (typeof schema.multipleOf === 'number') {
hints.push(`should${logic ? '' : ' not'} be multiple of ${schema.multipleOf}`);
if (typeof schema.multipleOf === "number") {
hints.push(`should${logic ? "" : " not"} be multiple of ${schema.multipleOf}`);
}

@@ -108,0 +108,0 @@

@@ -19,7 +19,7 @@ "use strict";

static getOperator(side, exclusive) {
if (side === 'left') {
return exclusive ? '>' : '>=';
if (side === "left") {
return exclusive ? ">" : ">=";
}
return exclusive ? '<' : '<=';
return exclusive ? "<" : "<=";
}

@@ -39,3 +39,3 @@ /**

return `should be ${Range.getOperator('right', exclusive)} ${value}`;
return `should be ${Range.getOperator("right", exclusive)} ${value}`;
}

@@ -55,3 +55,3 @@ /**

return `should be ${Range.getOperator('left', exclusive)} ${value}`;
return `should be ${Range.getOperator("left", exclusive)} ${value}`;
}

@@ -69,6 +69,6 @@ /**

static formatRange(start, end, startExclusive, endExclusive, logic) {
let result = 'should be';
result += ` ${Range.getOperator(logic ? 'left' : 'right', logic ? startExclusive : !startExclusive)} ${start} `;
result += logic ? 'and' : 'or';
result += ` ${Range.getOperator(logic ? 'right' : 'left', logic ? endExclusive : !endExclusive)} ${end}`;
let result = "should be";
result += ` ${Range.getOperator(logic ? "left" : "right", logic ? startExclusive : !startExclusive)} ${start} `;
result += logic ? "and" : "or";
result += ` ${Range.getOperator(logic ? "right" : "left", logic ? endExclusive : !endExclusive)} ${end}`;
return result;

@@ -142,3 +142,3 @@ }

if (!Number.isFinite(start) && !Number.isFinite(end)) {
return '';
return "";
}

@@ -150,3 +150,3 @@

if (realStart === realEnd) {
return `should be ${logic ? '' : '!'}= ${realStart}`;
return `should be ${logic ? "" : "!"}= ${realStart}`;
} // e.g. 4 < x < ∞

@@ -153,0 +153,0 @@

@@ -21,5 +21,5 @@ "use strict";

// Use CommonJS require for ajv libs so TypeScript consumers aren't locked into esModuleInterop (see #110).
const Ajv = require('ajv');
const Ajv = require("ajv");
const ajvKeywords = require('ajv-keywords');
const ajvKeywords = require("ajv-keywords");
/** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */

@@ -39,2 +39,3 @@

* @property {boolean=} formatExclusiveMaximum
* @property {string=} link
*/

@@ -66,3 +67,3 @@

});
ajvKeywords(ajv, ['instanceof', 'formatMinimum', 'formatMaximum', 'patternRequired']); // Custom keywords
ajvKeywords(ajv, ["instanceof", "formatMinimum", "formatMaximum", "patternRequired"]); // Custom keywords

@@ -69,0 +70,0 @@ (0, _absolutePath.default)(ajv);

@@ -11,3 +11,3 @@ "use strict";

numberHints
} = require('./util/hints');
} = require("./util/hints");
/** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */

@@ -118,3 +118,3 @@

while (i > -1 && !schemaPaths.every(predicate)) {
if (children[i].keyword === 'anyOf' || children[i].keyword === 'oneOf') {
if (children[i].keyword === "anyOf" || children[i].keyword === "oneOf") {
const refs = extractRefs(children[i]);

@@ -164,3 +164,3 @@ const childrenStart = findAllChildren(children.slice(0, i), refs.concat(children[i].schemaPath));

if (child.keyword === 'anyOf' || child.keyword === 'oneOf') {
if (child.keyword === "anyOf" || child.keyword === "oneOf") {
const refs = extractRefs(child);

@@ -239,3 +239,3 @@ const childrenStart = findAllChildren(children.slice(0, i), refs.concat(child.schemaPath));

function isObject(maybeObj) {
return typeof maybeObj === 'object' && maybeObj !== null;
return typeof maybeObj === "object" && maybeObj !== null;
}

@@ -249,3 +249,3 @@ /**

function likeNumber(schema) {
return schema.type === 'number' || typeof schema.minimum !== 'undefined' || typeof schema.exclusiveMinimum !== 'undefined' || typeof schema.maximum !== 'undefined' || typeof schema.exclusiveMaximum !== 'undefined' || typeof schema.multipleOf !== 'undefined';
return schema.type === "number" || typeof schema.minimum !== "undefined" || typeof schema.exclusiveMinimum !== "undefined" || typeof schema.maximum !== "undefined" || typeof schema.exclusiveMaximum !== "undefined" || typeof schema.multipleOf !== "undefined";
}

@@ -259,3 +259,3 @@ /**

function likeInteger(schema) {
return schema.type === 'integer' || typeof schema.minimum !== 'undefined' || typeof schema.exclusiveMinimum !== 'undefined' || typeof schema.maximum !== 'undefined' || typeof schema.exclusiveMaximum !== 'undefined' || typeof schema.multipleOf !== 'undefined';
return schema.type === "integer" || typeof schema.minimum !== "undefined" || typeof schema.exclusiveMinimum !== "undefined" || typeof schema.maximum !== "undefined" || typeof schema.exclusiveMaximum !== "undefined" || typeof schema.multipleOf !== "undefined";
}

@@ -269,3 +269,3 @@ /**

function likeString(schema) {
return schema.type === 'string' || typeof schema.minLength !== 'undefined' || typeof schema.maxLength !== 'undefined' || typeof schema.pattern !== 'undefined' || typeof schema.format !== 'undefined' || typeof schema.formatMinimum !== 'undefined' || typeof schema.formatMaximum !== 'undefined';
return schema.type === "string" || typeof schema.minLength !== "undefined" || typeof schema.maxLength !== "undefined" || typeof schema.pattern !== "undefined" || typeof schema.format !== "undefined" || typeof schema.formatMinimum !== "undefined" || typeof schema.formatMaximum !== "undefined";
}

@@ -279,3 +279,3 @@ /**

function likeBoolean(schema) {
return schema.type === 'boolean';
return schema.type === "boolean";
}

@@ -289,3 +289,3 @@ /**

function likeArray(schema) {
return schema.type === 'array' || typeof schema.minItems === 'number' || typeof schema.maxItems === 'number' || typeof schema.uniqueItems !== 'undefined' || typeof schema.items !== 'undefined' || typeof schema.additionalItems !== 'undefined' || typeof schema.contains !== 'undefined';
return schema.type === "array" || typeof schema.minItems === "number" || typeof schema.maxItems === "number" || typeof schema.uniqueItems !== "undefined" || typeof schema.items !== "undefined" || typeof schema.additionalItems !== "undefined" || typeof schema.contains !== "undefined";
}

@@ -299,3 +299,3 @@ /**

function likeObject(schema) {
return schema.type === 'object' || typeof schema.minProperties !== 'undefined' || typeof schema.maxProperties !== 'undefined' || typeof schema.required !== 'undefined' || typeof schema.properties !== 'undefined' || typeof schema.patternProperties !== 'undefined' || typeof schema.additionalProperties !== 'undefined' || typeof schema.dependencies !== 'undefined' || typeof schema.propertyNames !== 'undefined' || typeof schema.patternRequired !== 'undefined';
return schema.type === "object" || typeof schema.minProperties !== "undefined" || typeof schema.maxProperties !== "undefined" || typeof schema.required !== "undefined" || typeof schema.properties !== "undefined" || typeof schema.patternProperties !== "undefined" || typeof schema.additionalProperties !== "undefined" || typeof schema.dependencies !== "undefined" || typeof schema.propertyNames !== "undefined" || typeof schema.patternRequired !== "undefined";
}

@@ -309,3 +309,3 @@ /**

function likeNull(schema) {
return schema.type === 'null';
return schema.type === "null";
}

@@ -320,6 +320,6 @@ /**

if (/^[aeiou]/i.test(type)) {
return 'an';
return "an";
}
return 'a';
return "a";
}

@@ -334,3 +334,3 @@ /**

if (!schema) {
return '';
return "";
}

@@ -340,19 +340,19 @@

if (likeNumber(schema) || likeInteger(schema)) {
return ' | should be any non-number';
return " | should be any non-number";
}
if (likeString(schema)) {
return ' | should be any non-string';
return " | should be any non-string";
}
if (likeArray(schema)) {
return ' | should be any non-array';
return " | should be any non-array";
}
if (likeObject(schema)) {
return ' | should be any non-object';
return " | should be any non-object";
}
}
return '';
return "";
}

@@ -366,3 +366,3 @@ /**

function formatHints(hints) {
return hints.length > 0 ? `(${hints.join(', ')})` : '';
return hints.length > 0 ? `(${hints.join(", ")})` : "";
}

@@ -396,3 +396,3 @@ /**

this.name = 'ValidationError';
this.name = "ValidationError";
/** @type {Array<SchemaUtilErrorObject>} */

@@ -423,6 +423,6 @@

this.headerName = configuration.name || headerNameFromSchema || 'Object';
this.headerName = configuration.name || headerNameFromSchema || "Object";
/** @type {string} */
this.baseDataPath = configuration.baseDataPath || baseDataPathFromSchema || 'configuration';
this.baseDataPath = configuration.baseDataPath || baseDataPathFromSchema || "configuration";
/** @type {PostFormatter | null} */

@@ -444,3 +444,3 @@

getSchemaPart(path) {
const newPath = path.split('/');
const newPath = path.split("/");
let schemaPart = this.schema;

@@ -486,3 +486,3 @@

if (prevSchemas.includes(innerSchema)) {
return '(recursive)';
return "(recursive)";
}

@@ -500,3 +500,3 @@

const needApplyLogicHere = !schema.not.not;
const prefix = logic ? '' : 'non ';
const prefix = logic ? "" : "non ";
newLogic = !logic;

@@ -520,3 +520,3 @@ return needApplyLogicHere ? prefix + formatInnerSchema(schema.not) : formatInnerSchema(schema.not);

*/
item => item === 'Function' ? 'function' : item).join(' | ');
item => item === "Function" ? "function" : item).join(" | ");
}

@@ -527,7 +527,7 @@

/** @type {Array<any>} */
schema.enum.map(item => JSON.stringify(item)).join(' | ')
schema.enum.map(item => JSON.stringify(item)).join(" | ")
);
}
if (typeof schema.const !== 'undefined') {
if (typeof schema.const !== "undefined") {
return JSON.stringify(schema.const);

@@ -539,3 +539,3 @@ }

/** @type {Array<Schema>} */
schema.oneOf.map(item => formatInnerSchema(item, true)).join(' | ')
schema.oneOf.map(item => formatInnerSchema(item, true)).join(" | ")
);

@@ -547,3 +547,3 @@ }

/** @type {Array<Schema>} */
schema.anyOf.map(item => formatInnerSchema(item, true)).join(' | ')
schema.anyOf.map(item => formatInnerSchema(item, true)).join(" | ")
);

@@ -555,3 +555,3 @@ }

/** @type {Array<Schema>} */
schema.allOf.map(item => formatInnerSchema(item, true)).join(' & ')
schema.allOf.map(item => formatInnerSchema(item, true)).join(" & ")
);

@@ -570,3 +570,3 @@ }

schema;
return `${ifValue ? `if ${formatInnerSchema(ifValue)}` : ''}${thenValue ? ` then ${formatInnerSchema(thenValue)}` : ''}${elseValue ? ` else ${formatInnerSchema(elseValue)}` : ''}`;
return `${ifValue ? `if ${formatInnerSchema(ifValue)}` : ""}${thenValue ? ` then ${formatInnerSchema(thenValue)}` : ""}${elseValue ? ` else ${formatInnerSchema(elseValue)}` : ""}`;
}

@@ -580,3 +580,3 @@

const [type, ...hints] = getHints(schema, logic);
const str = `${type}${hints.length > 0 ? ` ${formatHints(hints)}` : ''}`;
const str = `${type}${hints.length > 0 ? ` ${formatHints(hints)}` : ""}`;
return logic ? str : hints.length > 0 ? `non-${type} | ${str}` : `non-${type}`;

@@ -587,8 +587,8 @@ }

const [type, ...hints] = getHints(schema, logic);
const str = `${type}${hints.length > 0 ? ` ${formatHints(hints)}` : ''}`;
return logic ? str : str === 'string' ? 'non-string' : `non-string | ${str}`;
const str = `${type}${hints.length > 0 ? ` ${formatHints(hints)}` : ""}`;
return logic ? str : str === "string" ? "non-string" : `non-string | ${str}`;
}
if (likeBoolean(schema)) {
return `${logic ? '' : 'non-'}boolean`;
return `${logic ? "" : "non-"}boolean`;
}

@@ -601,16 +601,16 @@

if (typeof schema.minItems === 'number') {
hints.push(`should not have fewer than ${schema.minItems} item${schema.minItems > 1 ? 's' : ''}`);
if (typeof schema.minItems === "number") {
hints.push(`should not have fewer than ${schema.minItems} item${schema.minItems > 1 ? "s" : ""}`);
}
if (typeof schema.maxItems === 'number') {
hints.push(`should not have more than ${schema.maxItems} item${schema.maxItems > 1 ? 's' : ''}`);
if (typeof schema.maxItems === "number") {
hints.push(`should not have more than ${schema.maxItems} item${schema.maxItems > 1 ? "s" : ""}`);
}
if (schema.uniqueItems) {
hints.push('should not have duplicate items');
hints.push("should not have duplicate items");
}
const hasAdditionalItems = typeof schema.additionalItems === 'undefined' || Boolean(schema.additionalItems);
let items = '';
const hasAdditionalItems = typeof schema.additionalItems === "undefined" || Boolean(schema.additionalItems);
let items = "";

@@ -621,3 +621,3 @@ if (schema.items) {

/** @type {Array<Schema>} */
schema.items.map(item => formatInnerSchema(item)).join(', ')}`;
schema.items.map(item => formatInnerSchema(item)).join(", ")}`;

@@ -634,7 +634,7 @@ if (hasAdditionalItems) {

// Fallback for empty `items` value
items = 'any';
items = "any";
}
} else {
// "additionalItems" is ignored
items = 'any';
items = "any";
}

@@ -646,3 +646,3 @@

return `[${items}${hasAdditionalItems ? ', ...' : ''}]${hints.length > 0 ? ` (${hints.join(', ')})` : ''}`;
return `[${items}${hasAdditionalItems ? ", ..." : ""}]${hints.length > 0 ? ` (${hints.join(", ")})` : ""}`;
}

@@ -655,8 +655,8 @@

if (typeof schema.minProperties === 'number') {
hints.push(`should not have fewer than ${schema.minProperties} ${schema.minProperties > 1 ? 'properties' : 'property'}`);
if (typeof schema.minProperties === "number") {
hints.push(`should not have fewer than ${schema.minProperties} ${schema.minProperties > 1 ? "properties" : "property"}`);
}
if (typeof schema.maxProperties === 'number') {
hints.push(`should not have more than ${schema.maxProperties} ${schema.minProperties && schema.minProperties > 1 ? 'properties' : 'property'}`);
if (typeof schema.maxProperties === "number") {
hints.push(`should not have more than ${schema.maxProperties} ${schema.minProperties && schema.minProperties > 1 ? "properties" : "property"}`);
}

@@ -666,3 +666,3 @@

const patternProperties = Object.keys(schema.patternProperties);
hints.push(`additional property names should match pattern${patternProperties.length > 1 ? 's' : ''} ${patternProperties.map(pattern => JSON.stringify(pattern)).join(' | ')}`);
hints.push(`additional property names should match pattern${patternProperties.length > 1 ? "s" : ""} ${patternProperties.map(pattern => JSON.stringify(pattern)).join(" | ")}`);
}

@@ -679,4 +679,4 @@

return `${property}${isRequired ? '' : '?'}`;
}).concat(typeof schema.additionalProperties === 'undefined' || Boolean(schema.additionalProperties) ? schema.additionalProperties && isObject(schema.additionalProperties) ? [`<key>: ${formatInnerSchema(schema.additionalProperties)}`] : ['…'] : []).join(', ');
return `${property}${isRequired ? "" : "?"}`;
}).concat(typeof schema.additionalProperties === "undefined" || Boolean(schema.additionalProperties) ? schema.additionalProperties && isObject(schema.additionalProperties) ? [`<key>: ${formatInnerSchema(schema.additionalProperties)}`] : ["…"] : []).join(", ");
const {

@@ -695,3 +695,3 @@ dependencies,

if (Array.isArray(dependency)) {
hints.push(`should have ${dependency.length > 1 ? 'properties' : 'property'} ${dependency.map(dep => `'${dep}'`).join(', ')} when property '${dependencyName}' is present`);
hints.push(`should have ${dependency.length > 1 ? "properties" : "property"} ${dependency.map(dep => `'${dep}'`).join(", ")} when property '${dependencyName}' is present`);
} else {

@@ -716,7 +716,7 @@ hints.push(`should be valid according to the schema ${formatInnerSchema(dependency)} when property '${dependencyName}' is present`);

return `object {${objectStructure ? ` ${objectStructure} ` : ''}}${hints.length > 0 ? ` (${hints.join(', ')})` : ''}`;
return `object {${objectStructure ? ` ${objectStructure} ` : ""}}${hints.length > 0 ? ` (${hints.join(", ")})` : ""}`;
}
if (likeNull(schema)) {
return `${logic ? '' : 'non-'}null`;
return `${logic ? "" : "non-"}null`;
}

@@ -726,3 +726,3 @@

// not logic already applied in formatValidationError
return `${schema.type.join(' | ')}`;
return `${schema.type.join(" | ")}`;
} // Fallback for unknown keywords

@@ -747,3 +747,3 @@ // not logic already applied in formatValidationError

if (!schemaPart) {
return '';
return "";
}

@@ -772,3 +772,3 @@

let schemaText = `${this.formatSchema(schemaPart, logic)}${needDot ? '.' : ''}`;
let schemaText = `${this.formatSchema(schemaPart, logic)}${needDot ? "." : ""}`;

@@ -779,2 +779,6 @@ if (schemaPart.description) {

if (schemaPart.link) {
schemaText += `\n-> Read more at ${schemaPart.link}`;
}
return schemaText;

@@ -790,3 +794,3 @@ }

if (!schemaPart) {
return '';
return "";
}

@@ -799,7 +803,13 @@

let schemaText = "";
if (schemaPart.description) {
return `\n-> ${schemaPart.description}`;
schemaText += `\n-> ${schemaPart.description}`;
}
return '';
if (schemaPart.link) {
schemaText += `\n-> Read more at ${schemaPart.link}`;
}
return schemaText;
}

@@ -820,3 +830,3 @@ /**

switch (keyword) {
case 'type':
case "type":
{

@@ -831,21 +841,21 @@ const {

params.type) {
case 'number':
case "number":
return `${dataPath} should be a ${this.getSchemaPartText(parentSchema, false, true)}`;
case 'integer':
case "integer":
return `${dataPath} should be a ${this.getSchemaPartText(parentSchema, false, true)}`;
case 'string':
case "string":
return `${dataPath} should be a ${this.getSchemaPartText(parentSchema, false, true)}`;
case 'boolean':
case "boolean":
return `${dataPath} should be a ${this.getSchemaPartText(parentSchema, false, true)}`;
case 'array':
case "array":
return `${dataPath} should be an array:\n${this.getSchemaPartText(parentSchema)}`;
case 'object':
case "object":
return `${dataPath} should be an object:\n${this.getSchemaPartText(parentSchema)}`;
case 'null':
case "null":
return `${dataPath} should be a ${this.getSchemaPartText(parentSchema, false, true)}`;

@@ -858,3 +868,3 @@

case 'instanceof':
case "instanceof":
{

@@ -867,3 +877,3 @@ const {

case 'pattern':
case "pattern":
{

@@ -882,3 +892,3 @@ const {

case 'format':
case "format":
{

@@ -897,4 +907,4 @@ const {

case 'formatMinimum':
case 'formatMaximum':
case "formatMinimum":
case "formatMaximum":
{

@@ -914,6 +924,6 @@ const {

case 'minimum':
case 'maximum':
case 'exclusiveMinimum':
case 'exclusiveMaximum':
case "minimum":
case "maximum":
case "exclusiveMinimum":
case "exclusiveMaximum":
{

@@ -938,6 +948,6 @@ const {

return `${dataPath} ${hints.join(' ')}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} ${hints.join(" ")}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}
case 'multipleOf':
case "multipleOf":
{

@@ -956,3 +966,3 @@ const {

case 'patternRequired':
case "patternRequired":
{

@@ -971,3 +981,3 @@ const {

case 'minLength':
case "minLength":
{

@@ -985,10 +995,10 @@ const {

if (limit === 1) {
return `${dataPath} should be an non-empty string${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} should be a non-empty string${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}
const length = limit - 1;
return `${dataPath} should be longer than ${length} character${length > 1 ? 's' : ''}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} should be longer than ${length} character${length > 1 ? "s" : ""}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}
case 'minItems':
case "minItems":
{

@@ -1006,3 +1016,3 @@ const {

if (limit === 1) {
return `${dataPath} should be an non-empty array${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} should be a non-empty array${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}

@@ -1013,3 +1023,3 @@

case 'minProperties':
case "minProperties":
{

@@ -1027,3 +1037,3 @@ const {

if (limit === 1) {
return `${dataPath} should be an non-empty object${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} should be a non-empty object${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}

@@ -1034,3 +1044,3 @@

case 'maxLength':
case "maxLength":
{

@@ -1047,6 +1057,6 @@ const {

const max = limit + 1;
return `${dataPath} should be shorter than ${max} character${max > 1 ? 's' : ''}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} should be shorter than ${max} character${max > 1 ? "s" : ""}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}
case 'maxItems':
case "maxItems":
{

@@ -1065,3 +1075,3 @@ const {

case 'maxProperties':
case "maxProperties":
{

@@ -1080,3 +1090,3 @@ const {

case 'uniqueItems':
case "uniqueItems":
{

@@ -1095,3 +1105,3 @@ const {

case 'additionalItems':
case "additionalItems":
{

@@ -1110,3 +1120,3 @@ const {

case 'contains':
case "contains":
{

@@ -1116,6 +1126,6 @@ const {

} = error;
return `${dataPath} should contains at least one ${this.getSchemaPartText(parentSchema, ['contains'])} item${getSchemaNonTypes(parentSchema)}.`;
return `${dataPath} should contains at least one ${this.getSchemaPartText(parentSchema, ["contains"])} item${getSchemaNonTypes(parentSchema)}.`;
}
case 'required':
case "required":
{

@@ -1128,3 +1138,3 @@ const {

/** @type {import("ajv").DependenciesParams} */
params.missingProperty.replace(/^\./, '');
params.missingProperty.replace(/^\./, "");
const hasProperty = parentSchema && Boolean(

@@ -1135,6 +1145,6 @@ /** @type {Schema} */

parentSchema.properties[missingProperty]);
return `${dataPath} misses the property '${missingProperty}'${getSchemaNonTypes(parentSchema)}.${hasProperty ? ` Should be:\n${this.getSchemaPartText(parentSchema, ['properties', missingProperty])}` : this.getSchemaPartDescription(parentSchema)}`;
return `${dataPath} misses the property '${missingProperty}'${getSchemaNonTypes(parentSchema)}.${hasProperty ? ` Should be:\n${this.getSchemaPartText(parentSchema, ["properties", missingProperty])}` : this.getSchemaPartDescription(parentSchema)}`;
}
case 'additionalProperties':
case "additionalProperties":
{

@@ -1153,3 +1163,3 @@ const {

case 'dependencies':
case "dependencies":
{

@@ -1166,3 +1176,3 @@ const {

params;
const dependencies = deps.split(',').map(
const dependencies = deps.split(",").map(
/**

@@ -1172,7 +1182,7 @@ * @param {string} dep

*/
dep => `'${dep.trim()}'`).join(', ');
dep => `'${dep.trim()}'`).join(", ");
return `${dataPath} should have properties ${dependencies} when property '${property}' is present${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
}
case 'propertyNames':
case "propertyNames":
{

@@ -1192,3 +1202,3 @@ const {

case 'enum':
case "enum":
{

@@ -1210,3 +1220,3 @@ const {

case 'const':
case "const":
{

@@ -1219,7 +1229,7 @@ const {

case 'not':
case "not":
{
const postfix = likeObject(
/** @type {Schema} */
error.parentSchema) ? `\n${this.getSchemaPartText(error.parentSchema)}` : '';
error.parentSchema) ? `\n${this.getSchemaPartText(error.parentSchema)}` : "";
const schemaOutput = this.getSchemaPartText(error.schema, false, false, false);

@@ -1235,7 +1245,7 @@

} = error;
return `${dataPath} should not be ${this.getSchemaPartText(schema, false, true)}${parentSchema && likeObject(parentSchema) ? `\n${this.getSchemaPartText(parentSchema)}` : ''}`;
return `${dataPath} should not be ${this.getSchemaPartText(schema, false, true)}${parentSchema && likeObject(parentSchema) ? `\n${this.getSchemaPartText(parentSchema)}` : ""}`;
}
case 'oneOf':
case 'anyOf':
case "oneOf":
case "anyOf":
{

@@ -1269,3 +1279,3 @@ const {

*/
nestedError => ` * ${indent(this.formatValidationError(nestedError), ' ')}`).join('\n')}`;
nestedError => ` * ${indent(this.formatValidationError(nestedError), " ")}`).join("\n")}`;
}

@@ -1276,3 +1286,3 @@

case 'if':
case "if":
{

@@ -1291,3 +1301,3 @@ const {

case 'absolutePath':
case "absolutePath":
{

@@ -1330,4 +1340,4 @@ const {

return ` - ${indent(formattedError, ' ')}`;
}).join('\n');
return ` - ${indent(formattedError, " ")}`;
}).join("\n");
}

@@ -1334,0 +1344,0 @@

{
"name": "schema-utils",
"version": "3.0.0",
"version": "3.1.0",
"description": "webpack Validation Utils",

@@ -27,7 +27,10 @@ "license": "MIT",

"commitlint": "commitlint --from=master",
"security": "npm audit",
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different",
"security": "npm audit --production",
"fmt:check": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different",
"lint:js": "eslint --cache .",
"lint:types": "tsc --pretty --noEmit",
"lint": "npm-run-all -l -p \"lint:**\"",
"lint": "npm-run-all lint:js lint:types fmt:check",
"fmt": "npm run fmt:check -- --write",
"fix:js": "npm run lint:js -- --fix",
"fix": "npm-run-all fix:js fmt",
"test:only": "cross-env NODE_ENV=test jest",

@@ -38,5 +41,4 @@ "test:watch": "npm run test:only -- --watch",

"test": "npm run test:coverage",
"prepare": "npm run build",
"release": "standard-version",
"defaults": "webpack-defaults"
"prepare": "npm run build && husky install",
"release": "standard-version"
},

@@ -48,28 +50,28 @@ "files": [

"dependencies": {
"@types/json-schema": "^7.0.7",
"ajv": "^6.12.5",
"ajv-keywords": "^3.5.2",
"@types/json-schema": "^7.0.6"
"ajv-keywords": "^3.5.2"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@webpack-contrib/defaults": "^6.3.0",
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^26.5.0",
"cross-env": "^7.0.2",
"babel-jest": "^27.0.6",
"cross-env": "^7.0.3",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-import": "^2.22.1",
"husky": "^4.3.0",
"jest": "^26.5.0",
"lint-staged": "^10.4.0",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"husky": "^6.0.0",
"jest": "^27.0.6",
"lint-staged": "^11.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"typescript": "^4.0.3"
"prettier": "^2.3.2",
"standard-version": "^9.3.0",
"typescript": "^4.3.4",
"webpack": "^5.41.1"
},

@@ -76,0 +78,0 @@ "keywords": [

@@ -49,7 +49,7 @@ <div align="center">

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
const options = { option: true };
const configuration = { name: 'Loader Name/Plugin Name/Name' };
const configuration = { name: "Loader Name/Plugin Name/Name" };

@@ -87,8 +87,8 @@ validate(schema, options, configuration);

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
const options = { foo: 'bar' };
const options = { foo: "bar" };
validate(schema, { name: 123 }, { name: 'MyPlugin' });
validate(schema, { name: 123 }, { name: "MyPlugin" });
```

@@ -128,8 +128,8 @@

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
const options = { foo: 'bar' };
const options = { foo: "bar" };
validate(schema, options, { name: 'MyPlugin' });
validate(schema, options, { name: "MyPlugin" });
```

@@ -150,8 +150,8 @@

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
const options = { foo: 'bar' };
const options = { foo: "bar" };
validate(schema, options, { name: 'MyPlugin', baseDataPath: 'options' });
validate(schema, options, { name: "MyPlugin", baseDataPath: "options" });
```

@@ -172,11 +172,11 @@

```js
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
const options = { foo: 'bar' };
const options = { foo: "bar" };
validate(schema, options, {
name: 'MyPlugin',
name: "MyPlugin",
postFormatter: (formattedError, error) => {
if (error.keyword === 'type') {
if (error.keyword === "type") {
return `${formattedError}\nAdditional Information.`;

@@ -228,6 +228,6 @@ }

```js
import { getOptions } from 'loader-utils';
import { validate } from 'schema-utils';
import { getOptions } from "loader-utils";
import { validate } from "schema-utils";
import schema from 'path/to/schema.json';
import schema from "path/to/schema.json";

@@ -238,4 +238,4 @@ function loader(src, map) {

validate(schema, options, {
name: 'Loader Name',
baseDataPath: 'options',
name: "Loader Name",
baseDataPath: "options",
});

@@ -252,5 +252,5 @@

```js
import { validate } from 'schema-utils';
import { validate } from "schema-utils";
import schema from 'path/to/schema.json';
import schema from "path/to/schema.json";

@@ -260,4 +260,4 @@ class Plugin {

validate(schema, options, {
name: 'Plugin Name',
baseDataPath: 'options',
name: "Plugin Name",
baseDataPath: "options",
});

@@ -264,0 +264,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc