n4s 4.1.1 → 4.1.4

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,5 +1,5 @@
1
1
  {
2
- "version": "4.1.1",
2
+ "version": "4.1.4",
3
3
  "license": "MIT",
4
4
  "main": "./dist/cjs/n4s.js",
5
5
  "types": "./types/n4s.d.ts",
@@ -10,7 +10,7 @@
10
10
  "release": "vx release"
11
11
  },
12
12
  "dependencies": {
13
- "context": "^2.0.1"
13
+ "context": "^2.0.3"
14
14
  },
15
15
  "module": "./dist/es/n4s.production.js",
16
16
  "exports": {
@@ -134,5 +134,7 @@
134
134
  },
135
135
  "bugs": {
136
136
  "url": "https://github.com/ealush/vest.git/issues"
137
- }
137
+ },
138
+ "unpkg": "./dist/umd/n4s.production.js",
139
+ "jsdelivr": "./dist/umd/n4s.production.js"
138
140
  }
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "main": "../dist/cjs/schema.js",
3
3
  "module": "../dist/es/schema.production.js",
4
+ "unpkg": "../dist/umd/schema.production.js",
5
+ "jsdelivr": "../dist/umd/schema.production.js",
4
6
  "name": "schema",
5
7
  "types": "../types/schema.d.ts",
6
8
  "private": true
@@ -2,19 +2,19 @@ type DropFirst<T extends unknown[]> = T extends [
2
2
  unknown,
3
3
  ...infer U
4
4
  ] ? U : never;
5
- type TStringable = string | ((...args: any[]) => string);
6
- type TRuleReturn = boolean | {
5
+ type Stringable = string | ((...args: any[]) => string);
6
+ type RuleReturn = boolean | {
7
7
  pass: boolean;
8
- message?: TStringable;
8
+ message?: Stringable;
9
9
  };
10
- type TRuleDetailedResult = {
10
+ type RuleDetailedResult = {
11
11
  pass: boolean;
12
12
  message?: string;
13
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;
14
+ type Args = any[];
15
+ type BaseRules = typeof baseRules;
16
+ type KBaseRules = keyof BaseRules;
17
+ declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
18
18
  declare function endsWith(value: string, arg1: string): boolean;
19
19
  declare function equals(value: unknown, arg1: unknown): boolean;
20
20
  declare function greaterThan(value: number | string, gt: number | string): boolean;
@@ -35,6 +35,7 @@ declare function isNull(value: unknown): value is null;
35
35
  declare function isNullish(value: any): value is null | undefined;
36
36
  declare function isNumber(value: unknown): value is number;
37
37
  declare function isNumeric(value: string | number): boolean;
38
+ declare function isPositive(value: number | string): boolean;
38
39
  declare function isStringValue(v: unknown): v is string;
39
40
  declare function isTruthy(value: unknown): boolean;
40
41
  declare function isUndefined(value?: unknown): boolean;
@@ -89,7 +90,7 @@ declare const baseRules: {
89
90
  isNumber: typeof isNumber;
90
91
  isNumeric: typeof isNumeric;
91
92
  isOdd: (value: any) => boolean;
92
- isPositive: (value: string | number) => boolean;
93
+ isPositive: typeof isPositive;
93
94
  isString: typeof isStringValue;
94
95
  isTruthy: typeof isTruthy;
95
96
  isUndefined: typeof isUndefined;
@@ -112,29 +113,29 @@ declare const baseRules: {
112
113
  shorterThanOrEquals: typeof shorterThanOrEquals;
113
114
  startsWith: typeof startsWith;
114
115
  };
115
- type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
116
- [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
116
+ type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
117
+ [P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
117
118
  };
118
119
  /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
119
120
  declare global {
120
121
  namespace n4s {
121
- interface IRules<E> extends TRules<E> {
122
+ interface IRules<E> extends Rules<E> {
122
123
  }
123
124
  }
124
125
  }
125
- type TLazyRules = n4s.IRules<TLazyRuleMethods>;
126
- type TLazy = TLazyRules & TLazyRuleMethods &
126
+ type LazyRules = n4s.IRules<LazyRuleMethods>;
127
+ type Lazy = LazyRules & LazyRuleMethods &
127
128
  // This is a "catch all" hack to make TS happy while not
128
129
  // losing type hints
129
130
  Record<string, (...args: any[]) => any>;
130
- type TLazyRuleMethods = TLazyRuleRunners & {
131
- message: (message: TLazyMessage) => TLazy;
131
+ type LazyRuleMethods = LazyRuleRunners & {
132
+ message: (message: LazyMessage) => Lazy;
132
133
  };
133
- type TLazyRuleRunners = {
134
+ type LazyRuleRunners = {
134
135
  test: (value: unknown) => boolean;
135
- run: (value: unknown) => TRuleDetailedResult;
136
+ run: (value: unknown) => RuleDetailedResult;
136
137
  };
137
- type TComposeResult = TLazyRuleRunners & ((value: any) => void);
138
- type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
139
- declare function compose(...composites: TLazyRuleRunners[]): TComposeResult;
138
+ type ComposeResult = LazyRuleRunners & ((value: any) => void);
139
+ type LazyMessage = string | ((value: unknown, originalMessage?: Stringable) => string);
140
+ declare function compose(...composites: LazyRuleRunners[]): ComposeResult;
140
141
  export { compose as default };
@@ -2,19 +2,19 @@ type DropFirst<T extends unknown[]> = T extends [
2
2
  unknown,
3
3
  ...infer U
4
4
  ] ? U : never;
5
- type TStringable = string | ((...args: any[]) => string);
6
- type TRuleReturn = boolean | {
5
+ type Stringable = string | ((...args: any[]) => string);
6
+ type RuleReturn = boolean | {
7
7
  pass: boolean;
8
- message?: TStringable;
8
+ message?: Stringable;
9
9
  };
10
- type TRuleDetailedResult = {
10
+ type RuleDetailedResult = {
11
11
  pass: boolean;
12
12
  message?: string;
13
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;
14
+ type Args = any[];
15
+ type BaseRules = typeof baseRules;
16
+ type KBaseRules = keyof BaseRules;
17
+ declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
18
18
  declare function endsWith(value: string, arg1: string): boolean;
19
19
  declare function equals(value: unknown, arg1: unknown): boolean;
20
20
  declare function greaterThan(value: number | string, gt: number | string): boolean;
@@ -35,6 +35,7 @@ declare function isNull(value: unknown): value is null;
35
35
  declare function isNullish(value: any): value is null | undefined;
36
36
  declare function isNumber(value: unknown): value is number;
37
37
  declare function isNumeric(value: string | number): boolean;
38
+ declare function isPositive(value: number | string): boolean;
38
39
  declare function isStringValue(v: unknown): v is string;
39
40
  declare function isTruthy(value: unknown): boolean;
40
41
  declare function isUndefined(value?: unknown): boolean;
@@ -89,7 +90,7 @@ declare const baseRules: {
89
90
  isNumber: typeof isNumber;
90
91
  isNumeric: typeof isNumeric;
91
92
  isOdd: (value: any) => boolean;
92
- isPositive: (value: string | number) => boolean;
93
+ isPositive: typeof isPositive;
93
94
  isString: typeof isStringValue;
94
95
  isTruthy: typeof isTruthy;
95
96
  isUndefined: typeof isUndefined;
@@ -112,33 +113,33 @@ declare const baseRules: {
112
113
  shorterThanOrEquals: typeof shorterThanOrEquals;
113
114
  startsWith: typeof startsWith;
114
115
  };
115
- type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
116
- [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
116
+ type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
117
+ [P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
117
118
  };
118
119
  /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
119
120
  declare global {
120
121
  namespace n4s {
121
- interface IRules<E> extends TRules<E> {
122
+ interface IRules<E> extends Rules<E> {
122
123
  }
123
124
  }
124
125
  }
125
- type TLazyRules = n4s.IRules<TLazyRuleMethods>;
126
- type TLazy = TLazyRules & TLazyRuleMethods &
126
+ type LazyRules = n4s.IRules<LazyRuleMethods>;
127
+ type Lazy = LazyRules & LazyRuleMethods &
127
128
  // This is a "catch all" hack to make TS happy while not
128
129
  // losing type hints
129
130
  Record<string, (...args: any[]) => any>;
130
- type TLazyRuleMethods = TLazyRuleRunners & {
131
- message: (message: TLazyMessage) => TLazy;
131
+ type LazyRuleMethods = LazyRuleRunners & {
132
+ message: (message: LazyMessage) => Lazy;
132
133
  };
133
- type TLazyRuleRunners = {
134
+ type LazyRuleRunners = {
134
135
  test: (value: unknown) => boolean;
135
- run: (value: unknown) => TRuleDetailedResult;
136
+ run: (value: unknown) => RuleDetailedResult;
136
137
  };
137
- type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
138
- declare function allOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
139
- declare function anyOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
140
- declare function noneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
141
- declare function oneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
138
+ type LazyMessage = string | ((value: unknown, originalMessage?: Stringable) => string);
139
+ declare function allOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult;
140
+ declare function anyOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult;
141
+ declare function noneOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult;
142
+ declare function oneOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult;
142
143
  declare global {
143
144
  namespace n4s {
144
145
  interface EnforceCustomMatchers<R> {
package/types/n4s.d.ts CHANGED
@@ -10,31 +10,31 @@ type CTXType = {
10
10
  set?: boolean;
11
11
  parent: () => CTXType | null;
12
12
  };
13
- type TEnforceContext = null | {
13
+ type EnforceContext = null | {
14
14
  meta: Record<string, any>;
15
15
  value: any;
16
- parent: () => TEnforceContext;
16
+ parent: () => EnforceContext;
17
17
  };
18
18
  type DropFirst<T extends unknown[]> = T extends [
19
19
  unknown,
20
20
  ...infer U
21
21
  ] ? U : never;
22
- type TStringable = string | ((...args: any[]) => string);
23
- type TRuleReturn = boolean | {
22
+ type Stringable = string | ((...args: any[]) => string);
23
+ type RuleReturn = boolean | {
24
24
  pass: boolean;
25
- message?: TStringable;
25
+ message?: Stringable;
26
26
  };
27
- type TRuleDetailedResult = {
27
+ type RuleDetailedResult = {
28
28
  pass: boolean;
29
29
  message?: string;
30
30
  };
31
- type TArgs = any[];
32
- type TRuleValue = any;
33
- type TRuleBase = (value: TRuleValue, ...args: TArgs) => TRuleReturn;
34
- type TRule = Record<string, TRuleBase>;
35
- type TBaseRules = typeof baseRules;
36
- type KBaseRules = keyof TBaseRules;
37
- declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
31
+ type Args = any[];
32
+ type RuleValue = any;
33
+ type RuleBase = (value: RuleValue, ...args: Args) => RuleReturn;
34
+ type Rule = Record<string, RuleBase>;
35
+ type BaseRules = typeof baseRules;
36
+ type KBaseRules = keyof BaseRules;
37
+ declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
38
38
  declare function endsWith(value: string, arg1: string): boolean;
39
39
  declare function equals(value: unknown, arg1: unknown): boolean;
40
40
  declare function greaterThan(value: number | string, gt: number | string): boolean;
@@ -55,6 +55,7 @@ declare function isNull(value: unknown): value is null;
55
55
  declare function isNullish(value: any): value is null | undefined;
56
56
  declare function isNumber(value: unknown): value is number;
57
57
  declare function isNumeric(value: string | number): boolean;
58
+ declare function isPositive(value: number | string): boolean;
58
59
  declare function isStringValue(v: unknown): v is string;
59
60
  declare function isTruthy(value: unknown): boolean;
60
61
  declare function isUndefined(value?: unknown): boolean;
@@ -109,7 +110,7 @@ declare const baseRules: {
109
110
  isNumber: typeof isNumber;
110
111
  isNumeric: typeof isNumeric;
111
112
  isOdd: (value: any) => boolean;
112
- isPositive: (value: string | number) => boolean;
113
+ isPositive: typeof isPositive;
113
114
  isString: typeof isStringValue;
114
115
  isTruthy: typeof isTruthy;
115
116
  isUndefined: typeof isUndefined;
@@ -132,37 +133,37 @@ declare const baseRules: {
132
133
  shorterThanOrEquals: typeof shorterThanOrEquals;
133
134
  startsWith: typeof startsWith;
134
135
  };
135
- type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
136
- [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
136
+ type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
137
+ [P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
137
138
  };
138
139
  /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
139
140
  declare global {
140
141
  namespace n4s {
141
- interface IRules<E> extends TRules<E> {
142
+ interface IRules<E> extends Rules<E> {
142
143
  }
143
144
  }
144
145
  }
145
146
  type IRules = n4s.IRules<Record<string, any>>;
146
- declare function enforceEager(value: TRuleValue): IRules;
147
- type TEnforceEager = typeof enforceEager;
148
- type TLazyRules = n4s.IRules<TLazyRuleMethods>;
149
- type TLazy = TLazyRules & TLazyRuleMethods &
147
+ declare function enforceEager(value: RuleValue): IRules;
148
+ type EnforceEager = typeof enforceEager;
149
+ type LazyRules = n4s.IRules<LazyRuleMethods>;
150
+ type Lazy = LazyRules & LazyRuleMethods &
150
151
  // This is a "catch all" hack to make TS happy while not
151
152
  // losing type hints
152
153
  Record<string, (...args: any[]) => any>;
153
- type TLazyRuleMethods = TLazyRuleRunners & {
154
- message: (message: TLazyMessage) => TLazy;
154
+ type LazyRuleMethods = LazyRuleRunners & {
155
+ message: (message: LazyMessage) => Lazy;
155
156
  };
156
- type TLazyRuleRunners = {
157
+ type LazyRuleRunners = {
157
158
  test: (value: unknown) => boolean;
158
- run: (value: unknown) => TRuleDetailedResult;
159
+ run: (value: unknown) => RuleDetailedResult;
159
160
  };
160
- type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
161
- declare const enforce: TEnforce;
162
- type TEnforce = TEnforceMethods & TLazyRules & TEnforceEager;
163
- type TEnforceMethods = {
164
- context: () => TEnforceContext;
165
- extend: (customRules: TRule) => void;
161
+ type LazyMessage = string | ((value: unknown, originalMessage?: Stringable) => string);
162
+ declare const enforce: Enforce;
163
+ type Enforce = EnforceMethods & LazyRules & EnforceEager;
164
+ type EnforceMethods = {
165
+ context: () => EnforceContext;
166
+ extend: (customRules: Rule) => void;
166
167
  };
167
168
  declare global {
168
169
  namespace n4s {
package/types/schema.d.ts CHANGED
@@ -2,19 +2,19 @@ type DropFirst<T extends unknown[]> = T extends [
2
2
  unknown,
3
3
  ...infer U
4
4
  ] ? U : never;
5
- type TStringable = string | ((...args: any[]) => string);
6
- type TRuleReturn = boolean | {
5
+ type Stringable = string | ((...args: any[]) => string);
6
+ type RuleReturn = boolean | {
7
7
  pass: boolean;
8
- message?: TStringable;
8
+ message?: Stringable;
9
9
  };
10
- type TRuleDetailedResult = {
10
+ type RuleDetailedResult = {
11
11
  pass: boolean;
12
12
  message?: string;
13
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;
14
+ type Args = any[];
15
+ type BaseRules = typeof baseRules;
16
+ type KBaseRules = keyof BaseRules;
17
+ declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
18
18
  declare function endsWith(value: string, arg1: string): boolean;
19
19
  declare function equals(value: unknown, arg1: unknown): boolean;
20
20
  declare function greaterThan(value: number | string, gt: number | string): boolean;
@@ -35,6 +35,7 @@ declare function isNull(value: unknown): value is null;
35
35
  declare function isNullish(value: any): value is null | undefined;
36
36
  declare function isNumber(value: unknown): value is number;
37
37
  declare function isNumeric(value: string | number): boolean;
38
+ declare function isPositive(value: number | string): boolean;
38
39
  declare function isStringValue(v: unknown): v is string;
39
40
  declare function isTruthy(value: unknown): boolean;
40
41
  declare function isUndefined(value?: unknown): boolean;
@@ -89,7 +90,7 @@ declare const baseRules: {
89
90
  isNumber: typeof isNumber;
90
91
  isNumeric: typeof isNumeric;
91
92
  isOdd: (value: any) => boolean;
92
- isPositive: (value: string | number) => boolean;
93
+ isPositive: typeof isPositive;
93
94
  isString: typeof isStringValue;
94
95
  isTruthy: typeof isTruthy;
95
96
  isUndefined: typeof isUndefined;
@@ -112,37 +113,37 @@ declare const baseRules: {
112
113
  shorterThanOrEquals: typeof shorterThanOrEquals;
113
114
  startsWith: typeof startsWith;
114
115
  };
115
- type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
116
- [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
116
+ type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
117
+ [P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
117
118
  };
118
119
  /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
119
120
  declare global {
120
121
  namespace n4s {
121
- interface IRules<E> extends TRules<E> {
122
+ interface IRules<E> extends Rules<E> {
122
123
  }
123
124
  }
124
125
  }
125
- type TLazyRules = n4s.IRules<TLazyRuleMethods>;
126
- type TLazy = TLazyRules & TLazyRuleMethods &
126
+ type LazyRules = n4s.IRules<LazyRuleMethods>;
127
+ type Lazy = LazyRules & LazyRuleMethods &
127
128
  // This is a "catch all" hack to make TS happy while not
128
129
  // losing type hints
129
130
  Record<string, (...args: any[]) => any>;
130
- type TLazyRuleMethods = TLazyRuleRunners & {
131
- message: (message: TLazyMessage) => TLazy;
131
+ type LazyRuleMethods = LazyRuleRunners & {
132
+ message: (message: LazyMessage) => Lazy;
132
133
  };
133
- type TLazyRuleRunners = {
134
+ type LazyRuleRunners = {
134
135
  test: (value: unknown) => boolean;
135
- run: (value: unknown) => TRuleDetailedResult;
136
+ run: (value: unknown) => RuleDetailedResult;
136
137
  };
137
- type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
138
- declare function isArrayOf(inputArray: any[], currentRule: TLazyRuleRunners): TRuleDetailedResult;
139
- interface IShapeObject extends Record<string, any>, Record<string, TLazyRuleRunners> {
138
+ type LazyMessage = string | ((value: unknown, originalMessage?: Stringable) => string);
139
+ declare function isArrayOf(inputArray: any[], currentRule: LazyRuleRunners): RuleDetailedResult;
140
+ interface ShapeObject extends Record<string, any>, Record<string, LazyRuleRunners> {
140
141
  }
141
- declare function loose(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
142
- declare function optional(value: any, ruleChain: TLazy): TRuleDetailedResult;
143
- declare function shape(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
142
+ declare function loose(inputObject: Record<string, any>, shapeObject: ShapeObject): RuleDetailedResult;
143
+ declare function optional(value: any, ruleChain: Lazy): RuleDetailedResult;
144
+ declare function shape(inputObject: Record<string, any>, shapeObject: ShapeObject): RuleDetailedResult;
144
145
  // Help needed improving the typings of this file.
145
- // Ideally, we'd be able to extend IShapeObject, but that's not possible.
146
+ // Ideally, we'd be able to extend ShapeObject, but that's not possible.
146
147
  declare function partial<T extends Record<any, any>>(shapeObject: T): T;
147
148
  declare global {
148
149
  namespace n4s {