Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonpolice

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonpolice - npm Package Compare versions

Comparing version 10.0.1 to 11.0.0

9

dist/errors.js

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationError = exports.SchemaError = void 0;
class SchemaError extends Error {
export class SchemaError extends Error {
constructor(scope, type, info) {

@@ -12,4 +9,3 @@ super(type);

}
exports.SchemaError = SchemaError;
class ValidationError extends Error {
export class ValidationError extends Error {
constructor(path, scope, type, errors) {

@@ -40,3 +36,2 @@ super(type);

}
exports.ValidationError = ValidationError;
//# sourceMappingURL=errors.js.map

@@ -1,8 +0,8 @@

import { Schema } from './schema';
import { SchemaOptions } from './types';
import { Schema } from './schema.js';
import { SchemaOptions } from './types.js';
export * from 'jsonref';
export * from './errors';
export * from './schema';
export * from './types';
export * from './errors.js';
export * from './schema.js';
export * from './types.js';
export declare function create(dataOrUri: any, opts: SchemaOptions): Promise<Schema>;
export default create;

@@ -1,28 +0,10 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = void 0;
const schema_1 = require("./schema");
__exportStar(require("jsonref"), exports);
__exportStar(require("./errors"), exports);
__exportStar(require("./schema"), exports);
__exportStar(require("./types"), exports);
function create(dataOrUri, opts) {
return schema_1.StaticSchema.create(dataOrUri, opts);
import { StaticSchema } from './schema.js';
export * from 'jsonref';
export * from './errors.js';
export * from './schema.js';
export * from './types.js';
export function create(dataOrUri, opts) {
return StaticSchema.create(dataOrUri, opts);
}
exports.create = create;
exports.default = create;
export default create;
//# sourceMappingURL=index.js.map

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

import { SchemaError } from './errors';
import { SchemaOptions, ValidationOptions } from './types';
import { SchemaError } from './errors.js';
import { SchemaOptions, ValidationOptions } from './types.js';
export declare abstract class Schema {

@@ -4,0 +4,0 @@ protected _validators: Set<string>;

@@ -1,32 +0,6 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticSchema = exports.Schema = void 0;
const refs = __importStar(require("jsonref"));
const _ = __importStar(require("lodash"));
const errors_1 = require("./errors");
const utils_1 = require("./utils");
class Schema {
import * as refs from 'jsonref';
import _ from 'lodash';
import { SchemaError, ValidationError } from './errors.js';
import { testRegExp } from './utils.js';
export class Schema {
get validators() {

@@ -79,3 +53,3 @@ if (!this._validators) {

else if (spec === false) {
throw new errors_1.ValidationError(path, scope, 'false');
throw new ValidationError(path, scope, 'false');
}

@@ -108,3 +82,3 @@ else {

else {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'multiple', errors);
throw new ValidationError(path, Schema.scope(spec), 'multiple', errors);
}

@@ -145,3 +119,3 @@ }

if (!found) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'type');
throw new ValidationError(path, Schema.scope(spec), 'type');
}

@@ -155,3 +129,3 @@ return data;

else if (typeof spec.enum.find((v) => _.isEqual(v, data)) === 'undefined') {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'enum');
throw new ValidationError(path, Schema.scope(spec), 'enum');
}

@@ -165,3 +139,3 @@ return data;

else if (!_.isEqual(spec.const, data)) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'const');
throw new ValidationError(path, Schema.scope(spec), 'const');
}

@@ -176,3 +150,3 @@ return data;

else if (data % spec.multipleOf !== 0) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'multipleOf');
throw new ValidationError(path, Schema.scope(spec), 'multipleOf');
}

@@ -188,3 +162,3 @@ }

else if (data > spec.maximum) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'maximum');
throw new ValidationError(path, Schema.scope(spec), 'maximum');
}

@@ -200,3 +174,3 @@ }

else if (data >= spec.exclusiveMaximum) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'exclusiveMaximum');
throw new ValidationError(path, Schema.scope(spec), 'exclusiveMaximum');
}

@@ -212,3 +186,3 @@ }

else if (data < spec.minimum) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'minimum');
throw new ValidationError(path, Schema.scope(spec), 'minimum');
}

@@ -224,3 +198,3 @@ }

else if (data <= spec.exclusiveMinimum) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'exclusiveMinimum');
throw new ValidationError(path, Schema.scope(spec), 'exclusiveMinimum');
}

@@ -236,3 +210,3 @@ }

else if (data.length > spec.maxLength) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'maxLength');
throw new ValidationError(path, Schema.scope(spec), 'maxLength');
}

@@ -248,3 +222,3 @@ }

else if (data.length < spec.minLength) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'minLength');
throw new ValidationError(path, Schema.scope(spec), 'minLength');
}

@@ -261,4 +235,4 @@ }

}
else if (!(0, utils_1.testRegExp)(spec.pattern, data)) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'pattern');
else if (!testRegExp(spec.pattern, data)) {
throw new ValidationError(path, Schema.scope(spec), 'pattern');
}

@@ -282,3 +256,3 @@ }

case 'date-time':
if (!(0, utils_1.testRegExp)(spec.format, data)) {
if (!testRegExp(spec.format, data)) {
throw Schema.error(spec, 'format');

@@ -295,3 +269,3 @@ }

case 'uri':
if (!(0, utils_1.testRegExp)(spec.format, data)) {
if (!testRegExp(spec.format, data)) {
throw Schema.error(spec, 'format');

@@ -330,3 +304,3 @@ }

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'items', errors);
throw new ValidationError(path, Schema.scope(spec), 'items', errors);
}

@@ -350,3 +324,3 @@ }

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'additionalItems', errors);
throw new ValidationError(path, Schema.scope(spec), 'additionalItems', errors);
}

@@ -362,3 +336,3 @@ }

else if (data.length > spec.maxItems) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'maxItems');
throw new ValidationError(path, Schema.scope(spec), 'maxItems');
}

@@ -374,3 +348,3 @@ }

else if (data.length < spec.minItems) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'minItems');
throw new ValidationError(path, Schema.scope(spec), 'minItems');
}

@@ -386,3 +360,3 @@ }

else if (spec.uniqueItems && _.uniqWith(data, _.isEqual).length !== data.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'uniqueItems');
throw new ValidationError(path, Schema.scope(spec), 'uniqueItems');
}

@@ -403,3 +377,3 @@ }

if (!found) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'contains');
throw new ValidationError(path, Schema.scope(spec), 'contains');
}

@@ -415,3 +389,3 @@ }

else if (Object.keys(data).length > spec.maxProperties) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'maxProperties');
throw new ValidationError(path, Schema.scope(spec), 'maxProperties');
}

@@ -427,3 +401,3 @@ }

else if (Object.keys(data).length < spec.minProperties) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'minProperties');
throw new ValidationError(path, Schema.scope(spec), 'minProperties');
}

@@ -445,3 +419,3 @@ }

(typeof spec.properties?.[i]?.writeOnly === 'undefined' || (spec.properties[i].writeOnly === true && opts.context !== 'read'))) {
throw new errors_1.ValidationError(`${path}/${i}`, Schema.scope(spec), 'required');
throw new ValidationError(`${path}/${i}`, Schema.scope(spec), 'required');
}

@@ -480,3 +454,3 @@ }

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'properties', errors);
throw new ValidationError(path, Schema.scope(spec), 'properties', errors);
}

@@ -494,3 +468,3 @@ }

for (let p in spec.patternProperties) {
if ((0, utils_1.testRegExp)(p, i)) {
if (testRegExp(p, i)) {
try {

@@ -512,3 +486,3 @@ if ((opts.context === 'write' && spec.patternProperties[p].readOnly === true) ||

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'patternProperties', errors);
throw new ValidationError(path, Schema.scope(spec), 'patternProperties', errors);
}

@@ -522,3 +496,3 @@ }

for (let i in data) {
if ((!spec.properties || !spec.properties[i]) && (!spec.patternProperties || !Object.keys(spec.patternProperties).find((p) => (0, utils_1.testRegExp)(p, i)))) {
if ((!spec.properties || !spec.properties[i]) && (!spec.patternProperties || !Object.keys(spec.patternProperties).find((p) => testRegExp(p, i)))) {
try {

@@ -544,3 +518,3 @@ if ((opts.context === 'write' && spec.additionalProperties.readOnly === true) ||

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'additionalProperties', errors);
throw new ValidationError(path, Schema.scope(spec), 'additionalProperties', errors);
}

@@ -564,3 +538,3 @@ }

else if (!(j in data)) {
errors.push(new errors_1.ValidationError(`${path}/dependencies/${i}`, Schema.scope(spec.dependencies[i]), 'dependencies'));
errors.push(new ValidationError(`${path}/dependencies/${i}`, Schema.scope(spec.dependencies[i]), 'dependencies'));
}

@@ -580,3 +554,3 @@ }

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'dependencies', errors);
throw new ValidationError(path, Schema.scope(spec), 'dependencies', errors);
}

@@ -599,3 +573,3 @@ }

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'propertyNames', errors);
throw new ValidationError(path, Schema.scope(spec), 'propertyNames', errors);
}

@@ -634,3 +608,3 @@ }

if (errors.length) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'allOf', errors);
throw new ValidationError(path, Schema.scope(spec), 'allOf', errors);
}

@@ -652,3 +626,3 @@ return data;

if (!found) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'anyOf');
throw new ValidationError(path, Schema.scope(spec), 'anyOf');
}

@@ -672,3 +646,3 @@ return data;

if (found !== 1) {
throw new errors_1.ValidationError(path, Schema.scope(spec), 'oneOf');
throw new ValidationError(path, Schema.scope(spec), 'oneOf');
}

@@ -684,3 +658,3 @@ return data;

}
throw new errors_1.ValidationError(path, Schema.scope(spec), 'not');
throw new ValidationError(path, Schema.scope(spec), 'not');
}

@@ -694,7 +668,6 @@ default(spec, path) {

static error(spec, prop) {
return new errors_1.SchemaError(Schema.scope(spec[prop]), prop, spec[prop]);
return new SchemaError(Schema.scope(spec[prop]), prop, spec[prop]);
}
}
exports.Schema = Schema;
class StaticSchema extends Schema {
export class StaticSchema extends Schema {
constructor(dataOrUri, opts) {

@@ -710,3 +683,3 @@ super();

else {
throw new errors_1.SchemaError(opts.scope, 'schema', dataOrUri);
throw new SchemaError(opts.scope, 'schema', dataOrUri);
}

@@ -723,3 +696,2 @@ }

}
exports.StaticSchema = StaticSchema;
//# sourceMappingURL=schema.js.map
import * as refs from 'jsonref';
import { Schema } from './schema';
import { Schema } from './schema.js';
export interface SchemaOptions extends refs.ParseOptions {

@@ -4,0 +4,0 @@ }

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
//# sourceMappingURL=types.js.map

@@ -1,12 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.testRegExp = exports.enumerableAndDefined = exports.defined = void 0;
function defined(v) {
export function defined(v) {
return typeof v !== 'undefined';
}
exports.defined = defined;
function enumerableAndDefined(o, k) {
export function enumerableAndDefined(o, k) {
return defined(o) && o.propertyIsEnumerable(k) && defined(o[k]);
}
exports.enumerableAndDefined = enumerableAndDefined;
const defaultREs = {

@@ -24,3 +19,3 @@ date: /^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/,

const cachedREs = {};
function testRegExp(exp, value) {
export function testRegExp(exp, value) {
var r = defaultREs[exp] || cachedREs[exp];

@@ -32,3 +27,2 @@ if (!r) {

}
exports.testRegExp = testRegExp;
//# sourceMappingURL=utils.js.map
{
"name": "jsonpolice",
"version": "10.0.1",
"version": "11.0.0",
"description": "JSON Schema parser and validator",
"type": "module",
"main": "dist/index.js",

@@ -22,7 +23,6 @@ "typings": "dist/index.d.ts",

"clean:all": "npm run clean && rimraf node_modules",
"cover": "nyc --reporter=lcov --reporter=text npm t",
"cover": "c8 --require esm --reporter=lcov --reporter=text npm t",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"prebuild": "rimraf dist",
"commit": "git-cz",
"check-coverage": "nyc check-coverage",
"check-coverage": "c8 check-coverage",
"watch:test": "npm t -- -w",

@@ -51,25 +51,20 @@ "test": "find ./test/ts -type f -name '*.js' -delete && npm run build && tsc -p test && mocha --exit --no-timeouts --recursive --reporter mochawesome --reporter-options reportDir=test-results test/**/*.test.js",

"devDependencies": {
"@commitlint/config-conventional": "^16.2.1",
"@types/chai": "^4.3.0",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-spies": "^1.0.3",
"@types/mocha": "^9.1.0",
"@types/mocha": "^9.1.1",
"@types/node": "^16.11.26",
"c8": "^7.11.3",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"chai-spies": "^1.0.0",
"commitizen": "^4.2.4",
"commitlint": "^16.2.1",
"coveralls": "^3.1.1",
"cz-conventional-changelog": "^3.3.0",
"husky": "^7.0.4",
"mocha": "^9.2.1",
"mochawesome": "^7.1.0",
"nyc": "^15.1.0",
"mocha": "^10.0.0",
"mochawesome": "^7.1.3",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.2",
"typescript": "^4.6.2"
"typescript": "^4.7.3"
},
"dependencies": {
"jsonref": "^7.0.0",
"jsonref": "^8.0.4",
"lodash": "^4.17.21"

@@ -80,14 +75,3 @@ },

},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "npm run build && npm run cover && npm run check-coverage"
}
},
"nyc": {
"c8": {
"lines": 100,

@@ -94,0 +78,0 @@ "statements": 100,

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