validate-value
Advanced tools
Comparing version 8.7.0 to 8.8.0
@@ -5,3 +5,3 @@ "use strict"; | ||
const getByDataPath = function ({ object, dataPath }) { | ||
const pathSegments = dataPath.split('.'); | ||
const pathSegments = dataPath.replace(/\//u, '.').split('.'); | ||
const nonEmptyPathSegments = pathSegments.filter((segment) => segment !== ''); | ||
@@ -8,0 +8,0 @@ let value = object; |
@@ -1,6 +0,6 @@ | ||
import Ajv from 'ajv'; | ||
import { ErrorObject } from 'ajv'; | ||
declare class ValidationError extends Error { | ||
origin: Ajv.ErrorObject; | ||
constructor(message: string, origin: Ajv.ErrorObject); | ||
origin: ErrorObject; | ||
constructor(message: string, origin: ErrorObject); | ||
} | ||
export { ValidationError }; |
@@ -1,6 +0,6 @@ | ||
import Ajv from 'ajv'; | ||
import { JSONSchema7 } from 'json-schema'; | ||
import { ValidateFunction } from 'ajv'; | ||
declare class Value { | ||
schema: JSONSchema7; | ||
protected validateInternal: Ajv.ValidateFunction; | ||
protected validateInternal: ValidateFunction; | ||
constructor(schema: JSONSchema7); | ||
@@ -7,0 +7,0 @@ validate(value: any, { valueName, separator }?: { |
@@ -7,6 +7,8 @@ "use strict"; | ||
exports.Value = void 0; | ||
const ajv_1 = __importDefault(require("ajv")); | ||
const ajv_formats_1 = __importDefault(require("ajv-formats")); | ||
const getByDataPath_1 = require("./getByDataPath"); | ||
const ValidationError_1 = require("./ValidationError"); | ||
const ajv_1 = __importDefault(require("ajv")); | ||
const ajvInstance = new ajv_1.default(); | ||
ajv_formats_1.default(ajvInstance); | ||
ajvInstance.addFormat('alphanumeric', /[a-zA-Z0-9]/u); | ||
@@ -87,2 +89,7 @@ class Value { | ||
} | ||
case 'format': { | ||
const { format } = error.params; | ||
message = `Value does not satisfy format: ${format}`; | ||
break; | ||
} | ||
default: { | ||
@@ -89,0 +96,0 @@ // Intentionally left blank. |
@@ -0,1 +1,8 @@ | ||
# [8.8.0](https://github.com/thenativeweb/validate-value/compare/8.7.0...8.8.0) (2020-11-25) | ||
### Features | ||
* Support additional formats. ([#225](https://github.com/thenativeweb/validate-value/issues/225)) ([edb1922](https://github.com/thenativeweb/validate-value/commit/edb192240a31d910ed21bce943ba4658db9ba336)) | ||
# [8.7.0](https://github.com/thenativeweb/validate-value/compare/8.6.0...8.7.0) (2020-11-25) | ||
@@ -2,0 +9,0 @@ |
const getByDataPath = function ({ object, dataPath }: { object: any; dataPath: string }): any { | ||
const pathSegments = dataPath.split('.'); | ||
const pathSegments = dataPath.replace(/\//u, '.').split('.'); | ||
const nonEmptyPathSegments = pathSegments.filter((segment): boolean => segment !== ''); | ||
@@ -4,0 +4,0 @@ |
@@ -1,7 +0,7 @@ | ||
import Ajv from 'ajv'; | ||
import { ErrorObject } from 'ajv'; | ||
class ValidationError extends Error { | ||
public origin: Ajv.ErrorObject; | ||
public origin: ErrorObject; | ||
public constructor (message: string, origin: Ajv.ErrorObject) { | ||
public constructor (message: string, origin: ErrorObject) { | ||
super(message); | ||
@@ -8,0 +8,0 @@ this.origin = origin; |
@@ -1,8 +0,10 @@ | ||
import Ajv from 'ajv'; | ||
import addFormats from 'ajv-formats'; | ||
import { getByDataPath } from './getByDataPath'; | ||
import { JSONSchema7 } from 'json-schema'; | ||
import { ValidationError } from './ValidationError'; | ||
import Ajv, { ValidateFunction } from 'ajv'; | ||
const ajvInstance: Ajv.Ajv = new Ajv(); | ||
const ajvInstance = new Ajv(); | ||
addFormats(ajvInstance); | ||
ajvInstance.addFormat('alphanumeric', /[a-zA-Z0-9]/u); | ||
@@ -13,3 +15,3 @@ | ||
protected validateInternal: Ajv.ValidateFunction; | ||
protected validateInternal: ValidateFunction; | ||
@@ -39,3 +41,3 @@ public constructor (schema: JSONSchema7) { | ||
case 'required': { | ||
const missingPropertyName = (error.params as Ajv.RequiredParams).missingProperty; | ||
const missingPropertyName = error.params.missingProperty; | ||
@@ -49,3 +51,3 @@ message = `Missing required property: ${missingPropertyName}`; | ||
case 'additionalProperties': { | ||
const additionalPropertyName = (error.params as Ajv.AdditionalPropertiesParams).additionalProperty; | ||
const additionalPropertyName = error.params.additionalProperty; | ||
@@ -59,3 +61,3 @@ message = `Unexpected additional property: ${additionalPropertyName}`; | ||
case 'minLength': { | ||
const minPropertyLength = (error.params as Ajv.LimitParams).limit; | ||
const minPropertyLength = error.params.limit; | ||
const actualLength = failingValue.length; | ||
@@ -69,3 +71,3 @@ | ||
case 'maxLength': { | ||
const maxPropertyLength = (error.params as Ajv.LimitParams).limit; | ||
const maxPropertyLength = error.params.limit; | ||
const actualLength = failingValue.length; | ||
@@ -79,3 +81,3 @@ | ||
case 'minimum': { | ||
const minimumValue = (error.params as Ajv.LimitParams).limit; | ||
const minimumValue = error.params.limit; | ||
const actualValue = failingValue; | ||
@@ -89,3 +91,3 @@ | ||
case 'maximum': { | ||
const maximumValue = (error.params as Ajv.LimitParams).limit; | ||
const maximumValue = error.params.limit; | ||
const actualValue = failingValue; | ||
@@ -99,3 +101,3 @@ | ||
case 'enum': { | ||
const { allowedValues } = error.params as Ajv.EnumParams; | ||
const { allowedValues } = error.params; | ||
const actualValue = failingValue; | ||
@@ -109,3 +111,3 @@ | ||
case 'pattern': { | ||
const { pattern } = error.params as Ajv.PatternParams; | ||
const { pattern } = error.params; | ||
@@ -118,3 +120,3 @@ message = `String does not match pattern: ${pattern}`; | ||
case 'minItems': { | ||
const { limit } = error.params as Ajv.LimitParams; | ||
const { limit } = error.params; | ||
const actualCount = failingValue.length; | ||
@@ -128,3 +130,3 @@ | ||
case 'maxItems': { | ||
const { limit } = error.params as Ajv.LimitParams; | ||
const { limit } = error.params; | ||
const actualCount = failingValue.length; | ||
@@ -137,2 +139,9 @@ | ||
case 'format': { | ||
const { format } = error.params; | ||
message = `Value does not satisfy format: ${format}`; | ||
break; | ||
} | ||
default: { | ||
@@ -139,0 +148,0 @@ // Intentionally left blank. |
{ | ||
"name": "validate-value", | ||
"version": "8.7.0", | ||
"version": "8.8.0", | ||
"description": "validate-value validates values against JSON schemas.", | ||
@@ -26,3 +26,4 @@ "contributors": [ | ||
"dependencies": { | ||
"ajv": "6.12.6", | ||
"ajv": "7.0.0-beta.2", | ||
"ajv-formats": "0.5.0", | ||
"json-schema": "0.2.5" | ||
@@ -29,0 +30,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24866
383
3
+ Addedajv-formats@0.5.0
+ Addedajv@7.0.0-beta.2(transitive)
+ Addedajv-formats@0.5.0(transitive)
+ Addedjson-schema-traverse@0.5.0(transitive)
- Removedajv@6.12.6(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
Updatedajv@7.0.0-beta.2