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.
Files changed (83) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +1 -2
  3. package/README.md +10 -4
  4. package/compose/package.json +7 -0
  5. package/compounds/package.json +7 -0
  6. package/dist/cjs/compose.development.js +139 -0
  7. package/dist/cjs/compose.js +7 -0
  8. package/dist/cjs/compose.production.js +1 -0
  9. package/dist/cjs/compounds.development.js +132 -0
  10. package/dist/cjs/compounds.js +7 -0
  11. package/dist/cjs/compounds.production.js +1 -0
  12. package/dist/cjs/n4s.development.js +602 -0
  13. package/dist/cjs/n4s.js +7 -0
  14. package/dist/cjs/n4s.production.js +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/schema.development.js +144 -0
  17. package/dist/cjs/schema.js +7 -0
  18. package/dist/cjs/schema.production.js +1 -0
  19. package/dist/es/compose.development.js +137 -0
  20. package/dist/es/compose.production.js +1 -0
  21. package/dist/es/compounds.development.js +130 -0
  22. package/dist/es/compounds.production.js +1 -0
  23. package/dist/es/n4s.development.js +597 -0
  24. package/dist/es/n4s.production.js +1 -0
  25. package/dist/es/package.json +1 -0
  26. package/dist/es/schema.development.js +140 -0
  27. package/dist/es/schema.production.js +1 -0
  28. package/dist/umd/compose.development.js +143 -0
  29. package/dist/umd/compose.production.js +1 -0
  30. package/dist/umd/compounds.development.js +136 -0
  31. package/dist/umd/compounds.production.js +1 -0
  32. package/dist/umd/n4s.development.js +606 -0
  33. package/dist/umd/n4s.production.js +1 -0
  34. package/dist/umd/schema.development.js +148 -0
  35. package/dist/umd/schema.production.js +1 -0
  36. package/docs/README.md +10 -4
  37. package/docs/_sidebar.md +2 -2
  38. package/docs/external.md +27 -0
  39. package/docs/rules.md +74 -0
  40. package/package.json +126 -67
  41. package/schema/package.json +7 -0
  42. package/tsconfig.json +8 -0
  43. package/types/compose.d.ts +134 -0
  44. package/types/compounds.d.ts +146 -0
  45. package/types/n4s.d.ts +167 -0
  46. package/types/schema.d.ts +151 -0
  47. package/config/rollup/enforce.js +0 -13
  48. package/config/rollup/enforceExtended.js +0 -10
  49. package/config/rollup/ensure.js +0 -10
  50. package/config/rollup/rollup.config.js +0 -5
  51. package/docs/business_rules.md +0 -80
  52. package/docs/custom.md +0 -54
  53. package/docs/ensure.md +0 -40
  54. package/enforceExtended.cjs.development.js +0 -1949
  55. package/enforceExtended.cjs.production.js +0 -1949
  56. package/enforceExtended.cjs.production.min.js +0 -1
  57. package/enforceExtended.umd.development.js +0 -1955
  58. package/enforceExtended.umd.production.js +0 -1972
  59. package/enforceExtended.umd.production.min.js +0 -1
  60. package/ensure.cjs.development.js +0 -418
  61. package/ensure.cjs.production.js +0 -418
  62. package/ensure.cjs.production.min.js +0 -1
  63. package/ensure.umd.development.js +0 -424
  64. package/ensure.umd.production.js +0 -444
  65. package/ensure.umd.production.min.js +0 -1
  66. package/esm/enforceExtended.mjs.development.js +0 -1947
  67. package/esm/enforceExtended.mjs.production.js +0 -1947
  68. package/esm/enforceExtended.mjs.production.min.js +0 -1
  69. package/esm/ensure.mjs.development.js +0 -416
  70. package/esm/ensure.mjs.production.js +0 -416
  71. package/esm/ensure.mjs.production.min.js +0 -1
  72. package/esm/n4s.mjs.development.js +0 -394
  73. package/esm/n4s.mjs.production.js +0 -394
  74. package/esm/n4s.mjs.production.min.js +0 -1
  75. package/esm/package.json +0 -1
  76. package/jest.config.js +0 -3
  77. package/n4s.cjs.development.js +0 -396
  78. package/n4s.cjs.production.js +0 -396
  79. package/n4s.cjs.production.min.js +0 -1
  80. package/n4s.umd.development.js +0 -402
  81. package/n4s.umd.index.js +0 -7
  82. package/n4s.umd.production.js +0 -419
  83. 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
- ## Using enforce without a testing framework
29
+ ## Non throwing validations
30
30
 
31
- If you wish to use enforce's functionality without it throwing errors, you can use its [ensure](./ensure) interface.
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
@@ -1,5 +1,5 @@
1
1
  - [Main](./)
2
2
  - [List of Enforce Rules](./rules)
3
- - [Business reated rules](./business_rules)
3
+ - [Schema validations](./compound)
4
4
  - [Custom Enforce Rules](./custom)
5
- - [Non throwing validations (ensure)](./ensure)
5
+ - [Consuming external rules](./external)
@@ -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
- "version": "2.2.0-rc.1",
4
- "description": "Enforce - Validation assertions library",
5
- "main": "./n4s.umd.index.js",
6
- "browser": "./n4s.umd.index.js",
7
- "module": "./esm/n4s.mjs.production.js",
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
- "browser": "./n4s.umd.index.js",
11
- "import": "./esm/n4s.mjs.production.js",
12
- "require": "./n4s.cjs.production.js",
13
- "node": "./n4s.cjs.production.js",
14
- "default": "./n4s.cjs.production.js"
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
- "./esm/n4s.mjs.development.js": "./esm/n4s.mjs.development.js",
17
- "./esm/n4s.mjs.production.js": "./esm/n4s.mjs.production.js",
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": "git+https://github.com/ealush/vest.git"
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
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "../dist/cjs/schema.js",
3
+ "module": "../dist/es/schema.production.js",
4
+ "name": "schema",
5
+ "types": "../types/schema.d.ts",
6
+ "private": true
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declarationMap": true,
5
+ "declarationDir": "./types",
6
+ "outDir": "./dist"
7
+ }
8
+ }
@@ -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 };