@tldraw/validate
Advanced tools
Comparing version 2.0.0-canary.36e8813bf21d to 2.0.0-canary.38d74a9ff0d9
@@ -45,10 +45,2 @@ /** | ||
/** @public */ | ||
declare const boxModel: ObjectValidator<{ | ||
x: number; | ||
y: number; | ||
w: number; | ||
h: number; | ||
}>; | ||
/** | ||
@@ -88,2 +80,5 @@ * Validation that an option is a dict with particular keys and values. | ||
/** @public */ | ||
declare function literalEnum<const Values extends readonly unknown[]>(...values: Values): Validator<Values[number]>; | ||
/** | ||
@@ -113,2 +108,5 @@ * A named object with an ID. Errors will be reported as being part of the object with the given | ||
/** @public */ | ||
declare function nullable<T>(validator: Validatable<T>): Validator<null | T>; | ||
/** | ||
@@ -160,7 +158,3 @@ * Validates that a value is a finite non-NaN number. | ||
/** @public */ | ||
declare const point: ObjectValidator<{ | ||
x: number; | ||
y: number; | ||
z: number | undefined; | ||
}>; | ||
declare function optional<T>(validator: Validatable<T>): Validator<T | undefined>; | ||
@@ -200,2 +194,5 @@ /** | ||
setEnum, | ||
optional, | ||
nullable, | ||
literalEnum, | ||
ValidatorFn, | ||
@@ -222,5 +219,3 @@ Validatable, | ||
array, | ||
unknownObject, | ||
point, | ||
boxModel | ||
unknownObject | ||
} | ||
@@ -227,0 +222,0 @@ } |
@@ -32,12 +32,13 @@ "use strict"; | ||
boolean: () => boolean, | ||
boxModel: () => boxModel, | ||
dict: () => dict, | ||
integer: () => integer, | ||
literal: () => literal, | ||
literalEnum: () => literalEnum, | ||
model: () => model, | ||
nonZeroInteger: () => nonZeroInteger, | ||
nonZeroNumber: () => nonZeroNumber, | ||
nullable: () => nullable, | ||
number: () => number, | ||
object: () => object, | ||
point: () => point, | ||
optional: () => optional, | ||
positiveInteger: () => positiveInteger, | ||
@@ -138,7 +139,3 @@ positiveNumber: () => positiveNumber, | ||
nullable() { | ||
return new Validator((value) => { | ||
if (value === null) | ||
return null; | ||
return this.validate(value); | ||
}); | ||
return nullable(this); | ||
} | ||
@@ -150,7 +147,3 @@ /** | ||
optional() { | ||
return new Validator((value) => { | ||
if (value === void 0) | ||
return void 0; | ||
return this.validate(value); | ||
}); | ||
return optional(this); | ||
} | ||
@@ -388,13 +381,19 @@ /** | ||
} | ||
const point = object({ | ||
x: number, | ||
y: number, | ||
z: number.optional() | ||
}); | ||
const boxModel = object({ | ||
x: number, | ||
y: number, | ||
w: number, | ||
h: number | ||
}); | ||
function optional(validator) { | ||
return new Validator((value) => { | ||
if (value === void 0) | ||
return void 0; | ||
return validator.validate(value); | ||
}); | ||
} | ||
function nullable(validator) { | ||
return new Validator((value) => { | ||
if (value === null) | ||
return null; | ||
return validator.validate(value); | ||
}); | ||
} | ||
function literalEnum(...values) { | ||
return setEnum(new Set(values)); | ||
} | ||
//# sourceMappingURL=validation.js.map |
{ | ||
"name": "@tldraw/validate", | ||
"description": "A runtime validation library by tldraw.", | ||
"version": "2.0.0-canary.36e8813bf21d", | ||
"version": "2.0.0-canary.38d74a9ff0d9", | ||
"packageManager": "yarn@3.5.0", | ||
@@ -45,3 +45,3 @@ "author": { | ||
"dependencies": { | ||
"@tldraw/utils": "2.0.0-canary.36e8813bf21d" | ||
"@tldraw/utils": "2.0.0-canary.38d74a9ff0d9" | ||
}, | ||
@@ -48,0 +48,0 @@ "jest": { |
@@ -106,6 +106,3 @@ import { exhaustiveSwitchError, getOwnProperty, hasOwnProperty } from '@tldraw/utils' | ||
nullable(): Validator<T | null> { | ||
return new Validator((value) => { | ||
if (value === null) return null | ||
return this.validate(value) | ||
}) | ||
return nullable(this) | ||
} | ||
@@ -118,6 +115,3 @@ | ||
optional(): Validator<T | undefined> { | ||
return new Validator((value) => { | ||
if (value === undefined) return undefined | ||
return this.validate(value) | ||
}) | ||
return optional(this) | ||
} | ||
@@ -549,14 +543,22 @@ | ||
/** @public */ | ||
export const point = object({ | ||
x: number, | ||
y: number, | ||
z: number.optional(), | ||
}) | ||
export function optional<T>(validator: Validatable<T>): Validator<T | undefined> { | ||
return new Validator((value) => { | ||
if (value === undefined) return undefined | ||
return validator.validate(value) | ||
}) | ||
} | ||
/** @public */ | ||
export const boxModel = object({ | ||
x: number, | ||
y: number, | ||
w: number, | ||
h: number, | ||
}) | ||
export function nullable<T>(validator: Validatable<T>): Validator<T | null> { | ||
return new Validator((value) => { | ||
if (value === null) return null | ||
return validator.validate(value) | ||
}) | ||
} | ||
/** @public */ | ||
export function literalEnum<const Values extends readonly unknown[]>( | ||
...values: Values | ||
): Validator<Values[number]> { | ||
return setEnum(new Set(values)) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123620
1725
+ Added@tldraw/utils@2.0.0-canary.38d74a9ff0d9(transitive)
- Removed@tldraw/utils@2.0.0-canary.36e8813bf21d(transitive)