@nhtio/validation 0.1.0-master-ebe86e9e → 0.1.0-master-cd50e735

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhtio/validation",
3
- "version": "0.1.0-master-ebe86e9e",
3
+ "version": "0.1.0-master-cd50e735",
4
4
  "description": "A powerful schema description language and data validator",
5
5
  "keywords": [],
6
6
  "author": "Jak Giveon <jak@nht.io>",
@@ -1,3 +1,4 @@
1
+ import type { DateTime } from 'luxon';
1
2
  import type { PhoneSchema } from './schemas/phone';
2
3
  import type { BigIntSchema } from './schemas/bigint';
3
4
  import type { DatetimeSchema } from './schemas/datetime';
@@ -24,21 +25,66 @@ import type { AlternativesSchema, AnySchema, StringSchema, BinarySchema, NumberS
24
25
  * @public
25
26
  */
26
27
  export interface ValidationRoot extends Omit<Root, 'any' | 'string' | 'binary' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'alternatives' | 'alt'> {
27
- any: () => AnySchema;
28
- string: () => StringSchema;
29
- binary: () => BinarySchema;
30
- number: () => NumberSchema;
31
- boolean: () => BooleanSchema;
28
+ /**
29
+ * Generates a schema object that matches any data type.
30
+ */
31
+ any<TSchema = any>(): AnySchema<TSchema>;
32
+ /**
33
+ * Generates a schema object that matches an array data type.
34
+ */
35
+ array<TSchema = any[]>(): ArraySchema<TSchema>;
36
+ /**
37
+ * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via boolean().
38
+ */
39
+ bool<TSchema = boolean>(): BooleanSchema<TSchema>;
40
+ /**
41
+ * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool().
42
+ */
43
+ boolean<TSchema = boolean>(): BooleanSchema<TSchema>;
44
+ /**
45
+ * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers).
46
+ */
47
+ binary<TSchema = Buffer>(): BinarySchema<TSchema>;
48
+ /**
49
+ * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds).
50
+ */
51
+ date<TSchema = Date>(): DateSchema<TSchema>;
52
+ /**
53
+ * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers).
54
+ */
55
+ number<TSchema = number>(): NumberSchema<TSchema>;
56
+ /**
57
+ * Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects).
58
+ */
32
59
  object<TSchema = any, IsStrict = false, T = TSchema>(schema?: SchemaMap<T, IsStrict>): ObjectSchema<TSchema>;
33
- array: () => ArraySchema;
34
- date: () => DateSchema;
35
- bigint(): BigIntSchema;
36
- datetime(): DatetimeSchema;
37
- phone(country?: CountryOrUnknown | Reference | null): PhoneSchema;
60
+ /**
61
+ * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').
62
+ */
63
+ string<TSchema = string>(): StringSchema<TSchema>;
64
+ /**
65
+ * Generates a type that will match one of the provided alternative schemas
66
+ */
38
67
  alternatives<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
39
68
  alternatives<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
69
+ /**
70
+ * Alias for `alternatives`
71
+ */
40
72
  alt<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
41
73
  alt<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
74
+ /**
75
+ * Generates a schema object that matches a BigInt data type.
76
+ */
77
+ bigint<TSchema = bigint>(): BigIntSchema<TSchema>;
78
+ /**
79
+ * Generates a schema object that matches a DateTime data type.
80
+ */
81
+ datetime<TSchema = DateTime>(): DatetimeSchema<TSchema>;
82
+ /**
83
+ * Generates a schema object that matches a phone number data type.
84
+ *
85
+ * @param country - Optional country code or reference for phone validation
86
+ */
87
+ phone<TSchema = string>(country?: CountryOrUnknown | Reference | null): PhoneSchema<TSchema>;
42
88
  }
43
89
  /**
44
90
  * Extended Joi instance with custom schema types.