vest 4.0.0-dev-366a8b → 4.0.0-dev-e266d9

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +70 -49
  2. package/README.md +2 -112
  3. package/dist/cjs/classnames.development.js +3 -3
  4. package/dist/cjs/classnames.production.js +1 -1
  5. package/dist/cjs/compose.js +7 -0
  6. package/dist/cjs/compounds.js +7 -0
  7. package/dist/cjs/enforce/compose.development.js +139 -0
  8. package/dist/cjs/enforce/compose.production.js +1 -0
  9. package/dist/cjs/enforce/compounds.development.js +132 -0
  10. package/dist/cjs/enforce/compounds.production.js +1 -0
  11. package/dist/cjs/enforce/package.json +1 -0
  12. package/dist/cjs/enforce/schema.development.js +144 -0
  13. package/dist/cjs/enforce/schema.production.js +1 -0
  14. package/dist/cjs/promisify.development.js +1 -1
  15. package/dist/cjs/promisify.production.js +1 -1
  16. package/dist/cjs/schema.js +7 -0
  17. package/dist/cjs/vest.development.js +608 -1097
  18. package/dist/cjs/vest.production.js +1 -1
  19. package/dist/es/classnames.development.js +3 -3
  20. package/dist/es/classnames.production.js +1 -1
  21. package/dist/es/enforce/compose.development.js +137 -0
  22. package/dist/es/enforce/compose.production.js +1 -0
  23. package/dist/es/enforce/compounds.development.js +130 -0
  24. package/dist/es/enforce/compounds.production.js +1 -0
  25. package/dist/es/enforce/package.json +1 -0
  26. package/dist/es/enforce/schema.development.js +140 -0
  27. package/dist/es/enforce/schema.production.js +1 -0
  28. package/dist/es/promisify.development.js +1 -1
  29. package/dist/es/promisify.production.js +1 -1
  30. package/dist/es/vest.development.js +602 -1097
  31. package/dist/es/vest.production.js +1 -1
  32. package/dist/umd/classnames.development.js +3 -3
  33. package/dist/umd/classnames.production.js +1 -1
  34. package/dist/umd/enforce/compose.development.js +143 -0
  35. package/dist/umd/enforce/compose.production.js +1 -0
  36. package/dist/umd/enforce/compounds.development.js +136 -0
  37. package/dist/umd/enforce/compounds.production.js +1 -0
  38. package/dist/umd/enforce/schema.development.js +148 -0
  39. package/dist/umd/enforce/schema.production.js +1 -0
  40. package/dist/umd/promisify.development.js +1 -1
  41. package/dist/umd/promisify.production.js +1 -1
  42. package/dist/umd/vest.development.js +1693 -2185
  43. package/dist/umd/vest.production.js +1 -1
  44. package/enforce/compose/package.json +7 -0
  45. package/enforce/compounds/package.json +7 -0
  46. package/enforce/schema/package.json +7 -0
  47. package/package.json +107 -13
  48. package/testUtils/mockThrowError.ts +16 -0
  49. package/types/classnames.d.ts +2 -2
  50. package/types/enforce/compose.d.ts +134 -0
  51. package/types/enforce/compounds.d.ts +146 -0
  52. package/types/enforce/schema.d.ts +151 -0
  53. package/types/vest.d.ts +31 -196
  54. package/docs/.nojekyll +0 -0
  55. package/docs/README.md +0 -113
  56. package/docs/_assets/favicon.ico +0 -0
  57. package/docs/_assets/vest-logo.png +0 -0
  58. package/docs/_sidebar.md +0 -14
  59. package/docs/cross_field_validations.md +0 -33
  60. package/docs/enforce.md +0 -11
  61. package/docs/exclusion.md +0 -129
  62. package/docs/getting_started.md +0 -72
  63. package/docs/group.md +0 -142
  64. package/docs/index.html +0 -41
  65. package/docs/migration.md +0 -202
  66. package/docs/n4s/rules.md +0 -1282
  67. package/docs/node.md +0 -36
  68. package/docs/optional.md +0 -103
  69. package/docs/result.md +0 -249
  70. package/docs/state.md +0 -102
  71. package/docs/test.md +0 -172
  72. package/docs/utilities.md +0 -109
  73. package/docs/warn.md +0 -82
@@ -0,0 +1,151 @@
1
+ type DropFirst<T extends unknown[]> = T extends [
2
+ unknown,
3
+ ...infer U
4
+ ] ? U : never;
5
+ type TStringable = string | ((...args: any[]) => string);
6
+ type TRuleReturn = boolean | {
7
+ pass: boolean;
8
+ message?: TStringable;
9
+ };
10
+ type TRuleDetailedResult = {
11
+ pass: boolean;
12
+ message?: string;
13
+ };
14
+ type TArgs = any[];
15
+ type TBaseRules = typeof baseRules;
16
+ type KBaseRules = keyof TBaseRules;
17
+ declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
18
+ declare function endsWith(value: string, arg1: string): boolean;
19
+ declare function equals(value: unknown, arg1: unknown): boolean;
20
+ declare function greaterThan(value: number | string, gt: number | string): boolean;
21
+ declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
22
+ declare function inside(value: unknown, arg1: string | unknown[]): boolean;
23
+ // The module is named "isArrayValue" since it
24
+ // is conflicting with a nested npm dependency.
25
+ // We may need to revisit this in the future.
26
+ declare function isArray(value: unknown): value is Array<unknown>;
27
+ declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
28
+ declare function isBlank(value: unknown): boolean;
29
+ declare function isBoolean(value: unknown): value is boolean;
30
+ declare function isEmpty(value: unknown): boolean;
31
+ declare function isNaN(value: unknown): boolean;
32
+ declare function isNegative(value: number | string): boolean;
33
+ declare function isNull(value: unknown): value is null;
34
+ declare function isNullish(value: any): value is null | undefined;
35
+ declare function isNumber(value: unknown): value is number;
36
+ declare function isNumeric(value: string | number): boolean;
37
+ declare function isStringValue(v: unknown): v is string;
38
+ declare function isTruthy(value: unknown): boolean;
39
+ declare function isUndefined(value?: unknown): boolean;
40
+ declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
41
+ declare function lessThan(value: string | number, lt: string | number): boolean;
42
+ declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
43
+ declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
44
+ declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
45
+ declare function matches(value: string, regex: RegExp | string): boolean;
46
+ declare function numberEquals(value: string | number, eq: string | number): boolean;
47
+ declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
48
+ declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
49
+ declare function startsWith(value: string, arg1: string): boolean;
50
+ declare const baseRules: {
51
+ condition: typeof condition;
52
+ doesNotEndWith: (value: string, arg1: string) => boolean;
53
+ doesNotStartWith: (value: string, arg1: string) => boolean;
54
+ endsWith: typeof endsWith;
55
+ equals: typeof equals;
56
+ greaterThan: typeof greaterThan;
57
+ greaterThanOrEquals: typeof greaterThanOrEquals;
58
+ gt: typeof greaterThan;
59
+ gte: typeof greaterThanOrEquals;
60
+ inside: typeof inside;
61
+ isArray: typeof isArray;
62
+ isBetween: typeof isBetween;
63
+ isBlank: typeof isBlank;
64
+ isBoolean: typeof isBoolean;
65
+ isEmpty: typeof isEmpty;
66
+ isEven: (value: any) => boolean;
67
+ isFalsy: (value: unknown) => boolean;
68
+ isNaN: typeof isNaN;
69
+ isNegative: typeof isNegative;
70
+ isNotArray: (value: unknown) => boolean;
71
+ isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
72
+ isNotBlank: (value: unknown) => boolean;
73
+ isNotBoolean: (value: unknown) => boolean;
74
+ isNotEmpty: (value: unknown) => boolean;
75
+ isNotNaN: (value: unknown) => boolean;
76
+ isNotNull: (value: unknown) => boolean;
77
+ isNotNullish: (value: any) => boolean;
78
+ isNotNumber: (value: unknown) => boolean;
79
+ isNotNumeric: (value: string | number) => boolean;
80
+ isNotString: (v: unknown) => boolean;
81
+ isNotUndefined: (value?: unknown) => boolean;
82
+ isNull: typeof isNull;
83
+ isNullish: typeof isNullish;
84
+ isNumber: typeof isNumber;
85
+ isNumeric: typeof isNumeric;
86
+ isOdd: (value: any) => boolean;
87
+ isPositive: (value: string | number) => boolean;
88
+ isString: typeof isStringValue;
89
+ isTruthy: typeof isTruthy;
90
+ isUndefined: typeof isUndefined;
91
+ lengthEquals: typeof lengthEquals;
92
+ lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
93
+ lessThan: typeof lessThan;
94
+ lessThanOrEquals: typeof lessThanOrEquals;
95
+ longerThan: typeof longerThan;
96
+ longerThanOrEquals: typeof longerThanOrEquals;
97
+ lt: typeof lessThan;
98
+ lte: typeof lessThanOrEquals;
99
+ matches: typeof matches;
100
+ notEquals: (value: unknown, arg1: unknown) => boolean;
101
+ notInside: (value: unknown, arg1: string | unknown[]) => boolean;
102
+ notMatches: (value: string, regex: string | RegExp) => boolean;
103
+ numberEquals: typeof numberEquals;
104
+ numberNotEquals: (value: string | number, eq: string | number) => boolean;
105
+ shorterThan: typeof shorterThan;
106
+ shorterThanOrEquals: typeof shorterThanOrEquals;
107
+ startsWith: typeof startsWith;
108
+ };
109
+ type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
110
+ [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
111
+ };
112
+ /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
113
+ declare global {
114
+ namespace n4s {
115
+ interface IRules<E> extends TRules<E> {
116
+ }
117
+ }
118
+ }
119
+ type TLazyRules = n4s.IRules<TLazyRuleMethods>;
120
+ type TLazy = TLazyRules & TLazyRuleMethods &
121
+ // This is a "catch all" hack to make TS happy while not
122
+ // losing type hints
123
+ Record<string, (...args: any[]) => any>;
124
+ interface IShapeObject extends Record<string, any>, Record<string, TLazyRuleRunners> {
125
+ }
126
+ type TLazyRuleMethods = TLazyRuleRunners & {
127
+ message: (message: TLazyMessage) => TLazy;
128
+ };
129
+ type TLazyRuleRunners = {
130
+ test: (value: unknown) => boolean;
131
+ run: (value: unknown) => TRuleDetailedResult;
132
+ };
133
+ type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
134
+ declare function isArrayOf(inputArray: any[], currentRule: TLazy): TRuleDetailedResult;
135
+ declare function loose(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
136
+ declare function optional(value: any, ruleChain: TLazy): TRuleDetailedResult;
137
+ declare function shape(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
138
+ // Help needed improving the typings of this file.
139
+ // Ideally, we'd be able to extend IShapeObject, but that's not possible.
140
+ declare function partial<T extends Record<any, any>>(shapeObject: T): T;
141
+ declare global {
142
+ namespace n4s {
143
+ interface EnforceCustomMatchers<R> {
144
+ isArrayOf: (...args: DropFirst<Parameters<typeof isArrayOf>>) => R;
145
+ loose: (...args: DropFirst<Parameters<typeof loose>>) => R;
146
+ shape: (...args: DropFirst<Parameters<typeof shape>>) => R;
147
+ optional: (...args: DropFirst<Parameters<typeof optional>>) => R;
148
+ }
149
+ }
150
+ }
151
+ export { partial };
package/types/vest.d.ts CHANGED
@@ -1,174 +1,4 @@
1
- type TEnforceContext = null | {
2
- meta: Record<string, any>;
3
- value: any;
4
- parent: () => TEnforceContext;
5
- };
6
- type DropFirst<T extends unknown[]> = T extends [
7
- unknown,
8
- ...infer U
9
- ] ? U : never;
10
- type TStringable = string | ((...args: any[]) => string);
11
- type TRuleReturn = boolean | {
12
- pass: boolean;
13
- message?: TStringable;
14
- };
15
- type TRuleDetailedResult = {
16
- pass: boolean;
17
- message?: string;
18
- };
19
- type TLazyRules = TRules<TLazyRuleMethods>;
20
- type TLazy = TLazyRules & TLazyRuleMethods;
21
- type TShapeObject = Record<any, TLazy>;
22
- type TLazyRuleMethods = TLazyRuleRunners & {
23
- message: (message: TLazyMessage) => TLazy;
24
- };
25
- type TLazyRuleRunners = {
26
- test: (value: unknown) => boolean;
27
- run: (value: unknown) => TRuleDetailedResult;
28
- };
29
- type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
30
- declare function allOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
31
- declare function anyOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
32
- declare function noneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
33
- declare function oneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
34
- declare function optional(value: any, ruleChain: TLazy): TRuleDetailedResult;
35
- declare function compounds(): {
36
- allOf: typeof allOf;
37
- anyOf: typeof anyOf;
38
- noneOf: typeof noneOf;
39
- oneOf: typeof oneOf;
40
- optional: typeof optional;
41
- };
42
- type TCompounds = ReturnType<typeof compounds>;
43
- type KCompounds = keyof TCompounds;
44
- type TArgs = any[];
45
- type TRuleValue = any;
46
- type TRuleBase = (value: TRuleValue, ...args: TArgs) => TRuleReturn;
47
- type TRule = Record<string, TRuleBase>;
48
- type TBaseRules = typeof baseRules;
49
- type KBaseRules = keyof TBaseRules;
50
- declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
51
- declare function endsWith(value: string, arg1: string): boolean;
52
- declare function equals(value: unknown, arg1: unknown): boolean;
53
- declare function greaterThan(value: number | string, gt: number | string): boolean;
54
- declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
55
- declare function inside(value: unknown, arg1: string | unknown[]): boolean;
56
- // The module is named "isArrayValue" since it
57
- // is conflicting with a nested npm dependency.
58
- // We may need to revisit this in the future.
59
- declare function isArray(value: unknown): value is Array<unknown>;
60
- declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
61
- declare function isBlank(value: unknown): boolean;
62
- declare function isBoolean(value: unknown): value is boolean;
63
- declare function isEmpty(value: unknown): boolean;
64
- declare function isNaN(value: unknown): boolean;
65
- declare function isNegative(value: number | string): boolean;
66
- declare function isNull(value: unknown): value is null;
67
- declare function isNumber(value: unknown): value is number;
68
- declare function isNumeric(value: string | number): boolean;
69
- declare function isStringValue(v: unknown): v is string;
70
- declare function isTruthy(value: unknown): boolean;
71
- declare function isUndefined(value?: unknown): boolean;
72
- declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
73
- declare function lessThan(value: string | number, lt: string | number): boolean;
74
- declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
75
- declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
76
- declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
77
- declare function matches(value: string, regex: RegExp | string): boolean;
78
- declare function numberEquals(value: string | number, eq: string | number): boolean;
79
- declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
80
- declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
81
- declare function startsWith(value: string, arg1: string): boolean;
82
- declare function shape(inputObject: Record<string, any>, shapeObject: TShapeObject): TRuleDetailedResult;
83
- declare function loose(inputObject: Record<string, any>, shapeObject: TShapeObject): TRuleDetailedResult;
84
- declare function isArrayOf(inputArray: any[], currentRule: TLazy): TRuleDetailedResult;
85
- declare const baseRules: {
86
- condition: typeof condition;
87
- doesNotEndWith: (value: string, arg1: string) => boolean;
88
- doesNotStartWith: (value: string, arg1: string) => boolean;
89
- endsWith: typeof endsWith;
90
- equals: typeof equals;
91
- greaterThan: typeof greaterThan;
92
- greaterThanOrEquals: typeof greaterThanOrEquals;
93
- gt: typeof greaterThan;
94
- gte: typeof greaterThanOrEquals;
95
- inside: typeof inside;
96
- isArray: typeof isArray;
97
- isBetween: typeof isBetween;
98
- isBlank: typeof isBlank;
99
- isBoolean: typeof isBoolean;
100
- isEmpty: typeof isEmpty;
101
- isEven: (value: any) => boolean;
102
- isFalsy: (value: unknown) => boolean;
103
- isNaN: typeof isNaN;
104
- isNegative: typeof isNegative;
105
- isNotArray: (value: unknown) => boolean;
106
- isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
107
- isNotBlank: (value: unknown) => boolean;
108
- isNotBoolean: (value: unknown) => boolean;
109
- isNotEmpty: (value: unknown) => boolean;
110
- isNotNaN: (value: unknown) => boolean;
111
- isNotNull: (value: unknown) => boolean;
112
- isNotNumber: (value: unknown) => boolean;
113
- isNotNumeric: (value: string | number) => boolean;
114
- isNotString: (v: unknown) => boolean;
115
- isNotUndefined: (value?: unknown) => boolean;
116
- isNull: typeof isNull;
117
- isNumber: typeof isNumber;
118
- isNumeric: typeof isNumeric;
119
- isOdd: (value: any) => boolean;
120
- isPositive: (value: string | number) => boolean;
121
- isString: typeof isStringValue;
122
- isTruthy: typeof isTruthy;
123
- isUndefined: typeof isUndefined;
124
- lengthEquals: typeof lengthEquals;
125
- lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
126
- lessThan: typeof lessThan;
127
- lessThanOrEquals: typeof lessThanOrEquals;
128
- longerThan: typeof longerThan;
129
- longerThanOrEquals: typeof longerThanOrEquals;
130
- lt: typeof lessThan;
131
- lte: typeof lessThanOrEquals;
132
- matches: typeof matches;
133
- notEquals: (value: unknown, arg1: unknown) => boolean;
134
- notInside: (value: unknown, arg1: string | unknown[]) => boolean;
135
- notMatches: (value: string, regex: string | RegExp) => boolean;
136
- numberEquals: typeof numberEquals;
137
- numberNotEquals: (value: string | number, eq: string | number) => boolean;
138
- shorterThan: typeof shorterThan;
139
- shorterThanOrEquals: typeof shorterThanOrEquals;
140
- startsWith: typeof startsWith;
141
- } & {
142
- allOf: typeof allOf;
143
- anyOf: typeof anyOf;
144
- noneOf: typeof noneOf;
145
- oneOf: typeof oneOf;
146
- optional: typeof optional;
147
- } & {
148
- shape: typeof shape;
149
- loose: typeof loose;
150
- isArrayOf: typeof isArrayOf;
151
- };
152
- type TRules<E = Record<string, unknown>> = Record<string, (...args: TArgs) => TRules & E> & {
153
- [P in KCompounds]: (...args: DropFirst<Parameters<TCompounds[P]>> | TArgs) => TRules & E;
154
- } & {
155
- [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules & E;
156
- };
157
- declare function enforceEager(value: TRuleValue): TRules;
158
- type TEnforceEager = typeof enforceEager;
159
- // Help needed improving the typings of this file.
160
- // Ideally, we'd be able to extend TShapeObject, but that's not possible.
161
- declare function partial<T extends Record<any, any>>(shapeObject: T): T;
162
- declare function modifiers(): {
163
- partial: typeof partial;
164
- };
165
- type TModifiers = ReturnType<typeof modifiers>;
166
- declare const enforce: TEnforce;
167
- type TEnforce = TEnforceEager & TLazyRules & TEnforceMethods;
168
- type TEnforceMethods = TModifiers & {
169
- context: () => TEnforceContext;
170
- extend: (customRules: TRule) => void;
171
- };
1
+ import { enforce } from 'n4s';
172
2
  /**
173
3
  * Reads the testObjects list and gets full validation result from it.
174
4
  */
@@ -227,34 +57,46 @@ interface IDone {
227
57
  cb: (res: TDraftResult) => void
228
58
  ]): IVestResult;
229
59
  }
230
- // eslint-disable-next-line max-lines-per-function
231
- declare function create<T extends (...args: any[]) => void>(suiteCallback: T): {
232
- (...args: Parameters<T>): IVestResult;
60
+ type CreateProperties = {
233
61
  get: () => TDraftResult;
234
62
  reset: () => void;
235
63
  remove: (fieldName: string) => void;
236
64
  };
65
+ type CB = (...args: any[]) => void;
66
+ type SuiteReturnType<T extends CB> = {
67
+ (...args: Parameters<T>): IVestResult;
68
+ } & CreateProperties;
69
+ declare function create<T extends CB>(suiteName: string, suiteCallback: T): SuiteReturnType<T>;
70
+ declare function create<T extends CB>(suiteCallback: T): SuiteReturnType<T>;
71
+ declare function each<T>(list: T[], callback: (arg: T, index: number) => void): void;
72
+ declare enum TestSeverity {
73
+ Error = "error",
74
+ Warning = "warning"
75
+ }
237
76
  declare class VestTest {
238
77
  fieldName: string;
239
78
  testFn: TTestFn;
240
79
  asyncTest?: TAsyncTest;
241
80
  groupName?: string;
242
81
  message?: string;
82
+ key?: null | string;
243
83
  id: string;
244
- warns: boolean;
84
+ severity: TestSeverity;
245
85
  status: KStatus;
246
- constructor(fieldName: string, testFn: TTestFn, { message, groupName }?: {
86
+ constructor(fieldName: string, testFn: TTestFn, { message, groupName, key }?: {
247
87
  message?: string;
248
88
  groupName?: string;
89
+ key?: string;
249
90
  });
250
91
  run(): TTestResult;
251
92
  setStatus(status: KStatus): void;
93
+ warns(): boolean;
252
94
  setPending(): void;
253
95
  fail(): void;
254
96
  done(): void;
255
97
  warn(): void;
256
98
  isFinalStatus(): boolean;
257
- skip(): void;
99
+ skip(force?: boolean): void;
258
100
  cancel(): void;
259
101
  omit(): void;
260
102
  valueOf(): boolean;
@@ -288,35 +130,28 @@ declare function skip(item: TExclusionItem): void;
288
130
  declare namespace skip {
289
131
  var group: (item: TExclusionItem) => void;
290
132
  }
291
- declare function skipWhen(conditional: boolean | ((...args: any[]) => boolean), callback: (...args: any[]) => void): void;
292
- /**
293
- * Sets a running test to warn only mode.
294
- */
295
- declare function warn(): void;
296
133
  /**
297
134
  * Runs a group callback.
298
135
  */
299
136
  declare function group(groupName: string, tests: () => void): void;
300
- declare function optional$0(optionals: TOptionalsInput): void;
137
+ declare function optional(optionals: TOptionalsInput): void;
301
138
  type TOptionalsInput = string | string[] | TOptionalsObject;
302
139
  type TOptionalsObject = Record<string, () => boolean>;
303
- declare function testBase(fieldName: string, ...args: [
304
- message: string,
305
- cb: TTestFn
306
- ]): VestTest;
307
- declare function testBase(fieldName: string, ...args: [
308
- cb: TTestFn
309
- ]): VestTest;
140
+ declare function skipWhen(conditional: boolean | ((draft: TDraftResult) => boolean), callback: (...args: any[]) => void): void;
141
+ declare function testBase(fieldName: string, message: string, cb: TTestFn): VestTest;
142
+ declare function testBase(fieldName: string, cb: TTestFn): VestTest;
143
+ declare function testBase(fieldName: string, message: string, cb: TTestFn, key: string): VestTest;
144
+ declare function testBase(fieldName: string, cb: TTestFn, key: string): VestTest;
310
145
  declare const _default: typeof testBase & {
311
- each: (table: any[]) => {
312
- (fieldName: TStringable, message: TStringable, cb: (...args: any[]) => TTestResult): VestTest[];
313
- (fieldName: TStringable, cb: (...args: any[]) => TTestResult): VestTest[];
314
- };
315
146
  memo: {
316
147
  (fieldName: string, test: TTestFn, deps: unknown[]): VestTest;
317
148
  (fieldName: string, message: string, test: TTestFn, deps: unknown[]): VestTest;
318
149
  };
319
150
  };
320
151
  declare const test: typeof _default;
321
- declare const VERSION = "4.0.0-dev-366a8b";
322
- export { test, create, only, skip, warn, group, optional$0 as optional, skipWhen, enforce, VERSION };
152
+ /**
153
+ * Sets a running test to warn only mode.
154
+ */
155
+ declare function warn(): void;
156
+ declare const VERSION = "4.0.0-dev-e266d9";
157
+ export { test, create, each, only, skip, warn, group, optional, skipWhen, enforce, VERSION };
package/docs/.nojekyll DELETED
File without changes
package/docs/README.md DELETED
@@ -1,113 +0,0 @@
1
- ![Vest](https://cdn.jsdelivr.net/gh/ealush/vest@assets/vest-logo.png 'Vest')
2
-
3
- # Vest 🦺 Declarative Validation Testing
4
-
5
- ![Github Stars](https://githubbadges.com/star.svg?user=ealush&repo=vest&style=flat)
6
- ![Npm downloads](https://img.shields.io/npm/dt/vest?label=Downloads&logo=npm)
7
-
8
- [![npm version](https://badge.fury.io/js/vest.svg)](https://badge.fury.io/js/vest) [![Build Status](https://travis-ci.org/ealush/vest.svg?branch=latest)](https://travis-ci.org/ealush/vest) [![Known Vulnerabilities](https://snyk.io/test/npm/vest/badge.svg)](https://snyk.io/test/npm/vest)
9
- ![minifiedSize](https://img.shields.io/bundlephobia/min/vest?color=blue&logo=npm)
10
-
11
- [![Join discord](https://img.shields.io/discord/757686103292641312?label=Join%20Discord&logo=discord&logoColor=green)](https://discord.gg/WmADZpJnSe)
12
-
13
- - [Documentation homepage](https://vestjs.dev)
14
- - **Try vest live**
15
- - [Vanilla JS Example](https://stackblitz.com/edit/vest-vanilla-support-example?file=validation.js)
16
- - ReactJS Examples:
17
- - [Example 1 (groups)](https://codesandbox.io/s/ecstatic-waterfall-4i2ne?file=/src/validate.js)
18
- - [Example 2 (Async)](https://codesandbox.io/s/youthful-williamson-loijb?file=/src/validate.js)
19
- - [Example 3](https://stackblitz.com/edit/vest-react-support-example?file=validation.js)
20
- - [Example 4](https://stackblitz.com/edit/vest-react-registration?file=validate.js)
21
- - [Example 5 (Password validator)](https://codesandbox.io/s/password-validator-example-6puvy?file=/src/validate.js)
22
- - [VueJS Example](https://codesandbox.io/s/vest-vue-example-1j6r8?file=/src/validations.js)
23
- - [Svelte Example](https://codesandbox.io/s/vestdocssvelteexample-k87t7?file=/validate.js)
24
-
25
- ## Tutorials
26
-
27
- [Step By Step React Tutorial](https://dev.to/ealush/dead-simple-form-validation-with-vest-5gf8)
28
-
29
- ## [Release Notes](https://github.com/ealush/vest/releases)
30
-
31
- ## 🦺 What is Vest?
32
-
33
- Vest is a validations library for JS apps that derives its syntax from modern JS unit testing frameworks such as Mocha or Jest. It is easy to learn due to its use of already common declarative patterns.
34
- It works great with user-input validation and with validating upon user interaction to provide the best possible user experience.
35
-
36
- The idea behind Vest is that your validations can be described as a 'spec' or a contract that reflects your form or feature structure. Your validations run in production, and they are framework agnostic - meaning Vest works well with React, Angular, Vue, or even without a framework at all.
37
-
38
- Using Vest for form validation can reduce bloat, improve feature readability and maintainability.
39
-
40
- **Basic Example**
41
- ![full](https://cdn.jsdelivr.net/gh/ealush/vest@assets/demos/full_3.gif 'full')
42
-
43
- **Memoized async test**
44
- ![memo](https://cdn.jsdelivr.net/gh/ealush/vest@assets/demos/memo.gif 'memo')
45
-
46
- ## ✅ Motivation
47
-
48
- Writing forms is an integral part of building web apps, and even though it may seem trivial at first - as your feature grows over time, so does your validation logic grows in complexity.
49
-
50
- Vest tries to remediate this by separating validation logic from feature logic so it is easier to maintain over time and refactor when needed.
51
-
52
- ## ✨ Vest's features
53
-
54
- - 🎨 Framework agnostic (BYOUI)
55
- - ⚡️ Rich, extendable, assertions library (enforce) ([doc](http://vestjs.dev/#/enforce))
56
- - 🚥 Multiple validations for the same field
57
- - ⚠️ Warning (non failing) tests ([doc](http://vestjs.dev/#/warn))
58
- - 📝 Validate only the fields the user interacted with ([doc](http://vestjs.dev/#/exclusion))
59
- - ⏳ Memoize async validations to reduce calls to the server ([doc](http://vestjs.dev/#/test?id=testmemo-for-memoized-tests))
60
- - 🚦 Test grouping ([doc](http://vestjs.dev/#/group))
61
-
62
- ## Example code ([Run in sandbox](https://codesandbox.io/s/vest-react-tutorial-finished-ztt8t?file=/src/validate.js))
63
-
64
- ```js
65
- import { create, only, test, enforce, warn, skipWhen } from 'vest';
66
-
67
- export default create((data = {}, currentField) => {
68
- only(currentField);
69
-
70
- test('username', 'Username is required', () => {
71
- enforce(data.username).isNotEmpty();
72
- });
73
-
74
- test('username', 'Username is too short', () => {
75
- enforce(data.username).longerThanOrEquals(3);
76
- });
77
-
78
- test('password', 'Password is required', () => {
79
- enforce(data.password).isNotEmpty();
80
- });
81
-
82
- test('password', 'Password must be at least 6 chars long', () => {
83
- enforce(data.password).longerThanOrEquals(6);
84
- });
85
-
86
- test('password', 'Password is weak, Maybe add a number?', () => {
87
- warn();
88
- enforce(data.password).matches(/[0-9]/);
89
- });
90
-
91
- skipWhen(!data.password, () => {
92
- test('confirm_password', 'Passwords do not match', () => {
93
- enforce(data.confirm_password).equals(data.password);
94
- });
95
- });
96
-
97
- test('email', 'Email Address is not valid', () => {
98
- enforce(data.email).isEmail();
99
- });
100
-
101
- test('tos', () => {
102
- enforce(data.tos).isTruthy();
103
- });
104
- });
105
- ```
106
-
107
- ## Why Vest?
108
-
109
- - 🧠 Vest is really easy to learn. You can take your existing knowledge of unit tests and transfer it to validations.
110
- - ✏️ Vest takes into account user interaction and warn only validations.
111
- - 🧱 Your validations are structured, making it very simple to read and write. All validation files look the same.
112
- - 🖇 Your validation logic is separate from your feature logic, preventing the spaghetti code that's usually involved with writing validations.
113
- - 🧩 Validation logic is easy to share and reuse across features.
Binary file
Binary file
package/docs/_sidebar.md DELETED
@@ -1,14 +0,0 @@
1
- - [Getting Started](./getting_started)
2
- - [enforce](./enforce)
3
- - [The result object](./result)
4
- - [test](./test)
5
- - [How to fail a test](./test#failing_a_test)
6
- - [Warn only tests](./warn)
7
- - [Grouping tests](./group)
8
- - [Optional Tests](./optional)
9
- - Advanced cases
10
- - [Cross Field Validations](./cross_field_validations)
11
- - [Excluding or including tests](./exclusion)
12
- - [Using with node](./node)
13
- - [Utilities](./utilities)
14
- - [Migration Guides](./migration)
@@ -1,33 +0,0 @@
1
- # Cross Field Validations
2
-
3
- Sometimes it is not enough to only validate a field by itself, because its validity is dependant on the validity or invalidity of a different field.
4
-
5
- Take for example the password confirmation field, by itself it serves no purpose, and as long as the password itself is not field, you might choose to not validate it to begin with. That's an **AND** relationship between fields. There can also be an **OR** relationship between fields, for example - either email address or phone number have to be filled, but neither is required as long the other was filled by the user.
6
-
7
- All these cases can be easily handled with Vest in different ways, depending on your requirements and validation strategy.
8
-
9
- ## skipWhen for conditionally skipping a test
10
-
11
- Sometimes you might want to skip running a certain validation based on some criteria, for example - only test for password strength if password DOESN'T have Errors. You could access the intermediate validation result and use it mid-run.
12
-
13
- ```js
14
- import { create, test, enforce } from 'vest';
15
-
16
- const suite = create((data = {}) => {
17
- test('password', 'Password is required', () => {
18
- enforce(data.password).isNotEmpty();
19
- });
20
- skipWhen(suite.get().hasErrors('password'), () => {
21
- test('password', 'Password is weak', () => {
22
- enforce(data.password).longerThan(8);
23
- });
24
- });
25
- });
26
- export default suite;
27
- ```
28
-
29
- ## Optional tests
30
-
31
- By default, all the tests inside Vest are required in order for the suite to be considered as "valid". Sometimes your app's logic may allow tests not to be filled out and you want them not to be accounted for in the suites validity. The optional utility allows you to specify logic to determine if a test is optional or not, for example - if it depends on a different test.
32
-
33
- Read more in the [optional tests doc](./optional).
package/docs/enforce.md DELETED
@@ -1,11 +0,0 @@
1
- # Enforce
2
-
3
- Enforce is Vest's assertion library. It is used to validate values within, or outside of a Vest test.
4
-
5
- ```js
6
- import { enforce, test } from 'vest';
7
-
8
- test('username', 'Must be at least three characters long', () => {
9
- enforce(username).longerThan(2);
10
- });
11
- ```