n4s 5.0.1 → 5.0.2
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 +0 -4
- package/README.md +2 -0
- package/compose/package.json +2 -0
- package/compounds/package.json +2 -0
- package/date/package.json +9 -0
- package/dist/cjs/compose.development.js +14 -97
- package/dist/cjs/compose.js +0 -1
- package/dist/cjs/compose.production.js +1 -1
- package/dist/cjs/compounds.development.js +30 -86
- package/dist/cjs/compounds.js +0 -1
- package/dist/cjs/compounds.production.js +1 -1
- package/dist/cjs/date.development.js +186 -0
- package/dist/cjs/date.js +6 -0
- package/dist/cjs/date.production.js +1 -0
- package/dist/cjs/email.development.js +363 -0
- package/dist/cjs/email.js +6 -0
- package/dist/cjs/email.production.js +1 -0
- package/dist/cjs/isURL.development.js +353 -0
- package/dist/cjs/isURL.js +6 -0
- package/dist/cjs/isURL.production.js +1 -0
- package/dist/cjs/n4s.development.js +205 -387
- package/dist/cjs/n4s.js +0 -1
- package/dist/cjs/n4s.production.js +1 -1
- package/dist/cjs/schema.development.js +19 -80
- package/dist/cjs/schema.js +0 -1
- package/dist/cjs/schema.production.js +1 -1
- package/dist/es/compose.development.js +14 -97
- package/dist/es/compose.production.js +1 -1
- package/dist/es/compounds.development.js +28 -84
- package/dist/es/compounds.production.js +1 -1
- package/dist/es/date.development.js +184 -0
- package/dist/es/date.production.js +1 -0
- package/dist/es/email.development.js +361 -0
- package/dist/es/email.production.js +1 -0
- package/dist/es/isURL.development.js +351 -0
- package/dist/es/isURL.production.js +1 -0
- package/dist/es/n4s.development.js +192 -372
- package/dist/es/n4s.production.js +1 -1
- package/dist/es/schema.development.js +16 -75
- package/dist/es/schema.production.js +1 -1
- package/dist/umd/compose.development.js +18 -102
- package/dist/umd/compose.production.js +1 -1
- package/dist/umd/compounds.development.js +34 -91
- package/dist/umd/compounds.production.js +1 -1
- package/dist/umd/date.development.js +190 -0
- package/dist/umd/date.production.js +1 -0
- package/dist/umd/email.development.js +367 -0
- package/dist/umd/email.production.js +1 -0
- package/dist/umd/isURL.development.js +357 -0
- package/dist/umd/isURL.production.js +1 -0
- package/dist/umd/n4s.development.js +209 -392
- package/dist/umd/n4s.production.js +1 -1
- package/dist/umd/schema.development.js +23 -85
- package/dist/umd/schema.production.js +1 -1
- package/email/package.json +9 -0
- package/isURL/package.json +9 -0
- package/package.json +162 -55
- package/schema/package.json +2 -0
- package/testUtils/TEnforceMock.ts +3 -0
- package/types/compose.d.ts +46 -55
- package/types/compose.d.ts.map +1 -0
- package/types/compounds.d.ts +50 -62
- package/types/compounds.d.ts.map +1 -0
- package/types/date.d.ts +18 -0
- package/types/date.d.ts.map +1 -0
- package/types/email.d.ts +12 -0
- package/types/email.d.ts.map +1 -0
- package/types/isURL.d.ts +12 -0
- package/types/isURL.d.ts.map +1 -0
- package/types/n4s.d.ts +62 -73
- package/types/n4s.d.ts.map +1 -0
- package/types/schema.d.ts +55 -63
- package/types/schema.d.ts.map +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +0 -44
- package/docs/_sidebar.md +0 -5
- package/docs/external.md +0 -27
- package/docs/index.html +0 -32
- package/docs/rules.md +0 -1282
- package/tsconfig.json +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{assign as n,bindNot as t,isStringValue as e,numberEquals as r,greaterThan as s,isArray as u,isNumeric as o,isNullish as i,isBoolean as c,isEmpty as a,isNotArray as f,isNotEmpty as l,isNotNull as N,isNotNullish as m,isNotNumeric as g,isNotUndefined as h,isNull as p,isPositive as d,isUndefined as y,lengthEquals as E,lengthNotEquals as v,longerThan as O,numberNotEquals as q,defaultTo as x,optionalFunctionValue as T,invariant as b,StringObject as w,mapFirst as B}from"vest-utils";import{createCascade as W}from"context";const S=W(((t,e)=>{const r={value:t.value,meta:t.meta||{}};return e?t.set?n(r,{parent:()=>function(n){return{value:n.value,meta:n.meta,parent:n.parent}}(e)}):e:n(r,{parent:P})}));function P(){return null}function k(n,t){return e(n)&&e(t)&&n.endsWith(t)}const A=t(k);function I(n,t){return n===t}const J=t(I);function K(n,t){return r(n,t)||s(n,t)}function R(n,t){return(u(t)||!(!e(t)||!e(n)))&&-1!==t.indexOf(n)}const U=t(R);function V(n,t){return o(n)&&o(t)&&Number(n)<Number(t)}function $(n,t){return r(n,t)||V(n,t)}function F(n,t,e){return K(n,t)&&$(n,e)}const M=t(F);function X(n){return i(n)||e(n)&&!n.trim()}const j=t(X),z=t(c),C=n=>!!o(n)&&n%2==0;function D(n,t){return n in t}const G=t(D);function H(n){return Number.isNaN(n)}const L=t(H);function Q(n){return V(n,0)}function Y(n){return Boolean("number"==typeof n)}const Z=t(Y),_=n=>!!o(n)&&n%2!=0,nn=t(e);function tn(n){return!!n}const en=t(tn);function rn(n,t){if(i(t))return!1;for(const e in t)if(t[e]===n)return!0;return!1}const sn=t(rn);function un(n,t){return K(n.length,t)}function on(n,t){return t instanceof RegExp?t.test(n):!!e(t)&&new RegExp(t).test(n)}const cn=t(on);function an(n,t){try{return t(n)}catch(n){return!1}}function fn(n,t){return V(n.length,t)}function ln(n,t){return $(n.length,t)}function Nn(n,t){return e(n)&&e(t)&&n.startsWith(t)}const mn=t(Nn);const gn={condition:an,doesNotEndWith:A,doesNotStartWith:mn,endsWith:k,equals:I,greaterThan:s,greaterThanOrEquals:K,gt:s,gte:K,inside:R,isArray:u,isBetween:F,isBlank:X,isBoolean:c,isEmpty:a,isEven:C,isFalsy:en,isKeyOf:D,isNaN:H,isNegative:Q,isNotArray:f,isNotBetween:M,isNotBlank:j,isNotBoolean:z,isNotEmpty:l,isNotKeyOf:G,isNotNaN:L,isNotNull:N,isNotNullish:m,isNotNumber:Z,isNotNumeric:g,isNotString:nn,isNotUndefined:h,isNotValueOf:sn,isNull:p,isNullish:i,isNumber:Y,isNumeric:o,isOdd:_,isPositive:d,isString:e,isTruthy:tn,isUndefined:y,isValueOf:rn,lengthEquals:E,lengthNotEquals:v,lessThan:V,lessThanOrEquals:$,longerThan:O,longerThanOrEquals:un,lt:V,lte:$,matches:on,notEquals:J,notInside:U,notMatches:cn,numberEquals:r,numberNotEquals:q,shorterThan:fn,shorterThanOrEquals:ln,startsWith:Nn};function hn(n){return gn[n]}function pn(n,t){const e={pass:n};return t&&(e.message=t),e}function dn(n){return x(n,pn(!0))}function yn(n,t,e,...r){return function(n){b(c(n)||n&&c(n.pass),"Incorrect return value for rule: "+JSON.stringify(n))}(n),c(n)?pn(n):pn(n.pass,T(n.message,t,e,...r))}function En(n){const t={message:function(n){return e=n,r}};let e;const r=new Proxy(t,{get:(s,u)=>{const o=hn(u);return o?function(t,r,s){return function(...u){const o=S.run({value:n},(()=>yn(r(n,...u),s,n,...u)));function c(){return i(e)?i(o.message)?`enforce/${s} failed with ${JSON.stringify(n)}`:w(o.message):w(e)}return b(o.pass,c()),t}}(r,o,u):t[u]}});return r}const vn=function(){const t={context:()=>S.useX(),extend:t=>{n(gn,t)}};return new Proxy(n(En,t),{get:(n,t)=>t in n?n[t]:hn(t)?function(n){const t=[];let e;return function n(r){return(...s)=>{const u=hn(r);t.push((n=>yn(u(n,...s),r,n,...s)));let o={run:n=>dn(B(t,((t,r)=>{var s;const u=S.run({value:n},(()=>t(n)));r(!u.pass,pn(!!u.pass,null!==(s=T(e,n,u.message))&&void 0!==s?s:u.message))}))),test:n=>o.run(n).pass,message:n=>(n&&(e=n),o)};return o=new Proxy(o,{get:(t,e)=>hn(e)?n(e):t[e]}),o}}(n)}(t):void 0})}();export{S as ctx,vn as enforce};
|
|
@@ -1,39 +1,8 @@
|
|
|
1
1
|
import { ctx, enforce } from 'n4s';
|
|
2
|
-
|
|
3
|
-
function mapFirst(array, callback) {
|
|
4
|
-
var broke = false;
|
|
5
|
-
var breakoutValue = null;
|
|
6
|
-
for (var i = 0; i < array.length; i++) {
|
|
7
|
-
callback(array[i], breakout, i);
|
|
8
|
-
if (broke) {
|
|
9
|
-
return breakoutValue;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function breakout(value) {
|
|
13
|
-
broke = true;
|
|
14
|
-
breakoutValue = value;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function isFunction(value) {
|
|
19
|
-
return typeof value === 'function';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function optionalFunctionValue(value) {
|
|
23
|
-
var args = [];
|
|
24
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
25
|
-
args[_i - 1] = arguments[_i];
|
|
26
|
-
}
|
|
27
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function defaultTo(callback, defaultValue) {
|
|
31
|
-
var _a;
|
|
32
|
-
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
33
|
-
}
|
|
2
|
+
import { defaultTo, mapFirst, isNullish, hasOwnProperty } from 'vest-utils';
|
|
34
3
|
|
|
35
4
|
function ruleReturn(pass, message) {
|
|
36
|
-
|
|
5
|
+
const output = { pass };
|
|
37
6
|
if (message) {
|
|
38
7
|
output.message = message;
|
|
39
8
|
}
|
|
@@ -59,45 +28,24 @@ function runLazyRule(lazyRule, currentValue) {
|
|
|
59
28
|
}
|
|
60
29
|
|
|
61
30
|
function isArrayOf(inputArray, currentRule) {
|
|
62
|
-
return defaultToPassing(mapFirst(inputArray,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
breakout(res);
|
|
66
|
-
}
|
|
31
|
+
return defaultToPassing(mapFirst(inputArray, (currentValue, breakout, index) => {
|
|
32
|
+
const res = ctx.run({ value: currentValue, set: true, meta: { index } }, () => runLazyRule(currentRule, currentValue));
|
|
33
|
+
breakout(!res.pass, res);
|
|
67
34
|
}));
|
|
68
35
|
}
|
|
69
36
|
|
|
70
37
|
function loose(inputObject, shapeObject) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return runLazyRule(currentRule, currentValue);
|
|
76
|
-
});
|
|
38
|
+
for (const key in shapeObject) {
|
|
39
|
+
const currentValue = inputObject[key];
|
|
40
|
+
const currentRule = shapeObject[key];
|
|
41
|
+
const res = ctx.run({ value: currentValue, set: true, meta: { key } }, () => runLazyRule(currentRule, currentValue));
|
|
77
42
|
if (!res.pass) {
|
|
78
|
-
return
|
|
43
|
+
return res;
|
|
79
44
|
}
|
|
80
|
-
};
|
|
81
|
-
for (var key in shapeObject) {
|
|
82
|
-
var state_1 = _loop_1(key);
|
|
83
|
-
if (typeof state_1 === "object")
|
|
84
|
-
return state_1.value;
|
|
85
45
|
}
|
|
86
46
|
return passing();
|
|
87
47
|
}
|
|
88
48
|
|
|
89
|
-
function isNull(value) {
|
|
90
|
-
return value === null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function isUndefined(value) {
|
|
94
|
-
return value === undefined;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function isNullish(value) {
|
|
98
|
-
return isNull(value) || isUndefined(value);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
49
|
function optional(value, ruleChain) {
|
|
102
50
|
if (isNullish(value)) {
|
|
103
51
|
return passing();
|
|
@@ -105,19 +53,12 @@ function optional(value, ruleChain) {
|
|
|
105
53
|
return runLazyRule(ruleChain, value);
|
|
106
54
|
}
|
|
107
55
|
|
|
108
|
-
/**
|
|
109
|
-
* A safe hasOwnProperty access
|
|
110
|
-
*/
|
|
111
|
-
function hasOwnProperty(obj, key) {
|
|
112
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
56
|
function shape(inputObject, shapeObject) {
|
|
116
|
-
|
|
57
|
+
const baseRes = loose(inputObject, shapeObject);
|
|
117
58
|
if (!baseRes.pass) {
|
|
118
59
|
return baseRes;
|
|
119
60
|
}
|
|
120
|
-
for (
|
|
61
|
+
for (const key in inputObject) {
|
|
121
62
|
if (!hasOwnProperty(shapeObject, key)) {
|
|
122
63
|
return failing();
|
|
123
64
|
}
|
|
@@ -126,15 +67,15 @@ function shape(inputObject, shapeObject) {
|
|
|
126
67
|
}
|
|
127
68
|
|
|
128
69
|
// Help needed improving the typings of this file.
|
|
129
|
-
// Ideally, we'd be able to extend
|
|
70
|
+
// Ideally, we'd be able to extend ShapeObject, but that's not possible.
|
|
130
71
|
function partial(shapeObject) {
|
|
131
|
-
|
|
132
|
-
for (
|
|
72
|
+
const output = {};
|
|
73
|
+
for (const key in shapeObject) {
|
|
133
74
|
output[key] = enforce.optional(shapeObject[key]);
|
|
134
75
|
}
|
|
135
76
|
return output;
|
|
136
77
|
}
|
|
137
78
|
|
|
138
|
-
enforce.extend({ isArrayOf
|
|
79
|
+
enforce.extend({ isArrayOf, loose, optional, shape });
|
|
139
80
|
|
|
140
81
|
export { partial };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ctx as n,enforce as
|
|
1
|
+
import{ctx as n,enforce as t}from"n4s";import{defaultTo as r,mapFirst as o,isNullish as e,hasOwnProperty as u}from"vest-utils";function s(n,t){const r={pass:n};return t&&(r.message=t),r}function i(){return s(!1)}function c(){return s(!0)}function f(n,t){try{return n.run(t)}catch(n){return i()}}function a(t,r){for(const o in r){const e=t[o],u=r[o],s=n.run({value:e,set:!0,meta:{key:o}},(()=>f(u,e)));if(!s.pass)return s}return c()}function p(n){const r={};for(const o in n)r[o]=t.optional(n[o]);return r}t.extend({isArrayOf:function(t,e){return u=o(t,((t,r,o)=>{const u=n.run({value:t,set:!0,meta:{index:o}},(()=>f(e,t)));r(!u.pass,u)})),r(u,c());var u},loose:a,optional:function(n,t){return e(n)?c():f(t,n)},shape:function(n,t){const r=a(n,t);if(!r.pass)return r;for(const r in n)if(!u(t,r))return i();return c()}});export{p as partial};
|
|
@@ -1,81 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('n4s')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['n4s'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory(global.n4s));
|
|
5
|
-
}(this, (function (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
|
-
/**
|
|
40
|
-
* Throws a timed out error.
|
|
41
|
-
*/
|
|
42
|
-
function throwError(devMessage, productionMessage) {
|
|
43
|
-
throw new Error(devMessage );
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* A safe hasOwnProperty access
|
|
48
|
-
*/
|
|
49
|
-
function hasOwnProperty(obj, key) {
|
|
50
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function isNumber(value) {
|
|
54
|
-
return Boolean(typeof value === 'number');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function lengthEquals(value, arg1) {
|
|
58
|
-
return value.length === Number(arg1);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function isEmpty(value) {
|
|
62
|
-
if (!value) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
else if (isNumber(value)) {
|
|
66
|
-
return value === 0;
|
|
67
|
-
}
|
|
68
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
69
|
-
return lengthEquals(value, 0);
|
|
70
|
-
}
|
|
71
|
-
else if (typeof value === 'object') {
|
|
72
|
-
return lengthEquals(Object.keys(value), 0);
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('n4s'), require('vest-utils')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['n4s', 'vest-utils'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory(global.n4s, global["vest-utils"]));
|
|
5
|
+
})(this, (function (n4s, vestUtils) { 'use strict';
|
|
76
6
|
|
|
77
7
|
function ruleReturn(pass, message) {
|
|
78
|
-
|
|
8
|
+
const output = { pass };
|
|
79
9
|
if (message) {
|
|
80
10
|
output.message = message;
|
|
81
11
|
}
|
|
@@ -88,7 +18,7 @@
|
|
|
88
18
|
return ruleReturn(true);
|
|
89
19
|
}
|
|
90
20
|
function defaultToPassing(callback) {
|
|
91
|
-
return defaultTo(callback, passing());
|
|
21
|
+
return vestUtils.defaultTo(callback, passing());
|
|
92
22
|
}
|
|
93
23
|
|
|
94
24
|
function runLazyRule(lazyRule, currentValue) {
|
|
@@ -101,38 +31,24 @@
|
|
|
101
31
|
}
|
|
102
32
|
|
|
103
33
|
/* eslint-disable max-lines-per-function */
|
|
104
|
-
function compose() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
return Object.assign(function (value) {
|
|
110
|
-
var res = run(value);
|
|
111
|
-
if (!res.pass) {
|
|
112
|
-
if (isEmpty(res.message)) {
|
|
113
|
-
throwError();
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// Explicitly throw a string so that vest.test can pick it up as the validation error message
|
|
117
|
-
throw res.message;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
34
|
+
function compose(...composites) {
|
|
35
|
+
return vestUtils.assign((value) => {
|
|
36
|
+
const res = run(value);
|
|
37
|
+
vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
|
|
120
38
|
}, {
|
|
121
|
-
run
|
|
122
|
-
test:
|
|
39
|
+
run,
|
|
40
|
+
test: (value) => run(value).pass,
|
|
123
41
|
});
|
|
124
42
|
function run(value) {
|
|
125
|
-
return n4s.ctx.run({ value
|
|
126
|
-
return defaultToPassing(mapFirst(composites,
|
|
43
|
+
return n4s.ctx.run({ value }, () => {
|
|
44
|
+
return defaultToPassing(vestUtils.mapFirst(composites, (composite, breakout) => {
|
|
127
45
|
/* HACK: Just a small white lie. ~~HELP WANTED~~.
|
|
128
|
-
The ideal is that instead of `
|
|
46
|
+
The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
|
|
129
47
|
The problem is that lazy rules can't really be passed to this function due to some generic hell
|
|
130
48
|
so we're limiting it to a small set of functions.
|
|
131
49
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
breakout(res);
|
|
135
|
-
}
|
|
50
|
+
const res = runLazyRule(composite, value);
|
|
51
|
+
breakout(!res.pass, res);
|
|
136
52
|
}));
|
|
137
53
|
});
|
|
138
54
|
}
|
|
@@ -140,4 +56,4 @@
|
|
|
140
56
|
|
|
141
57
|
return compose;
|
|
142
58
|
|
|
143
|
-
}))
|
|
59
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).compose=t(e.n4s,e["vest-utils"])}(this,(function(e,t){"use strict";function n(e,t){const n={pass:e};return t&&(n.message=t),n}function s(e){return t.defaultTo(e,n(!0))}function u(e,t){try{return e.run(t)}catch(e){return n(!1)}}return function(...n){return t.assign((e=>{const n=r(e);t.invariant(n.pass,t.StringObject(n.message))}),{run:r,test:e=>r(e).pass});function r(r){return e.ctx.run({value:r},(()=>s(t.mapFirst(n,((e,t)=>{const n=u(e,r);t(!n.pass,n)})))))}}}));
|
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('n4s')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['n4s'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s));
|
|
5
|
-
}(this, (function (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
|
-
}
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('n4s'), require('vest-utils')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['n4s', 'vest-utils'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s, global["vest-utils"]));
|
|
5
|
+
})(this, (function (n4s, vestUtils) { 'use strict';
|
|
38
6
|
|
|
39
7
|
function ruleReturn(pass, message) {
|
|
40
|
-
|
|
8
|
+
const output = { pass };
|
|
41
9
|
if (message) {
|
|
42
10
|
output.message = message;
|
|
43
11
|
}
|
|
@@ -50,10 +18,10 @@
|
|
|
50
18
|
return ruleReturn(true);
|
|
51
19
|
}
|
|
52
20
|
function defaultToFailing(callback) {
|
|
53
|
-
return defaultTo(callback, failing());
|
|
21
|
+
return vestUtils.defaultTo(callback, failing());
|
|
54
22
|
}
|
|
55
23
|
function defaultToPassing(callback) {
|
|
56
|
-
return defaultTo(callback, passing());
|
|
24
|
+
return vestUtils.defaultTo(callback, passing());
|
|
57
25
|
}
|
|
58
26
|
|
|
59
27
|
function runLazyRule(lazyRule, currentValue) {
|
|
@@ -65,72 +33,47 @@
|
|
|
65
33
|
}
|
|
66
34
|
}
|
|
67
35
|
|
|
68
|
-
function allOf(value) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
74
|
-
var res = runLazyRule(rule, value);
|
|
75
|
-
if (!res.pass) {
|
|
76
|
-
breakout(res);
|
|
77
|
-
}
|
|
36
|
+
function allOf(value, ...rules) {
|
|
37
|
+
return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
|
|
38
|
+
const res = runLazyRule(rule, value);
|
|
39
|
+
breakout(!res.pass, res);
|
|
78
40
|
}));
|
|
79
41
|
}
|
|
80
42
|
|
|
81
|
-
function anyOf(value) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
87
|
-
var res = runLazyRule(rule, value);
|
|
88
|
-
if (res.pass) {
|
|
89
|
-
breakout(res);
|
|
90
|
-
}
|
|
43
|
+
function anyOf(value, ...rules) {
|
|
44
|
+
return defaultToFailing(vestUtils.mapFirst(rules, (rule, breakout) => {
|
|
45
|
+
const res = runLazyRule(rule, value);
|
|
46
|
+
breakout(res.pass, res);
|
|
91
47
|
}));
|
|
92
48
|
}
|
|
93
49
|
|
|
94
|
-
function noneOf(value) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
100
|
-
var res = runLazyRule(rule, value);
|
|
101
|
-
if (res.pass) {
|
|
102
|
-
breakout(failing());
|
|
103
|
-
}
|
|
50
|
+
function noneOf(value, ...rules) {
|
|
51
|
+
return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
|
|
52
|
+
const res = runLazyRule(rule, value);
|
|
53
|
+
breakout(res.pass, failing());
|
|
104
54
|
}));
|
|
105
55
|
}
|
|
106
56
|
|
|
107
|
-
function
|
|
108
|
-
return value
|
|
57
|
+
function equals(value, arg1) {
|
|
58
|
+
return value === arg1;
|
|
109
59
|
}
|
|
60
|
+
vestUtils.bindNot(equals);
|
|
110
61
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
function oneOf(value) {
|
|
117
|
-
var rules = [];
|
|
118
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
119
|
-
rules[_i - 1] = arguments[_i];
|
|
120
|
-
}
|
|
121
|
-
var passing = [];
|
|
122
|
-
rules.some(function (rule) {
|
|
123
|
-
if (longerThan(passing, REQUIRED_COUNT)) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
var res = runLazyRule(rule, value);
|
|
62
|
+
const REQUIRED_COUNT = 1;
|
|
63
|
+
function oneOf(value, ...rules) {
|
|
64
|
+
let passingCount = 0;
|
|
65
|
+
rules.some(rule => {
|
|
66
|
+
const res = runLazyRule(rule, value);
|
|
127
67
|
if (res.pass) {
|
|
128
|
-
|
|
68
|
+
passingCount++;
|
|
69
|
+
}
|
|
70
|
+
if (vestUtils.greaterThan(passingCount, REQUIRED_COUNT)) {
|
|
71
|
+
return false;
|
|
129
72
|
}
|
|
130
73
|
});
|
|
131
|
-
return ruleReturn(
|
|
74
|
+
return ruleReturn(equals(passingCount, REQUIRED_COUNT));
|
|
132
75
|
}
|
|
133
76
|
|
|
134
|
-
n4s.enforce.extend({ allOf
|
|
77
|
+
n4s.enforce.extend({ allOf, anyOf, noneOf, oneOf });
|
|
135
78
|
|
|
136
|
-
}))
|
|
79
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).n4s,n["vest-utils"])}(this,(function(n,t){"use strict";function e(n,t){const e={pass:n};return t&&(e.message=t),e}function r(){return e(!1)}function s(n){return t.defaultTo(n,e(!0))}function u(n,t){try{return n.run(t)}catch(n){return r()}}function i(n,t){return n===t}t.bindNot(i);n.enforce.extend({allOf:function(n,...e){return s(t.mapFirst(e,((t,e)=>{const r=u(t,n);e(!r.pass,r)})))},anyOf:function(n,...e){return s=t.mapFirst(e,((t,e)=>{const r=u(t,n);e(r.pass,r)})),t.defaultTo(s,r());var s},noneOf:function(n,...e){return s(t.mapFirst(e,((t,e)=>{e(u(t,n).pass,r())})))},oneOf:function(n,...r){let s=0;return r.some((e=>{if(u(e,n).pass&&s++,t.greaterThan(s,1))return!1})),e(i(s,1))}})}));
|