justus 0.0.1 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -34
- package/dist/dts-generator.js +166 -0
- package/dist/dts-generator.js.map +6 -0
- package/dist/dts-generator.mjs +158 -0
- package/dist/dts-generator.mjs.map +6 -0
- package/dist/{index.cjs → index.js} +246 -124
- package/dist/index.js.map +6 -0
- package/dist/index.mjs +218 -121
- package/dist/index.mjs.map +2 -2
- package/dts-generator.d.ts +13 -0
- package/{dist/index.d.ts → index.d.ts} +171 -40
- package/package.json +27 -16
- package/src/dts-generator.ts +276 -0
- package/src/errors.ts +3 -3
- package/src/index.ts +32 -8
- package/src/schema.ts +6 -6
- package/src/types.ts +15 -6
- package/src/validators/array.ts +14 -12
- package/src/validators/date.ts +3 -3
- package/src/validators/number.ts +54 -22
- package/src/validators/object.ts +67 -48
- package/src/validators/string.ts +25 -11
- package/src/validators/tuple.ts +17 -13
- package/src/validators/union.ts +3 -3
- package/src/validators/url.ts +140 -0
- package/dist/index.cjs.map +0 -6
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* An interface defining whether a `Schema` should include additional
|
|
3
5
|
* properties, and the `Validator` used to validate them.
|
|
@@ -31,17 +33,37 @@ export declare class AllOfValidator<A extends UnionArguments> extends Validator<
|
|
|
31
33
|
export declare const allowAdditionalProperties: typeof _allowAdditionalProperties & AdditionalProperties<Validator<any>>;
|
|
32
34
|
|
|
33
35
|
/** Internal definition of `allowAdditionalProperties(...)` */
|
|
34
|
-
declare function _allowAdditionalProperties(): AdditionalProperties<Validator<any>>;
|
|
36
|
+
export declare function _allowAdditionalProperties(): AdditionalProperties<Validator<any>>;
|
|
35
37
|
|
|
36
|
-
declare function _allowAdditionalProperties(allow: true): AdditionalProperties<Validator<any>>;
|
|
38
|
+
export declare function _allowAdditionalProperties(allow: true): AdditionalProperties<Validator<any>>;
|
|
37
39
|
|
|
38
|
-
declare function _allowAdditionalProperties(allow: false): AdditionalProperties<false>;
|
|
40
|
+
export declare function _allowAdditionalProperties(allow: false): AdditionalProperties<false>;
|
|
39
41
|
|
|
40
|
-
declare function _allowAdditionalProperties<V extends Validation>(validation: V): AdditionalProperties<Validator<InferValidation<V>>>;
|
|
42
|
+
export declare function _allowAdditionalProperties<V extends Validation>(validation: V): AdditionalProperties<Validator<InferValidation<V>>>;
|
|
41
43
|
|
|
42
44
|
/** The `Validator` validating _anything_. */
|
|
43
45
|
export declare const any: AnyValidator;
|
|
44
46
|
|
|
47
|
+
/** Basic validator for `Array` instances. */
|
|
48
|
+
export declare class AnyArrayValidator<T = any> extends Validator<T[]> {
|
|
49
|
+
validate(value: unknown, options: ValidationOptions): T[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A `Validator` validating any `number`. */
|
|
53
|
+
export declare class AnyNumberValidator extends Validator<number> {
|
|
54
|
+
validate(value: unknown): number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A `Validator` validating any `object`. */
|
|
58
|
+
export declare class AnyObjectValidator extends Validator<Record<string, any>> {
|
|
59
|
+
validate(value: unknown): Record<string, any>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A `Validator` validating any `string`. */
|
|
63
|
+
export declare class AnyStringValidator extends Validator<string> {
|
|
64
|
+
validate(value: unknown): string;
|
|
65
|
+
}
|
|
66
|
+
|
|
45
67
|
/** A `Validator` validating _anything_. */
|
|
46
68
|
export declare class AnyValidator extends Validator<any> {
|
|
47
69
|
validate(value: unknown): any;
|
|
@@ -50,12 +72,12 @@ export declare class AnyValidator extends Validator<any> {
|
|
|
50
72
|
/** Validate `Array`s. */
|
|
51
73
|
export declare const array: typeof _array & Iterable<TupleRestParameter<any[]>>;
|
|
52
74
|
|
|
53
|
-
declare function _array(): Validator<any[]>;
|
|
75
|
+
export declare function _array(): Validator<any[]>;
|
|
54
76
|
|
|
55
|
-
declare function _array<V extends Validation>(constraints: ArrayConstraints<V>): ArrayValidator<InferValidation<V>>;
|
|
77
|
+
export declare function _array<V extends Validation>(constraints: ArrayConstraints<V>): ArrayValidator<InferValidation<V>>;
|
|
56
78
|
|
|
57
79
|
/** Constraints to validate an `Array` with. */
|
|
58
|
-
declare interface ArrayConstraints<V extends Validation> {
|
|
80
|
+
export declare interface ArrayConstraints<V extends Validation> {
|
|
59
81
|
/** The _maximum_ number of elements a valid `Array`: `value.length <= maxItems` */
|
|
60
82
|
maxItems?: number;
|
|
61
83
|
/** The _minimum_ number of elements a valid `Array`: `value.length >= minItems` */
|
|
@@ -69,9 +91,7 @@ declare interface ArrayConstraints<V extends Validation> {
|
|
|
69
91
|
/** Validate `Array`s containing only the specified elements. */
|
|
70
92
|
export declare function arrayOf<V extends Validation>(validation: V): ArrayValidator<InferValidation<V>>;
|
|
71
93
|
|
|
72
|
-
/**
|
|
73
|
-
* A validator for `Array` instances.
|
|
74
|
-
*/
|
|
94
|
+
/** A validator for `Array` instances with constraints. */
|
|
75
95
|
export declare class ArrayValidator<T> extends Validator<T[]> {
|
|
76
96
|
readonly maxItems: number;
|
|
77
97
|
readonly minItems: number;
|
|
@@ -100,6 +120,25 @@ export declare class BooleanValidator extends Validator<boolean> {
|
|
|
100
120
|
validate(value: unknown): boolean;
|
|
101
121
|
}
|
|
102
122
|
|
|
123
|
+
/** Constraints to validate a `number` with extra branding information. */
|
|
124
|
+
export declare interface BrandedNumberConstraints<B extends string> extends NumberConstraints {
|
|
125
|
+
/** The _brand_ of the string (will generate a `__brand_${B}` type property */
|
|
126
|
+
brand: B;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Constraints to validate a `string` with extra branding information. */
|
|
130
|
+
export declare interface BrandedStringConstraints<B extends string> extends StringConstraints {
|
|
131
|
+
/** The _brand_ of the string (will generate a `__brand_${B}` type property */
|
|
132
|
+
brand: B;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Utility type to infer primitive branding according to a string */
|
|
136
|
+
export declare type Branding<S extends string> = {
|
|
137
|
+
[key in keyof {
|
|
138
|
+
__brand: never;
|
|
139
|
+
} as `__brand_${S}`]: never;
|
|
140
|
+
};
|
|
141
|
+
|
|
103
142
|
/**
|
|
104
143
|
* Mark a `Schema` property as both _optional_ and _read only_.
|
|
105
144
|
*/
|
|
@@ -108,7 +147,7 @@ export declare interface CombinedModifier<V extends Validator = Validator> exten
|
|
|
108
147
|
readonly: true;
|
|
109
148
|
}
|
|
110
149
|
|
|
111
|
-
declare type CombineModifiers<M1 extends Modifier, M2 extends Modifier> = M1 extends ReadonlyModifier ? M2 extends ReadonlyModifier<infer V> ? ReadonlyModifier<V> : M2 extends OptionalModifier<infer V> ? CombinedModifier<V> : never : M1 extends OptionalModifier ? M2 extends ReadonlyModifier<infer V> ? CombinedModifier<V> : M2 extends OptionalModifier<infer V> ? OptionalModifier<V> : never : never;
|
|
150
|
+
export declare type CombineModifiers<M1 extends Modifier, M2 extends Modifier> = M1 extends ReadonlyModifier ? M2 extends ReadonlyModifier<infer V> ? ReadonlyModifier<V> : M2 extends OptionalModifier<infer V> ? CombinedModifier<V> : never : M1 extends OptionalModifier ? M2 extends ReadonlyModifier<infer V> ? CombinedModifier<V> : M2 extends OptionalModifier<infer V> ? OptionalModifier<V> : never : never;
|
|
112
151
|
|
|
113
152
|
/** Validate _constants_. */
|
|
114
153
|
export declare function constant<T extends string | number | boolean | null>(constant: T): Validator<T>;
|
|
@@ -123,12 +162,12 @@ export declare class ConstantValidator<T extends string | number | boolean | nul
|
|
|
123
162
|
/** Validate dates and convert them to `Date` instances. */
|
|
124
163
|
export declare const date: typeof _date & Iterable<TupleRestParameter<Date>>;
|
|
125
164
|
|
|
126
|
-
declare function _date(): DateValidator;
|
|
165
|
+
export declare function _date(): DateValidator;
|
|
127
166
|
|
|
128
|
-
declare function _date(constraints: DateConstraints): DateValidator;
|
|
167
|
+
export declare function _date(constraints: DateConstraints): DateValidator;
|
|
129
168
|
|
|
130
169
|
/** Constraints to validate a `Date` with. */
|
|
131
|
-
declare interface DateConstraints {
|
|
170
|
+
export declare interface DateConstraints {
|
|
132
171
|
/** The format for dates, an _ISO date_ (RFC 3339) or a numeric timestamp */
|
|
133
172
|
format?: 'iso' | 'timestamp';
|
|
134
173
|
/** The earliest value a date can have */
|
|
@@ -153,32 +192,32 @@ export declare class DateValidator extends Validator<Date> {
|
|
|
153
192
|
*/
|
|
154
193
|
export declare function getValidator(validation?: Validation): Validator;
|
|
155
194
|
|
|
156
|
-
declare type InferAllOfValidationType<A extends UnionArguments> = A extends readonly [infer First, ...infer Rest] ? First extends Validation ? Rest extends UnionArguments ? InferValidation<First> & InferOneOfValidationType<Rest> : InferValidation<First> : never : never;
|
|
195
|
+
export declare type InferAllOfValidationType<A extends UnionArguments> = A extends readonly [infer First, ...infer Rest] ? First extends Validation ? Rest extends UnionArguments ? InferValidation<First> & InferOneOfValidationType<Rest> : InferValidation<First> : never : never;
|
|
157
196
|
|
|
158
197
|
/** Infer the type of _read only_ **and** _optional_ `Schema` properties */
|
|
159
|
-
declare type InferCombinedModifiers<S extends Schema> = {
|
|
198
|
+
export declare type InferCombinedModifiers<S extends Schema> = {
|
|
160
199
|
readonly [key in keyof S as key extends string ? S[key] extends CombinedModifier ? key : never : never]?: S[key] extends CombinedModifier<infer V> ? InferValidation<V> : never;
|
|
161
200
|
};
|
|
162
201
|
|
|
163
202
|
/** Ensure that we properly type `never` properties */
|
|
164
|
-
declare type InferNever<S extends Schema> = {
|
|
203
|
+
export declare type InferNever<S extends Schema> = {
|
|
165
204
|
[key in keyof S as key extends string ? S[key] extends typeof never ? key : never : never]: never;
|
|
166
205
|
};
|
|
167
206
|
|
|
168
|
-
declare type InferOneOfValidationType<A extends UnionArguments> = A extends readonly [infer First, ...infer Rest] ? First extends Validation ? Rest extends UnionArguments ? InferValidation<First> | InferOneOfValidationType<Rest> : InferValidation<First> : never : never;
|
|
207
|
+
export declare type InferOneOfValidationType<A extends UnionArguments> = A extends readonly [infer First, ...infer Rest] ? First extends Validation ? Rest extends UnionArguments ? InferValidation<First> | InferOneOfValidationType<Rest> : InferValidation<First> : never : never;
|
|
169
208
|
|
|
170
209
|
/** Infer the type of _optional_ `Schema` properties */
|
|
171
|
-
declare type InferOptionalModifiers<S extends Schema> = {
|
|
210
|
+
export declare type InferOptionalModifiers<S extends Schema> = {
|
|
172
211
|
[key in keyof S as key extends string ? S[key] extends ReadonlyModifier<Validator> ? never : S[key] extends OptionalModifier<Validator> ? key : never : never]?: S[key] extends OptionalModifier<infer V> ? InferValidation<V> : never;
|
|
173
212
|
};
|
|
174
213
|
|
|
175
214
|
/** Infer the type of _read only_ `Schema` properties */
|
|
176
|
-
declare type InferReadonlyModifiers<S extends Schema> = {
|
|
215
|
+
export declare type InferReadonlyModifiers<S extends Schema> = {
|
|
177
216
|
readonly [key in keyof S as key extends string ? S[key] extends OptionalModifier<Validator> ? never : S[key] extends ReadonlyModifier<Validator> ? key : never : never]: S[key] extends ReadonlyModifier<infer V> ? InferValidation<V> : never;
|
|
178
217
|
};
|
|
179
218
|
|
|
180
219
|
/** Infer the type of keys associated with `Validation`s */
|
|
181
|
-
declare type InferRequired<S extends Schema> = {
|
|
220
|
+
export declare type InferRequired<S extends Schema> = {
|
|
182
221
|
[key in keyof S as key extends string ? S[key] extends Validation ? key : never : never]: S[key] extends Validation ? InferValidation<S[key]> : never;
|
|
183
222
|
};
|
|
184
223
|
|
|
@@ -215,7 +254,7 @@ export declare type InferValidation<V> = V extends Validation ? V extends {
|
|
|
215
254
|
} ? A0 extends [] ? R0 : A1 extends [] ? R1 : A2 extends [] ? R2 : A3 extends [] ? R3 : A4 extends [] ? R4 : A5 extends [] ? R5 : A6 extends [] ? R6 : A7 extends [] ? R7 : A8 extends [] ? R8 : A9 extends [] ? R9 : never : V extends Validator<infer T> ? T : V extends Tuple ? InferTuple<V> : V extends Schema ? InferSchema<V> : V extends boolean ? V : V extends number ? V : V extends string ? V : V extends null ? V : never : never;
|
|
216
255
|
|
|
217
256
|
/** Infer the type validated by a `Validation` or `TupleRestParameter` */
|
|
218
|
-
declare type InferValidationOrTupleRest<T> = T extends TupleRestParameter<infer X> ? X : T extends Validation ? InferValidation<T> : never;
|
|
257
|
+
export declare type InferValidationOrTupleRest<T> = T extends TupleRestParameter<infer X> ? X : T extends Validation ? InferValidation<T> : never;
|
|
219
258
|
|
|
220
259
|
/** Type guard for `Modifier` instances */
|
|
221
260
|
export declare function isModifier(what: any): what is Modifier<any>;
|
|
@@ -238,12 +277,16 @@ export declare const never: unique symbol;
|
|
|
238
277
|
/** Validate `number`s. */
|
|
239
278
|
export declare const number: typeof _number & Iterable<TupleRestParameter<number>>;
|
|
240
279
|
|
|
241
|
-
declare function _number(): Validator<number>;
|
|
280
|
+
export declare function _number(): Validator<number>;
|
|
281
|
+
|
|
282
|
+
export declare function _number(constraints?: NumberConstraints): NumberValidator<number>;
|
|
283
|
+
|
|
284
|
+
export declare function _number<N extends number>(constraints?: NumberConstraints): NumberValidator<N>;
|
|
242
285
|
|
|
243
|
-
declare function _number<
|
|
286
|
+
export declare function _number<B extends string>(constraints: BrandedNumberConstraints<B>): NumberValidator<number & Branding<B>>;
|
|
244
287
|
|
|
245
288
|
/** Constraints to validate a `number` with. */
|
|
246
|
-
declare interface NumberConstraints {
|
|
289
|
+
export declare interface NumberConstraints {
|
|
247
290
|
/** The value for which a `number` must be multiple of for it to be valid */
|
|
248
291
|
multipleOf?: number;
|
|
249
292
|
/** The _inclusive_ maximum value for a valid `number`: `value <= maximum` */
|
|
@@ -258,7 +301,7 @@ declare interface NumberConstraints {
|
|
|
258
301
|
allowNaN?: boolean;
|
|
259
302
|
}
|
|
260
303
|
|
|
261
|
-
/** A `Validator` validating `number`s. */
|
|
304
|
+
/** A `Validator` validating `number`s with constaints. */
|
|
262
305
|
export declare class NumberValidator<N extends number = number> extends Validator<N> {
|
|
263
306
|
#private;
|
|
264
307
|
readonly allowNaN: boolean;
|
|
@@ -267,22 +310,31 @@ export declare class NumberValidator<N extends number = number> extends Validato
|
|
|
267
310
|
readonly maximum: number;
|
|
268
311
|
readonly minimum: number;
|
|
269
312
|
readonly multipleOf?: number;
|
|
313
|
+
readonly brand?: string;
|
|
270
314
|
constructor(constraints?: NumberConstraints);
|
|
271
315
|
validate(value: unknown): N;
|
|
272
|
-
static readonly PRECISION = 1000000;
|
|
273
316
|
}
|
|
274
317
|
|
|
275
318
|
/** Validate `object`s. */
|
|
276
319
|
export declare const object: typeof _object & Iterable<TupleRestParameter<Record<string, any>>>;
|
|
277
320
|
|
|
278
|
-
declare function _object(): Validator<Record<string, any>>;
|
|
321
|
+
export declare function _object(): Validator<Record<string, any>>;
|
|
279
322
|
|
|
280
|
-
declare function _object<S extends Schema>(schema: S): S
|
|
323
|
+
export declare function _object<S extends Schema>(schema: S): S & {
|
|
324
|
+
[Symbol.iterator](): Generator<TupleRestParameter<InferSchema<S>>>;
|
|
325
|
+
};
|
|
281
326
|
|
|
282
|
-
|
|
327
|
+
export declare type ObjectProperty = {
|
|
328
|
+
validator: Validator;
|
|
329
|
+
readonly?: true;
|
|
330
|
+
optional?: true;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/** A `Validator` validating `object`s according to a `Schema`. */
|
|
283
334
|
export declare class ObjectValidator<S extends Schema> extends Validator<InferSchema<S>> {
|
|
284
|
-
#private;
|
|
285
335
|
readonly schema: Readonly<S>;
|
|
336
|
+
properties: Map<string, ObjectProperty | undefined>;
|
|
337
|
+
additionalProperties?: Validator;
|
|
286
338
|
constructor(schema: S);
|
|
287
339
|
validate(value: unknown, options: ValidationOptions): InferSchema<S>;
|
|
288
340
|
}
|
|
@@ -351,12 +403,16 @@ export declare const schemaValidator: unique symbol;
|
|
|
351
403
|
/** Validate `string`s. */
|
|
352
404
|
export declare const string: typeof _string & Iterable<TupleRestParameter<string>>;
|
|
353
405
|
|
|
354
|
-
declare function _string(): Validator<string>;
|
|
406
|
+
export declare function _string(): Validator<string>;
|
|
407
|
+
|
|
408
|
+
export declare function _string(constraints?: StringConstraints): StringValidator<string>;
|
|
409
|
+
|
|
410
|
+
export declare function _string<S extends string>(constraints?: StringConstraints): StringValidator<S>;
|
|
355
411
|
|
|
356
|
-
declare function _string<
|
|
412
|
+
export declare function _string<B extends string>(constraints: BrandedStringConstraints<B>): StringValidator<string & Branding<B>>;
|
|
357
413
|
|
|
358
414
|
/** Constraints to validate a `string` with. */
|
|
359
|
-
declare interface StringConstraints {
|
|
415
|
+
export declare interface StringConstraints {
|
|
360
416
|
/** The _maximum_ length of a valid `string`: `value.length <= maxLength` */
|
|
361
417
|
maxLength?: number;
|
|
362
418
|
/** The _minimum_ length of a valid `string`: `value.length >= minLength` */
|
|
@@ -365,15 +421,22 @@ declare interface StringConstraints {
|
|
|
365
421
|
pattern?: RegExp;
|
|
366
422
|
}
|
|
367
423
|
|
|
368
|
-
/** A `Validator` validating `string`s. */
|
|
424
|
+
/** A `Validator` validating `string`s with constraints. */
|
|
369
425
|
export declare class StringValidator<S extends string = string> extends Validator<S> {
|
|
370
426
|
readonly maxLength: number;
|
|
371
427
|
readonly minLength: number;
|
|
372
428
|
readonly pattern?: RegExp;
|
|
429
|
+
readonly brand?: string;
|
|
373
430
|
constructor(constraints?: StringConstraints);
|
|
374
431
|
validate(value: unknown): S;
|
|
375
432
|
}
|
|
376
433
|
|
|
434
|
+
/**
|
|
435
|
+
* Validate a _value_ using the specified `Validation`, automatically stripping
|
|
436
|
+
* additional properties (but not forbidden ones).
|
|
437
|
+
*/
|
|
438
|
+
export declare function strip<V extends Validation>(validation: V, value: any, options?: ValidateOptions): InferValidation<V>;
|
|
439
|
+
|
|
377
440
|
/**
|
|
378
441
|
* A `Tuple` is defined to be an array of `Validation` or `TupleRest`
|
|
379
442
|
*/
|
|
@@ -382,6 +445,11 @@ export declare type Tuple = readonly (Validation | TupleRestParameter)[];
|
|
|
382
445
|
/** Validate _tuples_. */
|
|
383
446
|
export declare function tuple<T extends Tuple>(tuple: T): Validator<InferTuple<T>>;
|
|
384
447
|
|
|
448
|
+
export declare interface TupleMember {
|
|
449
|
+
single: boolean;
|
|
450
|
+
validator: Validator;
|
|
451
|
+
}
|
|
452
|
+
|
|
385
453
|
/**
|
|
386
454
|
* The `TupleRestParameter` defines a tuple member that can occur several
|
|
387
455
|
* times while validating an array.
|
|
@@ -401,15 +469,78 @@ export declare type TupleRestParameter<T = any> = {
|
|
|
401
469
|
|
|
402
470
|
/** A `Validator` for _tuples_. */
|
|
403
471
|
export declare class TupleValidator<T extends Tuple> extends Validator<InferTuple<T>> {
|
|
404
|
-
|
|
472
|
+
readonly members: readonly TupleMember[];
|
|
405
473
|
readonly tuple: T;
|
|
406
474
|
constructor(tuple: T);
|
|
407
475
|
validate(value: unknown, options: ValidationOptions): InferTuple<T>;
|
|
408
476
|
}
|
|
409
477
|
|
|
410
|
-
declare type UnionArguments = readonly [Validation, ...Validation[]];
|
|
478
|
+
export declare type UnionArguments = readonly [Validation, ...Validation[]];
|
|
479
|
+
|
|
480
|
+
/** Validate URLs and convert them to `URL` instances. */
|
|
481
|
+
export declare const url: typeof _url & Iterable<TupleRestParameter<URL>>;
|
|
482
|
+
|
|
483
|
+
export declare function _url(): URLValidator;
|
|
484
|
+
|
|
485
|
+
export declare function _url(constraints: URLConstraints): URLValidator;
|
|
486
|
+
|
|
487
|
+
/** Constraints to validate a `URL` with. */
|
|
488
|
+
export declare interface URLConstraints {
|
|
489
|
+
/** Constraint to validate the `href` component of the `URL`. */
|
|
490
|
+
href?: string | Validator<string>;
|
|
491
|
+
/** Constraint to validate the `origin` component of the `URL`. */
|
|
492
|
+
origin?: string | Validator<string>;
|
|
493
|
+
/** Constraint to validate the `protocol` component of the `URL`. */
|
|
494
|
+
protocol?: string | Validator<string>;
|
|
495
|
+
/** Constraint to validate the `username` component of the `URL`. */
|
|
496
|
+
username?: string | Validator<string>;
|
|
497
|
+
/** Constraint to validate the `password` component of the `URL`. */
|
|
498
|
+
password?: string | Validator<string>;
|
|
499
|
+
/** Constraint to validate the `host` (`hostname:port`) component of the `URL`. */
|
|
500
|
+
host?: string | Validator<string>;
|
|
501
|
+
/** Constraint to validate the `hostname` component of the `URL`. */
|
|
502
|
+
hostname?: string | Validator<string>;
|
|
503
|
+
/** Constraint to validate the `port` component of the `URL`. */
|
|
504
|
+
port?: string | Validator<string>;
|
|
505
|
+
/** Constraint to validate the `pathname` component of the `URL`. */
|
|
506
|
+
pathname?: string | Validator<string>;
|
|
507
|
+
/** Constraint to validate the `search` component of the `URL` as a string. */
|
|
508
|
+
search?: string | Validator<string>;
|
|
509
|
+
/** Constraint to validate the `hash` component of the `URL`. */
|
|
510
|
+
hash?: string | Validator<string>;
|
|
511
|
+
/**
|
|
512
|
+
* Schema used to validate the `searchParams` component of the `URL`.
|
|
513
|
+
*
|
|
514
|
+
* The `searchParams` will be normalized in a `Record<string, string>`, where
|
|
515
|
+
* only the _first_ value associated with a search parameter will be checked.
|
|
516
|
+
*/
|
|
517
|
+
searchParams?: Schema;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** A `Validator` validating URLs and converting them to `URL` instances. */
|
|
521
|
+
export declare class URLValidator extends Validator<URL> {
|
|
522
|
+
readonly href?: Validator<string>;
|
|
523
|
+
readonly origin?: Validator<string>;
|
|
524
|
+
readonly protocol?: Validator<string>;
|
|
525
|
+
readonly username?: Validator<string>;
|
|
526
|
+
readonly password?: Validator<string>;
|
|
527
|
+
readonly host?: Validator<string>;
|
|
528
|
+
readonly hostname?: Validator<string>;
|
|
529
|
+
readonly port?: Validator<string>;
|
|
530
|
+
readonly pathname?: Validator<string>;
|
|
531
|
+
readonly search?: Validator<string>;
|
|
532
|
+
readonly hash?: Validator<string>;
|
|
533
|
+
readonly searchParams?: ObjectValidator<Schema>;
|
|
534
|
+
constructor(constraints?: URLConstraints);
|
|
535
|
+
validate(value: unknown): URL;
|
|
536
|
+
}
|
|
411
537
|
|
|
412
|
-
/**
|
|
538
|
+
/**
|
|
539
|
+
* Validate a _value_ using the specified `Validation`.
|
|
540
|
+
*
|
|
541
|
+
* By default additional and forbidden properties will _not_ be stripped and
|
|
542
|
+
* reported as an error.
|
|
543
|
+
*/
|
|
413
544
|
export declare function validate<V extends Validation>(validation: V, value: any, options?: ValidateOptions): InferValidation<V>;
|
|
414
545
|
|
|
415
546
|
/** Options for `validate` */
|
|
@@ -465,7 +596,7 @@ export declare class ValidationErrorBuilder {
|
|
|
465
596
|
* @param key - The key in an object, or index in an array where the
|
|
466
597
|
* vaildation error was encountered
|
|
467
598
|
*/
|
|
468
|
-
record(error: any, key
|
|
599
|
+
record(error: any, ...key: (string | number)[]): this;
|
|
469
600
|
/**
|
|
470
601
|
* Assert there are no validation errors and return the specified value, or
|
|
471
602
|
* throw a `ValidationError` combining all errors
|
|
@@ -475,7 +606,7 @@ export declare class ValidationErrorBuilder {
|
|
|
475
606
|
assert<T>(value: T): T;
|
|
476
607
|
}
|
|
477
608
|
|
|
478
|
-
declare type ValidationErrors = {
|
|
609
|
+
export declare type ValidationErrors = {
|
|
479
610
|
path: (string | number)[];
|
|
480
611
|
message: string;
|
|
481
612
|
}[];
|
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "justus",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A JavaScript validation library, with types!",
|
|
5
|
-
"main": "dist/index.
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./dts-generator": {
|
|
13
|
+
"import": "./dist/dts-generator.mjs",
|
|
14
|
+
"require": "./dist/dts-generator.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"types": "./index.d.ts",
|
|
8
18
|
"scripts": {
|
|
9
|
-
"build": "build.sh",
|
|
19
|
+
"build": "./build.sh",
|
|
10
20
|
"dev": "nodemon -e ts -x build.sh -w src -w test -w test-d",
|
|
11
21
|
"lint": "eslint src test test-d",
|
|
12
22
|
"prepare": "patch -N -p0 -i .nyc.patch || true"
|
|
@@ -14,20 +24,21 @@
|
|
|
14
24
|
"author": "Juit Developers <developers@juit.com>",
|
|
15
25
|
"license": "MIT",
|
|
16
26
|
"devDependencies": {
|
|
17
|
-
"@microsoft/api-extractor": "^7.
|
|
18
|
-
"@types/chai": "^4.
|
|
19
|
-
"@types/mocha": "^9.
|
|
20
|
-
"@
|
|
21
|
-
"@typescript-eslint/
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
27
|
+
"@microsoft/api-extractor": "^7.19.5",
|
|
28
|
+
"@types/chai": "^4.3.0",
|
|
29
|
+
"@types/mocha": "^9.1.0",
|
|
30
|
+
"@types/node": "~16.11.26",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
32
|
+
"@typescript-eslint/parser": "^5.15.0",
|
|
33
|
+
"chai": "^4.3.6",
|
|
34
|
+
"esbuild": "^0.14.27",
|
|
35
|
+
"eslint": "^8.11.0",
|
|
25
36
|
"eslint-config-google": "^0.14.0",
|
|
26
|
-
"mocha": "^9.
|
|
37
|
+
"mocha": "^9.2.2",
|
|
27
38
|
"nodemon": "^2.0.15",
|
|
28
39
|
"nyc": "^15.1.0",
|
|
29
|
-
"tsd": "^0.19.
|
|
30
|
-
"typescript": "^4.
|
|
40
|
+
"tsd": "^0.19.1",
|
|
41
|
+
"typescript": "^4.6.2"
|
|
31
42
|
},
|
|
32
43
|
"directories": {
|
|
33
44
|
"test": "test"
|