+60
-42
@@ -63,2 +63,6 @@ // src/messages.ts | ||
| validate(value, { path } = defaultConfigValidate) { | ||
| if (this.context.allowNull && value === null) | ||
| return ""; | ||
| if (this.context.allowUndefined && value === undefined) | ||
| return ""; | ||
| for (const testEntity of this.context.rules) { | ||
@@ -72,2 +76,15 @@ const error = testEntity.test(value, { path }); | ||
| } | ||
| nullable() { | ||
| this.context.allowNull = true; | ||
| return this; | ||
| } | ||
| undefinable() { | ||
| this.context.allowUndefined = true; | ||
| return this; | ||
| } | ||
| optional() { | ||
| this.context.allowNull = true; | ||
| this.context.allowUndefined = true; | ||
| return this; | ||
| } | ||
| validateObj(value, config = defaultConfigValidate) { | ||
@@ -92,9 +109,7 @@ const validateError = this.validate(value, config); | ||
| rules = []; | ||
| allowNull = false; | ||
| allowUndefined = false; | ||
| } | ||
| // src/string/string.ts | ||
| function string() { | ||
| return StringDesy.new({ context: Context.new() }); | ||
| } | ||
| class StringDesy extends Schema { | ||
@@ -125,2 +140,4 @@ static new(config) { | ||
| optional() { | ||
| this.context.allowNull = true; | ||
| this.context.allowUndefined = true; | ||
| this.context.rules = this.context.rules.filter(({ test }) => test !== StringDesy.required); | ||
@@ -197,11 +214,7 @@ return this; | ||
| } | ||
| var a = string().oneOf(["hello"]); | ||
| function string() { | ||
| return StringDesy.new({ context: Context.new() }); | ||
| } | ||
| // src/object/object.ts | ||
| function object(value) { | ||
| return ObjectDesy.new({ | ||
| value, | ||
| context: Context.new() | ||
| }); | ||
| } | ||
| var strictName = "object:strict"; | ||
@@ -254,4 +267,4 @@ var fieldsName = "object:fields"; | ||
| for (const key in this.value) { | ||
| const schema3 = config.value[key]; | ||
| const error = schema3.validate(currentValue[key], { | ||
| const schema = config.value[key]; | ||
| const error = schema.validate(currentValue[key], { | ||
| path: path === "" ? key : `${path}.${key}` | ||
@@ -278,7 +291,7 @@ }); | ||
| for (const key in this.value) { | ||
| const schema3 = this.value[key]; | ||
| const schema = this.value[key]; | ||
| if (!(key in this.value)) { | ||
| continue; | ||
| } | ||
| const error = schema3.validate(currentValue[key], { | ||
| const error = schema.validate(currentValue[key], { | ||
| path: path === "" ? key : `${path}.${key}` | ||
@@ -313,7 +326,7 @@ }); | ||
| for (const key in this.value) { | ||
| const schema3 = this.value[key]; | ||
| const schema = this.value[key]; | ||
| if (!(key in currentValue) && optionalFields.includes(key)) { | ||
| continue; | ||
| } | ||
| const error = schema3.validate(currentValue[key], { | ||
| const error = schema.validate(currentValue[key], { | ||
| path: path === "" ? key : `${path}.${key}` | ||
@@ -332,7 +345,10 @@ }); | ||
| } | ||
| function object(value) { | ||
| return ObjectDesy.new({ | ||
| value, | ||
| context: Context.new() | ||
| }); | ||
| } | ||
| // src/number/number.ts | ||
| function number() { | ||
| return NumberDesy.new({ context: Context.new() }); | ||
| } | ||
| var testNumber = (value, { path }) => { | ||
@@ -402,7 +418,7 @@ if (typeof value !== "number" || isFinite(value) === false) { | ||
| } | ||
| function number() { | ||
| return NumberDesy.new({ context: Context.new() }); | ||
| } | ||
| // src/boolean/boolean.ts | ||
| function boolean() { | ||
| return BooleanDesy.new({ context: Context.new() }); | ||
| } | ||
| var testBoolean = (currentValue, { path }) => { | ||
@@ -451,7 +467,7 @@ if (typeof currentValue !== "boolean") { | ||
| } | ||
| function boolean() { | ||
| return BooleanDesy.new({ context: Context.new() }); | ||
| } | ||
| // src/array/array.ts | ||
| function array(schema6) { | ||
| return new ArrayDesy({ value: schema6, context: Context.new() }); | ||
| } | ||
| var testArray = (currentValue, { path }) => { | ||
@@ -527,7 +543,7 @@ if (!Array.isArray(currentValue)) { | ||
| } | ||
| function array(schema) { | ||
| return new ArrayDesy({ value: schema, context: Context.new() }); | ||
| } | ||
| // src/null/null.ts | ||
| function nullDesy() { | ||
| return NullDesy.new({ context: Context.new() }); | ||
| } | ||
| var testNull = (value, { path }) => { | ||
@@ -552,7 +568,7 @@ if (value !== null) { | ||
| } | ||
| function nullDesy() { | ||
| return NullDesy.new({ context: Context.new() }); | ||
| } | ||
| // src/date/date.ts | ||
| function date() { | ||
| return DateDesy.new({ context: Context.new() }); | ||
| } | ||
| var testDate = (value, { path }) => { | ||
@@ -563,4 +579,4 @@ const valueType = typeof value; | ||
| } | ||
| const date2 = new Date(value); | ||
| const valid = !isNaN(date2.getTime()); | ||
| const date = new Date(value); | ||
| const valid = !isNaN(date.getTime()); | ||
| if (!valid) { | ||
@@ -610,8 +626,7 @@ return messages.date.date({ path }); | ||
| } | ||
| function date() { | ||
| return DateDesy.new({ context: Context.new() }); | ||
| } | ||
| // src/mixed/mixed.ts | ||
| function mixed() { | ||
| return MixedDesy.new({ context: Context.new() }); | ||
| } | ||
| class MixedDesy extends Schema { | ||
@@ -621,4 +636,4 @@ static new(config) { | ||
| } | ||
| array(schema9) { | ||
| return ArrayDesy.new({ context: this.context, value: schema9 }); | ||
| array(schema) { | ||
| return ArrayDesy.new({ context: this.context, value: schema }); | ||
| } | ||
@@ -660,4 +675,4 @@ number() { | ||
| let lastError = ""; | ||
| for (const schema9 of schemas) { | ||
| const error = schema9.validate(value, { path }); | ||
| for (const schema of schemas) { | ||
| const error = schema.validate(value, { path }); | ||
| if (error === "") { | ||
@@ -674,2 +689,5 @@ return ""; | ||
| } | ||
| function mixed() { | ||
| return MixedDesy.new({ context: Context.new() }); | ||
| } | ||
@@ -676,0 +694,0 @@ // src/desy.ts |
+1
-1
| { | ||
| "name": "desy", | ||
| "version": "0.0.14", | ||
| "version": "0.0.15", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "types": "./dist/types/desy.d.ts", |
| import { Infer, Schema } from '../schema/schema.ts'; | ||
| import { ConfigValue } from '../types.ts'; | ||
| export declare class ArrayDesy<TSchema extends Schema<any>> extends Schema<Infer<TSchema>[]> { | ||
| static new<TSchema extends Schema<any>>(config: ConfigValue<TSchema>): ArrayDesy<TSchema>; | ||
| constructor(config: ConfigValue<TSchema>); | ||
| min(minLength: number): this; | ||
| max(maxLength: number): this; | ||
| length(length: number): this; | ||
| } | ||
| export declare function array<TValue extends Schema<any>>(schema: TValue): ArrayDesy<TValue>; |
| import { Schema } from '../schema/schema.ts'; | ||
| import { type Config } from '../types.ts'; | ||
| export declare class BooleanDesy<TValue extends boolean = boolean> extends Schema<TValue> { | ||
| static new<TValue extends boolean>(config: Config): BooleanDesy<TValue>; | ||
| constructor(config: Config); | ||
| true(): BooleanDesy<true>; | ||
| false(): BooleanDesy<false>; | ||
| } | ||
| export declare function boolean(): BooleanDesy<boolean>; |
| export type Test = (value: any, { path }: { | ||
| path: string; | ||
| }) => string; | ||
| export type TestEntity = { | ||
| name: string; | ||
| test: Test; | ||
| }; | ||
| export declare class Context { | ||
| static new(): Context; | ||
| rules: TestEntity[]; | ||
| } |
| import { Schema } from '../schema/schema.ts'; | ||
| import { Config } from '../types'; | ||
| type DateValue = string | number | Date; | ||
| export declare class DateDesy<TValue extends DateValue> extends Schema<TValue> { | ||
| static new(config: Config): DateDesy<DateValue>; | ||
| constructor(config: Config); | ||
| min(min: DateValue): this; | ||
| max(max: DateValue): this; | ||
| } | ||
| export declare function date(): DateDesy<DateValue>; | ||
| export {}; |
| import { string } from './string/string.ts'; | ||
| import { object } from './object/object.ts'; | ||
| import { number } from './number/number.ts'; | ||
| import { boolean } from './boolean/boolean.ts'; | ||
| import { array } from './array/array.ts'; | ||
| import { mixed } from './mixed/mixed.ts'; | ||
| import { date } from './date/date.ts'; | ||
| import { nullDesy } from './null/null.ts'; | ||
| import { type Schema, type Infer } from './schema/schema.ts'; | ||
| export { type Schema } from './schema/schema.ts'; | ||
| export type InferDesy<T extends Schema<any>> = Infer<T>; | ||
| export declare const d: { | ||
| string: typeof string; | ||
| object: typeof object; | ||
| number: typeof number; | ||
| boolean: typeof boolean; | ||
| array: typeof array; | ||
| mixed: typeof mixed; | ||
| date: typeof date; | ||
| null: typeof nullDesy; | ||
| }; |
| export type DefaultMessageProps = { | ||
| path: string; | ||
| }; | ||
| type Min = DefaultMessageProps & { | ||
| min: number; | ||
| }; | ||
| type Max = DefaultMessageProps & { | ||
| max: number; | ||
| }; | ||
| type Length = DefaultMessageProps & { | ||
| length: number; | ||
| }; | ||
| type RegexpMessage = DefaultMessageProps & { | ||
| regexp: string; | ||
| }; | ||
| export declare const messages: { | ||
| string: { | ||
| string: ({ path }: DefaultMessageProps) => string; | ||
| requred: ({ path }: DefaultMessageProps) => string; | ||
| min: ({ path, min }: Min) => string; | ||
| max: ({ path, max }: Max) => string; | ||
| length: ({ path, length }: Length) => string; | ||
| regexp: ({ path, regexp }: RegexpMessage) => string; | ||
| one_of: ({ path, variants, value, }: DefaultMessageProps & { | ||
| variants: string[]; | ||
| value: string; | ||
| }) => string; | ||
| }; | ||
| object: { | ||
| object: ({ path }: DefaultMessageProps) => string; | ||
| no_property: ({ path }: DefaultMessageProps) => string; | ||
| unknown: ({ path }: DefaultMessageProps) => string; | ||
| }; | ||
| mixed: { | ||
| not_void: ({ path }: DefaultMessageProps) => string; | ||
| }; | ||
| boolean: { | ||
| boolean: ({ path }: DefaultMessageProps) => string; | ||
| true: ({ path }: DefaultMessageProps) => string; | ||
| false: ({ path }: DefaultMessageProps) => string; | ||
| }; | ||
| number: { | ||
| number: ({ path }: DefaultMessageProps) => string; | ||
| min: ({ path, min }: Min) => string; | ||
| max: ({ path, max }: Max) => string; | ||
| int: ({ path }: DefaultMessageProps) => string; | ||
| float: ({ path }: DefaultMessageProps) => string; | ||
| }; | ||
| array: { | ||
| array: ({ path }: DefaultMessageProps) => string; | ||
| items: ({ path }: DefaultMessageProps) => string; | ||
| min: ({ path, min }: Min) => string; | ||
| max: ({ path, max }: Max) => string; | ||
| length: ({ path, length }: Length) => string; | ||
| }; | ||
| date: { | ||
| date: ({ path }: DefaultMessageProps) => string; | ||
| min: ({ path, min }: DefaultMessageProps & { | ||
| min: string; | ||
| }) => string; | ||
| max: ({ path, max }: DefaultMessageProps & { | ||
| max: string; | ||
| }) => string; | ||
| }; | ||
| null: { | ||
| null: ({ path }: DefaultMessageProps) => string; | ||
| }; | ||
| }; | ||
| export {}; |
| import { Infer, Schema } from '../schema/schema.ts'; | ||
| import { StringDesy as StringDesy } from '../string/string.ts'; | ||
| import { type ObjectDesyValue, ObjectDesy } from '../object/object.ts'; | ||
| import { BooleanDesy } from '../boolean/boolean.ts'; | ||
| import { type Config } from '../types.ts'; | ||
| import { NumberDesy } from '../number/number.ts'; | ||
| import { ArrayDesy } from '../array/array.ts'; | ||
| import { NullDesy } from '../null/null.ts'; | ||
| import { DateDesy } from '../date/date.ts'; | ||
| export declare class MixedDesy<TValue extends any = any> extends Schema<TValue> { | ||
| static new(config: Config): MixedDesy<any>; | ||
| array<TValue extends Schema<any>>(schema: TValue): ArrayDesy<TValue>; | ||
| number(): NumberDesy; | ||
| object<TValue extends ObjectDesyValue>(shape: TValue): ObjectDesy<TValue, { [K in keyof TValue]: Infer<TValue[K]>; }>; | ||
| boolean(): BooleanDesy<boolean>; | ||
| string(): StringDesy<string>; | ||
| date(): DateDesy<string | number | Date>; | ||
| null(): NullDesy; | ||
| notVoid(): this; | ||
| oneOf<TValue extends Schema<any>>(schemas: TValue[]): MixedDesy<Infer<TValue>>; | ||
| } | ||
| export declare function mixed(): MixedDesy<any>; |
| import { Schema } from '../schema/schema.ts'; | ||
| import { Config } from '../types.ts'; | ||
| export declare class NullDesy extends Schema<null> { | ||
| static new(config: Config): NullDesy; | ||
| constructor(config: Config); | ||
| } | ||
| export declare function nullDesy(): NullDesy; |
| import { Schema } from '../schema/schema.ts'; | ||
| import { Config } from '../types.ts'; | ||
| export declare class NumberDesy extends Schema<number> { | ||
| static new(config: Config): NumberDesy; | ||
| constructor(config: Config); | ||
| min(min: number): this; | ||
| max(max: number): this; | ||
| int(): this; | ||
| float(): this; | ||
| } | ||
| export declare function number(): NumberDesy; |
| import { Schema, type Infer } from '../schema/schema.ts'; | ||
| import { type ConfigValue } from '../types.ts'; | ||
| export type ObjectDesyValue = Record<string, Schema<any>>; | ||
| type PreparedTypes<TValue extends ObjectDesyValue> = { | ||
| [K in keyof TValue]: Infer<TValue[K]>; | ||
| }; | ||
| type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
| export declare class ObjectDesy<TValue extends ObjectDesyValue, TValueTypes = PreparedTypes<TValue>> extends Schema<TValueTypes> { | ||
| static new<TValue extends ObjectDesyValue>(config: ConfigValue<TValue>): ObjectDesy<TValue, PreparedTypes<TValue>>; | ||
| value: TValue; | ||
| constructor(config: ConfigValue<TValue>); | ||
| notStrict(): ObjectDesy<TValue, Partial<this["types"]>>; | ||
| optionalFields<TValueLocal extends keyof TValueTypes & string = any>(optionalFields: TValueLocal[]): ObjectDesy<TValue, PartialBy<this["types"], TValueLocal>>; | ||
| } | ||
| export declare function object<TValue extends ObjectDesyValue>(value: TValue): ObjectDesy<TValue, PreparedTypes<TValue>>; | ||
| export {}; |
| import { Context, Test } from '../context/context.ts'; | ||
| type Config = { | ||
| context: Context; | ||
| }; | ||
| export type Infer<TType extends Schema<any>> = TType['types']; | ||
| type ConfigValidate = { | ||
| path: string; | ||
| }; | ||
| export declare abstract class Schema<TValue> { | ||
| types: TValue; | ||
| protected context: Context; | ||
| constructor({ context }: Config); | ||
| validate(value: any, { path }?: ConfigValidate): string; | ||
| validateObj(value: any, config?: ConfigValidate): Infer<typeof this> | string; | ||
| test<TValue extends (typeof this)['types']>(cb: Test): Schema<TValue>; | ||
| } | ||
| export {}; |
| import { DefaultMessageProps } from '../messages.ts'; | ||
| import { Schema } from '../schema/schema.ts'; | ||
| import { Context } from '../context/context.ts'; | ||
| type Config = { | ||
| context: Context; | ||
| }; | ||
| export declare class StringDesy<TValue extends string> extends Schema<TValue> { | ||
| static new<TValue extends string>(config: Config): StringDesy<TValue>; | ||
| static string(value: any, { path }: DefaultMessageProps): string; | ||
| static required(value: string, { path }: DefaultMessageProps): string; | ||
| constructor(config: Config); | ||
| optional(): this; | ||
| length(length: number): this; | ||
| min(minLength: number): this; | ||
| max(maxLength: number): this; | ||
| oneOf<TValue extends readonly string[]>(variants: TValue): StringDesy<TValue[number]>; | ||
| regexp(regexp: RegExp): this; | ||
| } | ||
| export declare function string(): StringDesy<string>; | ||
| export {}; |
| import { type Context } from './context/context.ts'; | ||
| export type Config = { | ||
| context: Context; | ||
| }; | ||
| export type ConfigValue<TValue> = { | ||
| value: TValue; | ||
| context: Context; | ||
| }; |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
0
-100%24682
-25.5%3
-81.25%671
-24.01%