n4s 2.2.0-rc.1 → 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.
- package/CHANGELOG.md +129 -0
- package/LICENSE +1 -2
- package/README.md +10 -4
- package/compose/package.json +7 -0
- package/compounds/package.json +7 -0
- package/dist/cjs/compose.development.js +139 -0
- package/dist/cjs/compose.js +7 -0
- package/dist/cjs/compose.production.js +1 -0
- package/dist/cjs/compounds.development.js +132 -0
- package/dist/cjs/compounds.js +7 -0
- package/dist/cjs/compounds.production.js +1 -0
- package/dist/cjs/n4s.development.js +602 -0
- package/dist/cjs/n4s.js +7 -0
- package/dist/cjs/n4s.production.js +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/schema.development.js +144 -0
- package/dist/cjs/schema.js +7 -0
- package/dist/cjs/schema.production.js +1 -0
- package/dist/es/compose.development.js +137 -0
- package/dist/es/compose.production.js +1 -0
- package/dist/es/compounds.development.js +130 -0
- package/dist/es/compounds.production.js +1 -0
- package/dist/es/n4s.development.js +597 -0
- package/dist/es/n4s.production.js +1 -0
- package/dist/es/package.json +1 -0
- package/dist/es/schema.development.js +140 -0
- package/dist/es/schema.production.js +1 -0
- package/dist/umd/compose.development.js +143 -0
- package/dist/umd/compose.production.js +1 -0
- package/dist/umd/compounds.development.js +136 -0
- package/dist/umd/compounds.production.js +1 -0
- package/dist/umd/n4s.development.js +606 -0
- package/dist/umd/n4s.production.js +1 -0
- package/dist/umd/schema.development.js +148 -0
- package/dist/umd/schema.production.js +1 -0
- package/docs/README.md +10 -4
- package/docs/_sidebar.md +2 -2
- package/docs/external.md +27 -0
- package/docs/rules.md +74 -0
- package/package.json +126 -67
- package/schema/package.json +7 -0
- package/tsconfig.json +8 -0
- package/types/compose.d.ts +134 -0
- package/types/compounds.d.ts +146 -0
- package/types/n4s.d.ts +167 -0
- package/types/schema.d.ts +151 -0
- package/config/rollup/enforce.js +0 -13
- package/config/rollup/enforceExtended.js +0 -10
- package/config/rollup/ensure.js +0 -10
- package/config/rollup/rollup.config.js +0 -5
- package/docs/business_rules.md +0 -80
- package/docs/custom.md +0 -54
- package/docs/ensure.md +0 -40
- package/enforceExtended.cjs.development.js +0 -1949
- package/enforceExtended.cjs.production.js +0 -1949
- package/enforceExtended.cjs.production.min.js +0 -1
- package/enforceExtended.umd.development.js +0 -1955
- package/enforceExtended.umd.production.js +0 -1972
- package/enforceExtended.umd.production.min.js +0 -1
- package/ensure.cjs.development.js +0 -418
- package/ensure.cjs.production.js +0 -418
- package/ensure.cjs.production.min.js +0 -1
- package/ensure.umd.development.js +0 -424
- package/ensure.umd.production.js +0 -444
- package/ensure.umd.production.min.js +0 -1
- package/esm/enforceExtended.mjs.development.js +0 -1947
- package/esm/enforceExtended.mjs.production.js +0 -1947
- package/esm/enforceExtended.mjs.production.min.js +0 -1
- package/esm/ensure.mjs.development.js +0 -416
- package/esm/ensure.mjs.production.js +0 -416
- package/esm/ensure.mjs.production.min.js +0 -1
- package/esm/n4s.mjs.development.js +0 -394
- package/esm/n4s.mjs.production.js +0 -394
- package/esm/n4s.mjs.production.min.js +0 -1
- package/esm/package.json +0 -1
- package/jest.config.js +0 -3
- package/n4s.cjs.development.js +0 -396
- package/n4s.cjs.production.js +0 -396
- package/n4s.cjs.production.min.js +0 -1
- package/n4s.umd.development.js +0 -402
- package/n4s.umd.index.js +0 -7
- package/n4s.umd.production.js +0 -419
- package/n4s.umd.production.min.js +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('n4s')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'n4s'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}, global.n4s));
|
|
5
|
+
}(this, (function (exports, n4s) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function mapFirst(array, callback) {
|
|
8
|
+
var broke = false;
|
|
9
|
+
var breakoutValue = null;
|
|
10
|
+
for (var i = 0; i < array.length; i++) {
|
|
11
|
+
callback(array[i], breakout, i);
|
|
12
|
+
if (broke) {
|
|
13
|
+
return breakoutValue;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function breakout(value) {
|
|
17
|
+
broke = true;
|
|
18
|
+
breakoutValue = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isFunction(value) {
|
|
23
|
+
return typeof value === 'function';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function optionalFunctionValue(value) {
|
|
27
|
+
var args = [];
|
|
28
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
29
|
+
args[_i - 1] = arguments[_i];
|
|
30
|
+
}
|
|
31
|
+
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function defaultTo(callback, defaultValue) {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function ruleReturn(pass, message) {
|
|
40
|
+
var output = { pass: pass };
|
|
41
|
+
if (message) {
|
|
42
|
+
output.message = message;
|
|
43
|
+
}
|
|
44
|
+
return output;
|
|
45
|
+
}
|
|
46
|
+
function failing() {
|
|
47
|
+
return ruleReturn(false);
|
|
48
|
+
}
|
|
49
|
+
function passing() {
|
|
50
|
+
return ruleReturn(true);
|
|
51
|
+
}
|
|
52
|
+
function defaultToPassing(callback) {
|
|
53
|
+
return defaultTo(callback, passing());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function runLazyRule(lazyRule, currentValue) {
|
|
57
|
+
try {
|
|
58
|
+
return lazyRule.run(currentValue);
|
|
59
|
+
}
|
|
60
|
+
catch (_a) {
|
|
61
|
+
return failing();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isArrayOf(inputArray, currentRule) {
|
|
66
|
+
return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
|
|
67
|
+
var res = n4s.ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
|
|
68
|
+
if (!res.pass) {
|
|
69
|
+
breakout(res);
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function loose(inputObject, shapeObject) {
|
|
75
|
+
var _loop_1 = function (key) {
|
|
76
|
+
var currentValue = inputObject[key];
|
|
77
|
+
var currentRule = shapeObject[key];
|
|
78
|
+
var res = n4s.ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
|
|
79
|
+
return runLazyRule(currentRule, currentValue);
|
|
80
|
+
});
|
|
81
|
+
if (!res.pass) {
|
|
82
|
+
return { value: res };
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
for (var key in shapeObject) {
|
|
86
|
+
var state_1 = _loop_1(key);
|
|
87
|
+
if (typeof state_1 === "object")
|
|
88
|
+
return state_1.value;
|
|
89
|
+
}
|
|
90
|
+
return passing();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isNull(value) {
|
|
94
|
+
return value === null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isUndefined(value) {
|
|
98
|
+
return value === undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isNullish(value) {
|
|
102
|
+
return isNull(value) || isUndefined(value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function optional(value, ruleChain) {
|
|
106
|
+
if (isNullish(value)) {
|
|
107
|
+
return passing();
|
|
108
|
+
}
|
|
109
|
+
return runLazyRule(ruleChain, value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A safe hasOwnProperty access
|
|
114
|
+
*/
|
|
115
|
+
function hasOwnProperty(obj, key) {
|
|
116
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function shape(inputObject, shapeObject) {
|
|
120
|
+
var baseRes = loose(inputObject, shapeObject);
|
|
121
|
+
if (!baseRes.pass) {
|
|
122
|
+
return baseRes;
|
|
123
|
+
}
|
|
124
|
+
for (var key in inputObject) {
|
|
125
|
+
if (!hasOwnProperty(shapeObject, key)) {
|
|
126
|
+
return failing();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return passing();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Help needed improving the typings of this file.
|
|
133
|
+
// Ideally, we'd be able to extend IShapeObject, but that's not possible.
|
|
134
|
+
function partial(shapeObject) {
|
|
135
|
+
var output = {};
|
|
136
|
+
for (var key in shapeObject) {
|
|
137
|
+
output[key] = n4s.enforce.optional(shapeObject[key]);
|
|
138
|
+
}
|
|
139
|
+
return output;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
|
|
143
|
+
|
|
144
|
+
exports.partial = partial;
|
|
145
|
+
|
|
146
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
147
|
+
|
|
148
|
+
})));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("n4s")):"function"==typeof define&&define.amd?define(["exports","n4s"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).schema={},n.n4s)}(this,(function(n,e){function t(n,e){return n={pass:n},e&&(n.message=e),n}function r(n,e){try{return n.run(e)}catch(n){return t(!1)}}function o(n,o){var u,f=function(t){var u=n[t],f=o[t];if(!(t=e.ctx.run({value:u,set:!0,meta:{key:t}},(function(){return r(f,u)}))).pass)return{value:t}};for(u in o){var i=f(u);if("object"==typeof i)return i.value}return t(!0)}e.enforce.extend({isArrayOf:function(n,o){return function(n,e){var t;return null!==(t=function(n){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];return"function"==typeof n?n.apply(void 0,e):n}(n))&&void 0!==t?t:e}(function(n,e){function t(n){r=!0,o=n}for(var r=!1,o=null,u=0;u<n.length;u++)if(e(n[u],t,u),r)return o}(n,(function(n,t,u){(u=e.ctx.run({value:n,set:!0,meta:{index:u}},(function(){return r(o,n)}))).pass||t(u)})),t(!0))},loose:o,optional:function(n,e){return null==n?t(!0):r(e,n)},shape:function(n,e){var r=o(n,e);if(!r.pass)return r;for(var u in n)if(!Object.prototype.hasOwnProperty.call(e,u))return t(!1);return t(!0)}}),n.partial=function(n){var t,r={};for(t in n)r[t]=e.enforce.optional(n[t]);return r},Object.defineProperty(n,"__esModule",{value:!0})}));
|
package/docs/README.md
CHANGED
|
@@ -7,7 +7,7 @@ By default, enforce throws an error when your validations fail. These errors sho
|
|
|
7
7
|
You can extend Enforce per need, and you can add your custom validation rules in your app.
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
import enforce from 'n4s';
|
|
10
|
+
import { enforce } from 'n4s';
|
|
11
11
|
|
|
12
12
|
enforce(4).isNumber();
|
|
13
13
|
// passes
|
|
@@ -26,13 +26,19 @@ enforce(4)
|
|
|
26
26
|
npm i n4s
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
##
|
|
29
|
+
## Non throwing validations
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
> This functionality replaces the no-longer supported ensure export, as it performs the same functionality with better performance.
|
|
32
|
+
|
|
33
|
+
If you wish to use enforce's functionality safely with a boolean return interface instead, you can use its lazy validation interface:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
enforce.isArray().longerThan(3).test([1, 2, 3]);
|
|
37
|
+
```
|
|
32
38
|
|
|
33
39
|
## Content
|
|
34
40
|
|
|
35
41
|
- [List of Enforce rules](./rules)
|
|
36
42
|
- [Business reated rules](./business_rules)
|
|
43
|
+
- [Schema validation](./shape)
|
|
37
44
|
- [Custom Enforce Rules](./custom)
|
|
38
|
-
- [Non throwing validations (ensure)](./ensure)
|
package/docs/_sidebar.md
CHANGED
package/docs/external.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Consuming external rules
|
|
2
|
+
|
|
3
|
+
Enforce comes with the bare minimum of rules needed for input validation, not assuming your business logic constraints.
|
|
4
|
+
|
|
5
|
+
In some cases you might require more validations such as `isEmail` or `isPhoneNumber`. Enforce intentionally does not include those, since those validations may not necessarily reflect the way those validations should work in your app.
|
|
6
|
+
|
|
7
|
+
Luckily, there are numerous packages that can be used along with enforce to add those validations. One of the most popular, and most compatible is `validator.js`.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm i validator
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Validator.js is a pretty big package. To prevent it from unnecessarily increasing your bundle size for rules you don't use, import the ones you use individually.
|
|
14
|
+
|
|
15
|
+
Then add those rules with `enforce.extend`:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import isEmail from 'validator/es/lib/isEmail';
|
|
19
|
+
import isMobilePhone from 'validator/es/lib/isMobilePhone';
|
|
20
|
+
|
|
21
|
+
enforce.extend({ isEmail, isMobilePhone });
|
|
22
|
+
|
|
23
|
+
enforce('example@example.com').isEmail(); // ✅
|
|
24
|
+
enforce('example[at]example[dot]com').isEmail(); // 🚨
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
A full list of the supported validator.js rules can be found on [npmjs.com/package/validator](https://www.npmjs.com/package/validator).
|
package/docs/rules.md
CHANGED
|
@@ -28,6 +28,10 @@ Enforce rules are functions that allow you to test your data against different c
|
|
|
28
28
|
- [isFalsy](#isfalsy)
|
|
29
29
|
- [isArray](#isarray)
|
|
30
30
|
- [isNotArray](#isnotarray)
|
|
31
|
+
- [isBoolean](#isboolean)
|
|
32
|
+
- [isNotBoolean](#isnotboolean)
|
|
33
|
+
- [isBlank](#isblank)
|
|
34
|
+
- [isNotBlank](#isnotblank)
|
|
31
35
|
- [isNumber](#isnumber)
|
|
32
36
|
- [isNotNumber](#isnotnumber)
|
|
33
37
|
- [isNaN](#isNaN)
|
|
@@ -810,6 +814,76 @@ enforce('hello').isNotArray();
|
|
|
810
814
|
// passes
|
|
811
815
|
```
|
|
812
816
|
|
|
817
|
+
## isBoolean
|
|
818
|
+
|
|
819
|
+
### Description
|
|
820
|
+
|
|
821
|
+
Checks if a value is of type `boolean`.
|
|
822
|
+
Equals to `typeof value === 'boolean'`
|
|
823
|
+
|
|
824
|
+
### Usage examples:
|
|
825
|
+
|
|
826
|
+
```js
|
|
827
|
+
enforce(true).isBoolean();
|
|
828
|
+
enforce(false).isBoolean();
|
|
829
|
+
enforce(!!0).isBoolean();
|
|
830
|
+
// passes
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
```js
|
|
834
|
+
enforce([]).isBoolean();
|
|
835
|
+
enforce('143').isBoolean();
|
|
836
|
+
enforce('false').isBoolean();
|
|
837
|
+
// throws
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
## isNotBoolean
|
|
841
|
+
|
|
842
|
+
### Description
|
|
843
|
+
|
|
844
|
+
Checks if a value is of any type other than `boolean`.
|
|
845
|
+
Reverse implementation of `isBoolean`.
|
|
846
|
+
|
|
847
|
+
### Usage examples:
|
|
848
|
+
|
|
849
|
+
```js
|
|
850
|
+
enforce('143').isNotBoolean();
|
|
851
|
+
enforce(143).isNotBoolean();
|
|
852
|
+
// passes
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
```js
|
|
856
|
+
enforce(true).isNotBoolean();
|
|
857
|
+
enforce(false).isNotBoolean();
|
|
858
|
+
// throws
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
## isBlank
|
|
862
|
+
|
|
863
|
+
### Description
|
|
864
|
+
|
|
865
|
+
Determines wheter an enforced string contains only whitespaces
|
|
866
|
+
|
|
867
|
+
### Usage examples:
|
|
868
|
+
|
|
869
|
+
```js
|
|
870
|
+
enforce(' ').isBlank(); // passes
|
|
871
|
+
enforce('not blank').isBlank(); // throws
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
## isNotBlank
|
|
875
|
+
|
|
876
|
+
### Description
|
|
877
|
+
|
|
878
|
+
Determines wheter an enforced string contains at least a non-whitespace character
|
|
879
|
+
|
|
880
|
+
### Usage examples:
|
|
881
|
+
|
|
882
|
+
```js
|
|
883
|
+
enforce('not blank').isNotBlank(); // passes
|
|
884
|
+
enforce(' ').isNotBlank(); // throws
|
|
885
|
+
```
|
|
886
|
+
|
|
813
887
|
## isNumber
|
|
814
888
|
|
|
815
889
|
### Description
|
package/package.json
CHANGED
|
@@ -1,79 +1,138 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "4.0.0-dev-e266d9",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"main": "./dist/cjs/n4s.js",
|
|
5
|
+
"types": "./types/n4s.d.ts",
|
|
2
6
|
"name": "n4s",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
"author": "ealush",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "vx test",
|
|
10
|
+
"release": "vx release"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"context": "next"
|
|
14
|
+
},
|
|
15
|
+
"module": "./dist/es/n4s.production.js",
|
|
8
16
|
"exports": {
|
|
17
|
+
"./compose": {
|
|
18
|
+
"production": {
|
|
19
|
+
"types": "./types/compose.d.ts",
|
|
20
|
+
"browser": "./dist/es/compose.production.js",
|
|
21
|
+
"umd": "./dist/umd/compose.production.js",
|
|
22
|
+
"import": "./dist/es/compose.production.js",
|
|
23
|
+
"require": "./dist/cjs/compose.production.js",
|
|
24
|
+
"node": "./dist/cjs/compose.production.js",
|
|
25
|
+
"module": "./dist/es/compose.production.js",
|
|
26
|
+
"default": "./dist/cjs/compose.production.js"
|
|
27
|
+
},
|
|
28
|
+
"development": {
|
|
29
|
+
"types": "./types/compose.d.ts",
|
|
30
|
+
"browser": "./dist/es/compose.development.js",
|
|
31
|
+
"umd": "./dist/umd/compose.development.js",
|
|
32
|
+
"import": "./dist/es/compose.development.js",
|
|
33
|
+
"require": "./dist/cjs/compose.development.js",
|
|
34
|
+
"node": "./dist/cjs/compose.development.js",
|
|
35
|
+
"module": "./dist/es/compose.development.js",
|
|
36
|
+
"default": "./dist/cjs/compose.development.js"
|
|
37
|
+
},
|
|
38
|
+
"types": "./types/compose.d.ts",
|
|
39
|
+
"browser": "./dist/es/compose.production.js",
|
|
40
|
+
"umd": "./dist/umd/compose.production.js",
|
|
41
|
+
"import": "./dist/es/compose.production.js",
|
|
42
|
+
"require": "./dist/cjs/compose.production.js",
|
|
43
|
+
"node": "./dist/cjs/compose.production.js",
|
|
44
|
+
"module": "./dist/es/compose.production.js",
|
|
45
|
+
"default": "./dist/cjs/compose.production.js"
|
|
46
|
+
},
|
|
47
|
+
"./compounds": {
|
|
48
|
+
"production": {
|
|
49
|
+
"types": "./types/compounds.d.ts",
|
|
50
|
+
"browser": "./dist/es/compounds.production.js",
|
|
51
|
+
"umd": "./dist/umd/compounds.production.js",
|
|
52
|
+
"import": "./dist/es/compounds.production.js",
|
|
53
|
+
"require": "./dist/cjs/compounds.production.js",
|
|
54
|
+
"node": "./dist/cjs/compounds.production.js",
|
|
55
|
+
"module": "./dist/es/compounds.production.js",
|
|
56
|
+
"default": "./dist/cjs/compounds.production.js"
|
|
57
|
+
},
|
|
58
|
+
"development": {
|
|
59
|
+
"types": "./types/compounds.d.ts",
|
|
60
|
+
"browser": "./dist/es/compounds.development.js",
|
|
61
|
+
"umd": "./dist/umd/compounds.development.js",
|
|
62
|
+
"import": "./dist/es/compounds.development.js",
|
|
63
|
+
"require": "./dist/cjs/compounds.development.js",
|
|
64
|
+
"node": "./dist/cjs/compounds.development.js",
|
|
65
|
+
"module": "./dist/es/compounds.development.js",
|
|
66
|
+
"default": "./dist/cjs/compounds.development.js"
|
|
67
|
+
},
|
|
68
|
+
"types": "./types/compounds.d.ts",
|
|
69
|
+
"browser": "./dist/es/compounds.production.js",
|
|
70
|
+
"umd": "./dist/umd/compounds.production.js",
|
|
71
|
+
"import": "./dist/es/compounds.production.js",
|
|
72
|
+
"require": "./dist/cjs/compounds.production.js",
|
|
73
|
+
"node": "./dist/cjs/compounds.production.js",
|
|
74
|
+
"module": "./dist/es/compounds.production.js",
|
|
75
|
+
"default": "./dist/cjs/compounds.production.js"
|
|
76
|
+
},
|
|
77
|
+
"./schema": {
|
|
78
|
+
"production": {
|
|
79
|
+
"types": "./types/schema.d.ts",
|
|
80
|
+
"browser": "./dist/es/schema.production.js",
|
|
81
|
+
"umd": "./dist/umd/schema.production.js",
|
|
82
|
+
"import": "./dist/es/schema.production.js",
|
|
83
|
+
"require": "./dist/cjs/schema.production.js",
|
|
84
|
+
"node": "./dist/cjs/schema.production.js",
|
|
85
|
+
"module": "./dist/es/schema.production.js",
|
|
86
|
+
"default": "./dist/cjs/schema.production.js"
|
|
87
|
+
},
|
|
88
|
+
"development": {
|
|
89
|
+
"types": "./types/schema.d.ts",
|
|
90
|
+
"browser": "./dist/es/schema.development.js",
|
|
91
|
+
"umd": "./dist/umd/schema.development.js",
|
|
92
|
+
"import": "./dist/es/schema.development.js",
|
|
93
|
+
"require": "./dist/cjs/schema.development.js",
|
|
94
|
+
"node": "./dist/cjs/schema.development.js",
|
|
95
|
+
"module": "./dist/es/schema.development.js",
|
|
96
|
+
"default": "./dist/cjs/schema.development.js"
|
|
97
|
+
},
|
|
98
|
+
"types": "./types/schema.d.ts",
|
|
99
|
+
"browser": "./dist/es/schema.production.js",
|
|
100
|
+
"umd": "./dist/umd/schema.production.js",
|
|
101
|
+
"import": "./dist/es/schema.production.js",
|
|
102
|
+
"require": "./dist/cjs/schema.production.js",
|
|
103
|
+
"node": "./dist/cjs/schema.production.js",
|
|
104
|
+
"module": "./dist/es/schema.production.js",
|
|
105
|
+
"default": "./dist/cjs/schema.production.js"
|
|
106
|
+
},
|
|
9
107
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
108
|
+
"development": {
|
|
109
|
+
"types": "./types/n4s.d.ts",
|
|
110
|
+
"browser": "./dist/es/n4s.development.js",
|
|
111
|
+
"umd": "./dist/umd/n4s.development.js",
|
|
112
|
+
"import": "./dist/es/n4s.development.js",
|
|
113
|
+
"require": "./dist/cjs/n4s.development.js",
|
|
114
|
+
"node": "./dist/cjs/n4s.development.js",
|
|
115
|
+
"module": "./dist/es/n4s.development.js",
|
|
116
|
+
"default": "./dist/cjs/n4s.development.js"
|
|
117
|
+
},
|
|
118
|
+
"types": "./types/n4s.d.ts",
|
|
119
|
+
"browser": "./dist/es/n4s.production.js",
|
|
120
|
+
"umd": "./dist/umd/n4s.production.js",
|
|
121
|
+
"import": "./dist/es/n4s.production.js",
|
|
122
|
+
"require": "./dist/cjs/n4s.production.js",
|
|
123
|
+
"node": "./dist/cjs/n4s.production.js",
|
|
124
|
+
"module": "./dist/es/n4s.production.js",
|
|
125
|
+
"default": "./dist/cjs/n4s.production.js"
|
|
15
126
|
},
|
|
16
|
-
"./
|
|
17
|
-
"./
|
|
18
|
-
"./esm/n4s.mjs.production.min.js": "./esm/n4s.mjs.production.min.js",
|
|
19
|
-
"./n4s.cjs.development.js": "./n4s.cjs.development.js",
|
|
20
|
-
"./n4s.cjs.production.js": "./n4s.cjs.production.js",
|
|
21
|
-
"./n4s.cjs.production.min.js": "./n4s.cjs.production.min.js",
|
|
22
|
-
"./n4s.umd.development.js": "./n4s.umd.development.js",
|
|
23
|
-
"./n4s.umd.index.js": "./n4s.umd.index.js",
|
|
24
|
-
"./n4s.umd.production.js": "./n4s.umd.production.js",
|
|
25
|
-
"./n4s.umd.production.min.js": "./n4s.umd.production.min.js",
|
|
26
|
-
"./esm/ensure.mjs.development.js": "./esm/ensure.mjs.development.js",
|
|
27
|
-
"./esm/ensure.mjs.production.js": "./esm/ensure.mjs.production.js",
|
|
28
|
-
"./esm/ensure.mjs.production.min.js": "./esm/ensure.mjs.production.min.js",
|
|
29
|
-
"./ensure.cjs.development.js": "./ensure.cjs.development.js",
|
|
30
|
-
"./ensure.cjs.production.js": "./ensure.cjs.production.js",
|
|
31
|
-
"./ensure.cjs.production.min.js": "./ensure.cjs.production.min.js",
|
|
32
|
-
"./ensure.umd.development.js": "./ensure.umd.development.js",
|
|
33
|
-
"./ensure.umd.index.js": "./ensure.umd.index.js",
|
|
34
|
-
"./ensure.umd.production.js": "./ensure.umd.production.js",
|
|
35
|
-
"./ensure.umd.production.min.js": "./ensure.umd.production.min.js",
|
|
36
|
-
"./package.json": "./package.json"
|
|
127
|
+
"./package.json": "./package.json",
|
|
128
|
+
"./": "./"
|
|
37
129
|
},
|
|
38
130
|
"repository": {
|
|
39
131
|
"type": "git",
|
|
40
|
-
"url": "
|
|
132
|
+
"url": "https://github.com/ealush/vest.git",
|
|
133
|
+
"directory": "packages/n4s"
|
|
41
134
|
},
|
|
42
|
-
"keywords": [
|
|
43
|
-
"assertion",
|
|
44
|
-
"enforce",
|
|
45
|
-
"ensure",
|
|
46
|
-
"passable",
|
|
47
|
-
"vest",
|
|
48
|
-
"n4s",
|
|
49
|
-
"validations"
|
|
50
|
-
],
|
|
51
|
-
"author": "ealush",
|
|
52
|
-
"license": "MIT",
|
|
53
135
|
"bugs": {
|
|
54
|
-
"url": "https://github.com/ealush/vest/issues"
|
|
55
|
-
},
|
|
56
|
-
"homepage": "https://github.com/ealush/vest/tree/latest/packages/n4s",
|
|
57
|
-
"devDependencies": {
|
|
58
|
-
"@ampproject/rollup-plugin-closure-compiler": "^0.25.2",
|
|
59
|
-
"@babel/cli": "^7.8.4",
|
|
60
|
-
"@babel/core": "^7.9.0",
|
|
61
|
-
"@babel/plugin-transform-object-assign": "^7.8.3",
|
|
62
|
-
"@babel/preset-env": "^7.9.0",
|
|
63
|
-
"babel-eslint": "^10.0.2",
|
|
64
|
-
"babel-jest": "^26.0.0",
|
|
65
|
-
"eslint": "^7.0.0",
|
|
66
|
-
"faker": "^4.1.0",
|
|
67
|
-
"jest": "^26.0.0",
|
|
68
|
-
"lodash": "^4.17.15",
|
|
69
|
-
"rollup": "^2.0.3",
|
|
70
|
-
"rollup-plugin-babel": "^4.4.0",
|
|
71
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
72
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
73
|
-
"rollup-plugin-terser": "^6.1.0",
|
|
74
|
-
"validator": "^13.0.0"
|
|
75
|
-
},
|
|
76
|
-
"scripts": {
|
|
77
|
-
"build": "rollup -c ./config/rollup/rollup.config.js"
|
|
136
|
+
"url": "https://github.com/ealush/vest.git/issues"
|
|
78
137
|
}
|
|
79
138
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
type TLazyRuleMethods = TLazyRuleRunners & {
|
|
125
|
+
message: (message: TLazyMessage) => TLazy;
|
|
126
|
+
};
|
|
127
|
+
type TLazyRuleRunners = {
|
|
128
|
+
test: (value: unknown) => boolean;
|
|
129
|
+
run: (value: unknown) => TRuleDetailedResult;
|
|
130
|
+
};
|
|
131
|
+
type TComposeResult = TLazyRuleRunners & ((value: any) => void);
|
|
132
|
+
type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
|
|
133
|
+
declare function compose(...composites: TLazyRuleRunners[]): TComposeResult;
|
|
134
|
+
export { compose as default };
|