Comparing version
@@ -10,3 +10,3 @@ import { CommonConvertOptions, CommonValidationOptions, MaybeOptions, WithDefault } from './common'; | ||
} | ||
export declare type ArrayOptions<I, T extends I[] = I[]> = ItemProcessor & ValidationOptions<I, T>; | ||
export type ArrayOptions<I, T extends I[] = I[]> = ItemProcessor & ValidationOptions<I, T>; | ||
export declare const isArray: <I, T extends I[] = I[]>(item?: ValueProcessor<I> | undefined, options?: ArrayOptions<I, T> | undefined) => ValueProcessor<T>; | ||
@@ -13,0 +13,0 @@ export declare const maybeArray: <I, T extends I[] = I[]>(item?: ValueProcessor<I> | undefined, options?: (ItemProcessor & ValidationOptions<I, T> & MaybeOptions) | undefined) => ValueProcessor<T | undefined>; |
@@ -9,11 +9,11 @@ import { IssueResult, Next, Path, Result, ValueProcessor } from './types'; | ||
} | ||
export declare type UndefinedHandler<T> = () => Result<T> | undefined; | ||
export declare type Definitely<T> = (next: Next<unknown, T>) => (value: unknown, path?: Path[]) => Result<T>; | ||
export declare type IsAs<T> = (next: Next<T, T>) => (value: unknown, path: Path[]) => Result<T>; | ||
export declare type Maybe<T> = (next: Next<unknown, T>) => (value: unknown, path?: Path[]) => Result<T | undefined>; | ||
export declare type Empty = (value: unknown) => boolean; | ||
export declare type Check<T> = (value: unknown) => value is T; | ||
export declare type Convert<T, O = CommonConvertOptions<T>> = (value: unknown, options?: O) => T | undefined; | ||
export declare type Coerce<T, O> = (options?: O) => (next: Next<T, T>) => (value: T, path: Path[]) => Result<T>; | ||
export declare type Validate<T, O> = (value: T, path: Path[], options: O) => IssueResult; | ||
export type UndefinedHandler<T> = () => Result<T> | undefined; | ||
export type Definitely<T> = (next: Next<unknown, T>) => (value: unknown, path?: Path[]) => Result<T>; | ||
export type IsAs<T> = (next: Next<T, T>) => (value: unknown, path: Path[]) => Result<T>; | ||
export type Maybe<T> = (next: Next<unknown, T>) => (value: unknown, path?: Path[]) => Result<T | undefined>; | ||
export type Empty = (value: unknown) => boolean; | ||
export type Check<T> = (value: unknown) => value is T; | ||
export type Convert<T, O = CommonConvertOptions<T>> = (value: unknown, options?: O) => T | undefined; | ||
export type Coerce<T, O> = (options?: O) => (next: Next<T, T>) => (value: T, path: Path[]) => Result<T>; | ||
export type Validate<T, O> = (value: T, path: Path[], options: O) => IssueResult; | ||
export declare const withDefault: <T>(options?: WithDefault<T> | undefined) => UndefinedHandler<T>; | ||
@@ -20,0 +20,0 @@ export declare const definitely: <T>(undefinedHandler?: UndefinedHandler<T> | undefined) => Definitely<T>; |
import { CommonValidationOptions } from './common'; | ||
import { ValueProcessor } from './types'; | ||
declare type EnumValue = string | number; | ||
declare type EnumType = { | ||
type EnumValue = string | number; | ||
type EnumType = { | ||
[key: string]: EnumValue; | ||
@@ -11,6 +11,6 @@ }; | ||
} | ||
export declare const isEnum: <T>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T>; | ||
export declare const maybeEnum: <T>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T | undefined>; | ||
export declare const asEnum: <T>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T>; | ||
export declare const maybeAsEnum: <T>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T | undefined>; | ||
export declare const isEnum: <T extends string | number>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T>; | ||
export declare const maybeEnum: <T extends string | number>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T | undefined>; | ||
export declare const asEnum: <T extends string | number>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T>; | ||
export declare const maybeAsEnum: <T extends string | number>(type: EnumType, options?: ValidationOptions<T>) => ValueProcessor<T | undefined>; | ||
export {}; |
@@ -7,4 +7,4 @@ import { TypeOf } from './../types'; | ||
}>; | ||
export declare type SampleContract = TypeOf<typeof sample>; | ||
export declare type Sample = TypeOf<typeof sample>; | ||
export type SampleContract = TypeOf<typeof sample>; | ||
export type Sample = TypeOf<typeof sample>; | ||
export {}; |
@@ -11,4 +11,4 @@ import { CommonConvertOptions, CommonValidationOptions, MaybeOptions, WithDefault } from './common'; | ||
} | ||
declare type Reviver = (key: string, value: any) => any; | ||
export declare type ObjectOptions<T> = ValidationOptions<T> & AdditionalOptions; | ||
type Reviver = (key: string, value: any) => any; | ||
export type ObjectOptions<T> = ValidationOptions<T> & AdditionalOptions; | ||
export declare const isObject: <T extends { | ||
@@ -15,0 +15,0 @@ [key: string]: any; |
@@ -8,3 +8,3 @@ import { CommonConvertOptions, CommonValidationOptions, MaybeOptions, WithDefault } from './common'; | ||
} | ||
export declare type RecordOptions<T> = ValidationOptions<T>; | ||
export type RecordOptions<T> = ValidationOptions<T>; | ||
export declare const isRecord: <V>(check?: ValueProcessor<V> | undefined, options?: RecordOptions<Record<string, V>> | undefined) => ValueProcessor<Record<string, V>>; | ||
@@ -11,0 +11,0 @@ export declare const maybeRecord: <V>(check?: ValueProcessor<V> | undefined, options?: (RecordOptions<Record<string, V>> & MaybeOptions) | undefined) => ValueProcessor<Record<string, V> | undefined>; |
@@ -1,2 +0,2 @@ | ||
export declare type StringFormatCheck = (value: string) => true | FormatIssue; | ||
export type StringFormatCheck = (value: string) => true | FormatIssue; | ||
export interface FormatIssue { | ||
@@ -3,0 +3,0 @@ expectedFormat: string; |
@@ -7,3 +7,3 @@ import { CommonValidationOptions } from './common'; | ||
} | ||
declare type StringTransform = (value: string) => string; | ||
type StringTransform = (value: string) => string; | ||
interface CoerceOptions { | ||
@@ -10,0 +10,0 @@ limitLength?: number; |
@@ -5,5 +5,5 @@ import { CommonValidationOptions } from './common'; | ||
} | ||
export declare type Options<T extends unknown[]> = ValidationOptions<T>; | ||
export type Options<T extends unknown[]> = ValidationOptions<T>; | ||
export declare const isTuple: <T extends unknown[]>(items: { [K in keyof T]: ValueProcessor<T[K]>; }, options?: Options<T> | undefined) => ValueProcessor<T>; | ||
export declare const maybeTuple: <T extends unknown[]>(items: { [K in keyof T]: ValueProcessor<T[K]>; }, options?: Options<T> | undefined) => ValueProcessor<T | undefined>; | ||
export {}; |
@@ -1,5 +0,5 @@ | ||
export declare type Contract<T> = { | ||
export type Contract<T> = { | ||
[P in keyof T]-?: ValueProcessor<T[P]>; | ||
}; | ||
export declare type Result<T> = ValueResult<T> | IssueResult; | ||
export type Result<T> = ValueResult<T> | IssueResult; | ||
export interface ValueResult<T> { | ||
@@ -11,3 +11,3 @@ value: T; | ||
export declare const exists: <T>(value: T | undefined) => value is T; | ||
export declare type Path = string | number | symbol; | ||
export type Path = string | number | symbol; | ||
export declare class Issue { | ||
@@ -28,16 +28,16 @@ readonly path: Path[]; | ||
} | ||
export declare type Next<T, R> = (value: T, path: Path[]) => Result<R>; | ||
export type Next<T, R> = (value: T, path: Path[]) => Result<R>; | ||
export interface NotPrimitive { | ||
[key: string]: any; | ||
} | ||
export declare type KeysOfType<T, U> = { | ||
export type KeysOfType<T, U> = { | ||
[K in keyof T]: T[K] extends U ? K : never; | ||
}[keyof T]; | ||
export declare type RequiredKeys<T> = Exclude<KeysOfType<T, Exclude<T[keyof T], undefined>>, undefined>; | ||
export declare type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>; | ||
export declare type OptionalProperties<T extends NotPrimitive> = Pick<T, OptionalKeys<T>>; | ||
export declare type RequiredProperties<T extends NotPrimitive> = Omit<T, OptionalKeys<T>>; | ||
export declare type AllProperties<T extends NotPrimitive> = RequiredProperties<T> & Partial<OptionalProperties<T>>; | ||
export declare type TypeOf<T extends ValueProcessor<V> | Contract<V>, V = unknown> = T extends ValueProcessor<infer Type extends NotPrimitive> ? AllProperties<Type> : { | ||
export type RequiredKeys<T> = Exclude<KeysOfType<T, Exclude<T[keyof T], undefined>>, undefined>; | ||
export type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>; | ||
export type OptionalProperties<T extends NotPrimitive> = Pick<T, OptionalKeys<T>>; | ||
export type RequiredProperties<T extends NotPrimitive> = Omit<T, OptionalKeys<T>>; | ||
export type AllProperties<T extends NotPrimitive> = RequiredProperties<T> & Partial<OptionalProperties<T>>; | ||
export type TypeOf<T extends ValueProcessor<V> | Contract<V>, V = unknown> = T extends ValueProcessor<infer Type extends NotPrimitive> ? AllProperties<Type> : { | ||
[K in keyof T]: T[K] extends ValueProcessor<infer Type extends NotPrimitive> ? AllProperties<Type> : never; | ||
}; |
@@ -17,3 +17,5 @@ { | ||
"testRegex": "/(test|src)/.*\\.(test)\\.(tsx?)$", | ||
"testURL": "http://localhost", | ||
"testEnvironmentOptions": { | ||
"url": "http://localhost" | ||
}, | ||
"transform": { | ||
@@ -20,0 +22,0 @@ "^.+\\.tsx?$": "ts-jest" |
{ | ||
"name": "validata", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Type safe data validation and sanitization", | ||
@@ -40,22 +40,22 @@ "keywords": [ | ||
"dependencies": { | ||
"@types/luxon": "^3.0.1", | ||
"luxon": "^3.0.3", | ||
"@types/luxon": "^3.2.0", | ||
"luxon": "^3.2.1", | ||
"validator": "^13.7.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.24", | ||
"@types/validator": "^13.7.6", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/eslint-plugin-tslint": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"@types/jest": "^29.2.5", | ||
"@types/validator": "^13.7.10", | ||
"@typescript-eslint/eslint-plugin": "^5.48.2", | ||
"@typescript-eslint/eslint-plugin-tslint": "^5.48.2", | ||
"@typescript-eslint/parser": "^5.48.2", | ||
"change-case": "^4.1.2", | ||
"eslint": "^7.32.0", | ||
"eslint": "^8.32.0", | ||
"eslint-plugin-filenames": "^1.3.2", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"jest": "^27.5.1", | ||
"jest": "^29.3.1", | ||
"json-date-parser": "^1.0.1", | ||
"ts-jest": "^27.1.5", | ||
"ts-jest": "^29.0.5", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.8.2" | ||
"typescript": "^4.9.4" | ||
} | ||
} |
@@ -20,3 +20,3 @@ import { basicValidation, Check, Coerce, CommonConvertOptions, CommonValidationOptions, Convert, createAsCheck, createIsCheck, createMaybeAsCheck, createMaybeCheck, MaybeOptions, Validate, WithDefault } from './common'; | ||
return Array.isArray(value); // TODO check generic | ||
} | ||
}; | ||
@@ -43,3 +43,3 @@ public convert: Convert<T> = (value): T => { | ||
return issues.length ? { issues } : { value: output as T }; | ||
} | ||
}; | ||
@@ -63,3 +63,3 @@ public coerce: Coerce<T, CoerceOptions<I>> = (options) => (next) => (value, path) => { | ||
return next(coerced, path); | ||
} | ||
}; | ||
@@ -75,3 +75,3 @@ public validate: Validate<T, ValidationOptions<I, T>> = (value, path, options) => { | ||
return result; | ||
} | ||
}; | ||
} | ||
@@ -78,0 +78,0 @@ |
@@ -12,3 +12,3 @@ import { basicValidation, Check, Coerce, CommonValidationOptions, Convert, createAsCheck, createIsCheck, createMaybeAsCheck, createMaybeCheck, Validate } from './common'; | ||
class Generic<T> { | ||
class Generic<T extends string | number> { | ||
private keyToValue: { [key: string]: T } = {}; | ||
@@ -63,6 +63,6 @@ private valueToKey: { [key: string]: string } = {}; | ||
return /^\d+$/gi.test(key); | ||
} | ||
}; | ||
} | ||
export const isEnum = <T>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T> => { | ||
export const isEnum = <T extends string | number>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T> => { | ||
const g = new Generic<T>(type); | ||
@@ -72,3 +72,3 @@ return createIsCheck('enum', g.check(), g.coerce, g.validate)({ ...options }); | ||
export const maybeEnum = <T>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T | undefined> => { | ||
export const maybeEnum = <T extends string | number>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T | undefined> => { | ||
const g = new Generic<T>(type); | ||
@@ -78,3 +78,3 @@ return createMaybeCheck('enum', g.check(), g.coerce, g.validate)({ ...options }); | ||
export const asEnum = <T>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T> => { | ||
export const asEnum = <T extends string | number>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T> => { | ||
const g = new Generic<T>(type); | ||
@@ -84,5 +84,5 @@ return createAsCheck('enum', g.check(true), g.convert, g.coerce, g.validate)({ ...options }); | ||
export const maybeAsEnum = <T>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T | undefined> => { | ||
export const maybeAsEnum = <T extends string | number>(type: EnumType, options: ValidationOptions<T> = {}): ValueProcessor<T | undefined> => { | ||
const g = new Generic<T>(type); | ||
return createMaybeAsCheck('enum', g.check(true), g.convert, g.coerce, g.validate)({ ...options, strictParsing: true }); | ||
}; |
@@ -23,3 +23,3 @@ import { basicValidation, Check, Coerce, CommonConvertOptions, CommonValidationOptions, Convert, createAsCheck, createIsCheck, createMaybeAsCheck, createMaybeCheck, MaybeOptions, Validate, WithDefault } from './common'; | ||
return typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date); | ||
} | ||
}; | ||
@@ -68,3 +68,3 @@ public convert = (options?: ConvertOptions): Convert<T> => (value) => { | ||
return issues.length ? { issues } : { value: output }; | ||
} | ||
}; | ||
@@ -91,3 +91,3 @@ public coerce: Coerce<T, CoerceOptions<T>> = (options) => (next) => (value, path) => { | ||
return next(coerced, path); | ||
} | ||
}; | ||
@@ -94,0 +94,0 @@ public validate: Validate<T, ValidationOptions<T>> = (value, path, options) => basicValidation(value, path, options); |
@@ -17,3 +17,3 @@ import { basicValidation, Check, Coerce, CommonConvertOptions, CommonValidationOptions, Convert, createAsCheck, createIsCheck, createMaybeAsCheck, createMaybeCheck, MaybeOptions, Validate, WithDefault } from './common'; | ||
return typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date); | ||
} | ||
}; | ||
@@ -43,3 +43,3 @@ public convert: Convert<Record<string, V>> = (value): Record<string, V> | undefined => { | ||
return issues.length ? { issues } : { value: output }; | ||
} | ||
}; | ||
@@ -60,3 +60,3 @@ public coerce: Coerce<Record<string, V>, CoerceOptions<V>> = (options) => (next) => (value, path) => { | ||
return next(coerced, path); | ||
} | ||
}; | ||
@@ -84,3 +84,3 @@ public validate: Validate<Record<string, V>, ValidationOptions<Record<string, V>>> = (value, path, options) => { | ||
return result; | ||
} | ||
}; | ||
} | ||
@@ -87,0 +87,0 @@ |
@@ -13,3 +13,3 @@ import { basicValidation, Check, Coerce, CommonValidationOptions, createIsCheck, createMaybeCheck, Validate } from './common'; | ||
return Array.isArray(value); // TODO check generic | ||
} | ||
}; | ||
@@ -44,3 +44,3 @@ public process = (check: { [K in keyof T]: ValueProcessor<T[K]> }, target: T, path: Path[]): Result<T> => { | ||
return issues.length ? { issues } : { value: output }; | ||
} | ||
}; | ||
@@ -59,3 +59,3 @@ public coerce: Coerce<T, CoerceOptions<T>> = (options) => (next) => (value, path) => { | ||
return next(coerced, path); | ||
} | ||
}; | ||
@@ -62,0 +62,0 @@ public validate: Validate<T, ValidationOptions<T>> = (value, path, options) => basicValidation(value, path, options); |
@@ -28,3 +28,3 @@ export type Contract<T> = { | ||
return new Issue(Array.isArray(path) ? path : [path], value, reason, info); | ||
} | ||
}; | ||
@@ -34,3 +34,3 @@ public static nest = (parentPath: Path | Path[], issue: Issue): Issue => { | ||
return new Issue([...path, ...issue.path], issue.value, issue.reason, issue.info); | ||
} | ||
}; | ||
@@ -37,0 +37,0 @@ private constructor( |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
628140
0.03%7377
0.03%Updated
Updated