n4s 3.0.0 → 4.0.0-dev-1aae50
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 +2 -5
- 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 +2 -5
- package/docs/_sidebar.md +1 -2
- package/docs/external.md +1 -28
- package/docs/rules.md +28 -0
- package/package.json +129 -42
- 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/jest/jest.setup.js +0 -14
- package/config/rollup/enforce.js +0 -8
- package/config/rollup/rollup.config.js +0 -3
- package/docs/compound.md +0 -187
- package/docs/custom.md +0 -52
- package/docs/template.md +0 -53
- package/esm/n4s.mjs.development.js +0 -1101
- package/esm/n4s.mjs.production.js +0 -1101
- 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 -1103
- package/n4s.cjs.production.js +0 -1103
- package/n4s.cjs.production.min.js +0 -1
- package/n4s.js +0 -7
- package/n4s.umd.development.js +0 -1109
- package/n4s.umd.production.js +0 -1192
- 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
|
|
@@ -33,10 +33,7 @@ npm i n4s
|
|
|
33
33
|
If you wish to use enforce's functionality safely with a boolean return interface instead, you can use its lazy validation interface:
|
|
34
34
|
|
|
35
35
|
```js
|
|
36
|
-
enforce
|
|
37
|
-
.isArray()
|
|
38
|
-
.longerThan(3)
|
|
39
|
-
.test([1,2,3])
|
|
36
|
+
enforce.isArray().longerThan(3).test([1, 2, 3]);
|
|
40
37
|
```
|
|
41
38
|
|
|
42
39
|
## Content
|
package/docs/_sidebar.md
CHANGED
package/docs/external.md
CHANGED
|
@@ -24,31 +24,4 @@ enforce('example@example.com').isEmail(); // ✅
|
|
|
24
24
|
enforce('example[at]example[dot]com').isEmail(); // 🚨
|
|
25
25
|
```
|
|
26
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).
|
|
28
|
-
|
|
29
|
-
- isAfter
|
|
30
|
-
- isBefore
|
|
31
|
-
- isBtcAddress
|
|
32
|
-
- isCreditCard
|
|
33
|
-
- isCurrency
|
|
34
|
-
- isDate
|
|
35
|
-
- isEmail
|
|
36
|
-
- isFQDN
|
|
37
|
-
- isIBAN
|
|
38
|
-
- isIdentityCard
|
|
39
|
-
- isIP
|
|
40
|
-
- isIPRange
|
|
41
|
-
- isJSON
|
|
42
|
-
- isJWT
|
|
43
|
-
- isMACAddress
|
|
44
|
-
- isMD5
|
|
45
|
-
- isMimeType
|
|
46
|
-
- isMobilePhone
|
|
47
|
-
- isMongoId
|
|
48
|
-
- isPassportNumber
|
|
49
|
-
- isPort
|
|
50
|
-
- isPostalCode
|
|
51
|
-
- isSlug
|
|
52
|
-
- isURL
|
|
53
|
-
- isTaxID
|
|
54
|
-
- isUUID
|
|
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
|
@@ -30,6 +30,8 @@ Enforce rules are functions that allow you to test your data against different c
|
|
|
30
30
|
- [isNotArray](#isnotarray)
|
|
31
31
|
- [isBoolean](#isboolean)
|
|
32
32
|
- [isNotBoolean](#isnotboolean)
|
|
33
|
+
- [isBlank](#isblank)
|
|
34
|
+
- [isNotBlank](#isnotblank)
|
|
33
35
|
- [isNumber](#isnumber)
|
|
34
36
|
- [isNotNumber](#isnotnumber)
|
|
35
37
|
- [isNaN](#isNaN)
|
|
@@ -856,6 +858,32 @@ enforce(false).isNotBoolean();
|
|
|
856
858
|
// throws
|
|
857
859
|
```
|
|
858
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
|
+
|
|
859
887
|
## isNumber
|
|
860
888
|
|
|
861
889
|
### Description
|
package/package.json
CHANGED
|
@@ -1,51 +1,138 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "4.0.0-dev-1aae50",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"main": "./dist/cjs/n4s.js",
|
|
5
|
+
"types": "./types/n4s.d.ts",
|
|
2
6
|
"name": "n4s",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
"author": "ealush",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "vx test",
|
|
10
|
+
"release": "vx release"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"context": "2.0.0-dev-1aae50"
|
|
14
|
+
},
|
|
15
|
+
"module": "./dist/es/n4s.production.js",
|
|
7
16
|
"exports": {
|
|
8
|
-
"./
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
},
|
|
19
107
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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"
|
|
126
|
+
},
|
|
127
|
+
"./package.json": "./package.json",
|
|
128
|
+
"./": "./"
|
|
26
129
|
},
|
|
27
130
|
"repository": {
|
|
28
131
|
"type": "git",
|
|
29
|
-
"url": "
|
|
132
|
+
"url": "https://github.com/ealush/vest.git",
|
|
133
|
+
"directory": "packages/n4s"
|
|
30
134
|
},
|
|
31
|
-
"keywords": [
|
|
32
|
-
"assertion",
|
|
33
|
-
"enforce",
|
|
34
|
-
"ensure",
|
|
35
|
-
"passable",
|
|
36
|
-
"vest",
|
|
37
|
-
"n4s",
|
|
38
|
-
"validations"
|
|
39
|
-
],
|
|
40
|
-
"author": "ealush",
|
|
41
|
-
"license": "MIT",
|
|
42
135
|
"bugs": {
|
|
43
|
-
"url": "https://github.com/ealush/vest/issues"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "rollup -c ./config/rollup/rollup.config.js",
|
|
48
|
-
"test": "jest"
|
|
49
|
-
},
|
|
50
|
-
"module": "./esm/n4s.mjs.production.js"
|
|
51
|
-
}
|
|
136
|
+
"url": "https://github.com/ealush/vest.git/issues"
|
|
137
|
+
}
|
|
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 };
|