n4s 5.0.0 → 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.
Files changed (70) hide show
  1. package/README.md +2 -0
  2. package/date/package.json +9 -0
  3. package/dist/cjs/compose.development.js +9 -13
  4. package/dist/cjs/compose.js +0 -1
  5. package/dist/cjs/compose.production.js +1 -1
  6. package/dist/cjs/compounds.development.js +16 -32
  7. package/dist/cjs/compounds.js +0 -1
  8. package/dist/cjs/compounds.production.js +1 -1
  9. package/dist/cjs/date.development.js +186 -0
  10. package/dist/cjs/date.js +6 -0
  11. package/dist/cjs/date.production.js +1 -0
  12. package/dist/cjs/email.development.js +363 -0
  13. package/dist/cjs/email.js +6 -0
  14. package/dist/cjs/email.production.js +1 -0
  15. package/dist/cjs/isURL.development.js +353 -0
  16. package/dist/cjs/isURL.js +6 -0
  17. package/dist/cjs/isURL.production.js +1 -0
  18. package/dist/cjs/n4s.development.js +134 -213
  19. package/dist/cjs/n4s.js +0 -1
  20. package/dist/cjs/n4s.production.js +1 -1
  21. package/dist/cjs/schema.development.js +13 -22
  22. package/dist/cjs/schema.js +0 -1
  23. package/dist/cjs/schema.production.js +1 -1
  24. package/dist/es/compose.development.js +11 -15
  25. package/dist/es/compose.production.js +1 -1
  26. package/dist/es/compounds.development.js +16 -32
  27. package/dist/es/compounds.production.js +1 -1
  28. package/dist/es/date.development.js +184 -0
  29. package/dist/es/date.production.js +1 -0
  30. package/dist/es/email.development.js +361 -0
  31. package/dist/es/email.production.js +1 -0
  32. package/dist/es/isURL.development.js +351 -0
  33. package/dist/es/isURL.production.js +1 -0
  34. package/dist/es/n4s.development.js +155 -232
  35. package/dist/es/n4s.production.js +1 -1
  36. package/dist/es/schema.development.js +13 -20
  37. package/dist/es/schema.production.js +1 -1
  38. package/dist/umd/compose.development.js +12 -16
  39. package/dist/umd/compose.production.js +1 -1
  40. package/dist/umd/compounds.development.js +19 -35
  41. package/dist/umd/compounds.production.js +1 -1
  42. package/dist/umd/date.development.js +190 -0
  43. package/dist/umd/date.production.js +1 -0
  44. package/dist/umd/email.development.js +367 -0
  45. package/dist/umd/email.production.js +1 -0
  46. package/dist/umd/isURL.development.js +357 -0
  47. package/dist/umd/isURL.production.js +1 -0
  48. package/dist/umd/n4s.development.js +137 -216
  49. package/dist/umd/n4s.production.js +1 -1
  50. package/dist/umd/schema.development.js +16 -25
  51. package/dist/umd/schema.production.js +1 -1
  52. package/email/package.json +9 -0
  53. package/isURL/package.json +9 -0
  54. package/package.json +159 -55
  55. package/testUtils/TEnforceMock.ts +3 -0
  56. package/types/compose.d.ts +22 -23
  57. package/types/compose.d.ts.map +1 -0
  58. package/types/compounds.d.ts +22 -24
  59. package/types/compounds.d.ts.map +1 -0
  60. package/types/date.d.ts +18 -0
  61. package/types/date.d.ts.map +1 -0
  62. package/types/email.d.ts +12 -0
  63. package/types/email.d.ts.map +1 -0
  64. package/types/isURL.d.ts +12 -0
  65. package/types/isURL.d.ts.map +1 -0
  66. package/types/n4s.d.ts +30 -27
  67. package/types/n4s.d.ts.map +1 -0
  68. package/types/schema.d.ts +22 -23
  69. package/types/schema.d.ts.map +1 -0
  70. package/tsconfig.json +0 -8
@@ -2,7 +2,7 @@ import { ctx, enforce } from 'n4s';
2
2
  import { defaultTo, mapFirst, isNullish, hasOwnProperty } from 'vest-utils';
3
3
 
4
4
  function ruleReturn(pass, message) {
5
- var output = { pass: pass };
5
+ const output = { pass };
6
6
  if (message) {
7
7
  output.message = message;
8
8
  }
@@ -28,27 +28,20 @@ function runLazyRule(lazyRule, currentValue) {
28
28
  }
29
29
 
30
30
  function isArrayOf(inputArray, currentRule) {
31
- return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
32
- var res = ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
31
+ return defaultToPassing(mapFirst(inputArray, (currentValue, breakout, index) => {
32
+ const res = ctx.run({ value: currentValue, set: true, meta: { index } }, () => runLazyRule(currentRule, currentValue));
33
33
  breakout(!res.pass, res);
34
34
  }));
35
35
  }
36
36
 
37
37
  function loose(inputObject, shapeObject) {
38
- var _loop_1 = function (key) {
39
- var currentValue = inputObject[key];
40
- var currentRule = shapeObject[key];
41
- var res = ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
42
- return runLazyRule(currentRule, currentValue);
43
- });
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));
44
42
  if (!res.pass) {
45
- return { value: res };
43
+ return res;
46
44
  }
47
- };
48
- for (var key in shapeObject) {
49
- var state_1 = _loop_1(key);
50
- if (typeof state_1 === "object")
51
- return state_1.value;
52
45
  }
53
46
  return passing();
54
47
  }
@@ -61,11 +54,11 @@ function optional(value, ruleChain) {
61
54
  }
62
55
 
63
56
  function shape(inputObject, shapeObject) {
64
- var baseRes = loose(inputObject, shapeObject);
57
+ const baseRes = loose(inputObject, shapeObject);
65
58
  if (!baseRes.pass) {
66
59
  return baseRes;
67
60
  }
68
- for (var key in inputObject) {
61
+ for (const key in inputObject) {
69
62
  if (!hasOwnProperty(shapeObject, key)) {
70
63
  return failing();
71
64
  }
@@ -76,13 +69,13 @@ function shape(inputObject, shapeObject) {
76
69
  // Help needed improving the typings of this file.
77
70
  // Ideally, we'd be able to extend ShapeObject, but that's not possible.
78
71
  function partial(shapeObject) {
79
- var output = {};
80
- for (var key in shapeObject) {
72
+ const output = {};
73
+ for (const key in shapeObject) {
81
74
  output[key] = enforce.optional(shapeObject[key]);
82
75
  }
83
76
  return output;
84
77
  }
85
78
 
86
- enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
79
+ enforce.extend({ isArrayOf, loose, optional, shape });
87
80
 
88
81
  export { partial };
@@ -1 +1 @@
1
- import{defaultTo as r,mapFirst as n,isNullish as t,hasOwnProperty as e}from"vest-utils";import{ctx as u,enforce as o}from"n4s";function i(r,n){return r={pass:r},n&&(r.message=n),r}function a(r,n){try{return r.run(n)}catch(r){return i(!1)}}function f(r,n){function t(t){var e=r[t],o=n[t];if(!(t=u.run({value:e,set:!0,meta:{key:t}},(function(){return a(o,e)}))).pass)return{value:t}}for(var e in n){var o=t(e);if("object"==typeof o)return o.value}return i(!0)}o.extend({isArrayOf:function(t,e){return r(n(t,(function(r,n,t){n(!(t=u.run({value:r,set:!0,meta:{index:t}},(function(){return a(e,r)}))).pass,t)})),i(!0))},loose:f,optional:function(r,n){return t(r)?i(!0):a(n,r)},shape:function(r,n){var t=f(r,n);if(!t.pass)return t;for(var u in r)if(!e(n,u))return i(!1);return i(!0)}});export function partial(r){var n,t={};for(n in r)t[n]=o.optional(r[n]);return t}
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,11 +1,11 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('n4s'), require('vest-utils')) :
3
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';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory(global.n4s, global["vest-utils"]));
5
+ })(this, (function (n4s, vestUtils) { 'use strict';
6
6
 
7
7
  function ruleReturn(pass, message) {
8
- var output = { pass: pass };
8
+ const output = { pass };
9
9
  if (message) {
10
10
  output.message = message;
11
11
  }
@@ -31,27 +31,23 @@
31
31
  }
32
32
 
33
33
  /* eslint-disable max-lines-per-function */
34
- function compose() {
35
- var composites = [];
36
- for (var _i = 0; _i < arguments.length; _i++) {
37
- composites[_i] = arguments[_i];
38
- }
39
- return vestUtils.assign(function (value) {
40
- var res = run(value);
34
+ function compose(...composites) {
35
+ return vestUtils.assign((value) => {
36
+ const res = run(value);
41
37
  vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
42
38
  }, {
43
- run: run,
44
- test: function (value) { return run(value).pass; }
39
+ run,
40
+ test: (value) => run(value).pass,
45
41
  });
46
42
  function run(value) {
47
- return n4s.ctx.run({ value: value }, function () {
48
- return defaultToPassing(vestUtils.mapFirst(composites, function (composite, breakout) {
43
+ return n4s.ctx.run({ value }, () => {
44
+ return defaultToPassing(vestUtils.mapFirst(composites, (composite, breakout) => {
49
45
  /* HACK: Just a small white lie. ~~HELP WANTED~~.
50
46
  The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
51
47
  The problem is that lazy rules can't really be passed to this function due to some generic hell
52
48
  so we're limiting it to a small set of functions.
53
49
  */
54
- var res = runLazyRule(composite, value);
50
+ const res = runLazyRule(composite, value);
55
51
  breakout(!res.pass, res);
56
52
  }));
57
53
  });
@@ -60,4 +56,4 @@
60
56
 
61
57
  return compose;
62
58
 
63
- })));
59
+ }));
@@ -1 +1 @@
1
- "use strict";!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],n):(e="undefined"!=typeof globalThis?globalThis:e||self).compose=n(e.n4s,e["vest-utils"])}(this,(function(e,n){function t(e,n){return e={pass:e},n&&(e.message=n),e}return function(){function s(s){return e.ctx.run({value:s},(function(){return n.defaultTo(n.mapFirst(u,(function(e,n){try{var u=e.run(s)}catch(e){u=t(!1)}n(!u.pass,u)})),t(!0))}))}for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];return n.assign((function(e){e=s(e),n.invariant(e.pass,n.StringObject(e.message))}),{run:s,test:function(e){return s(e).pass}})}}));
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,11 +1,11 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('n4s'), require('vest-utils')) :
3
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';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s, global["vest-utils"]));
5
+ })(this, (function (n4s, vestUtils) { 'use strict';
6
6
 
7
7
  function ruleReturn(pass, message) {
8
- var output = { pass: pass };
8
+ const output = { pass };
9
9
  if (message) {
10
10
  output.message = message;
11
11
  }
@@ -33,35 +33,23 @@
33
33
  }
34
34
  }
35
35
 
36
- function allOf(value) {
37
- var rules = [];
38
- for (var _i = 1; _i < arguments.length; _i++) {
39
- rules[_i - 1] = arguments[_i];
40
- }
41
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
42
- var res = runLazyRule(rule, value);
36
+ function allOf(value, ...rules) {
37
+ return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
38
+ const res = runLazyRule(rule, value);
43
39
  breakout(!res.pass, res);
44
40
  }));
45
41
  }
46
42
 
47
- function anyOf(value) {
48
- var rules = [];
49
- for (var _i = 1; _i < arguments.length; _i++) {
50
- rules[_i - 1] = arguments[_i];
51
- }
52
- return defaultToFailing(vestUtils.mapFirst(rules, function (rule, breakout) {
53
- var res = runLazyRule(rule, value);
43
+ function anyOf(value, ...rules) {
44
+ return defaultToFailing(vestUtils.mapFirst(rules, (rule, breakout) => {
45
+ const res = runLazyRule(rule, value);
54
46
  breakout(res.pass, res);
55
47
  }));
56
48
  }
57
49
 
58
- function noneOf(value) {
59
- var rules = [];
60
- for (var _i = 1; _i < arguments.length; _i++) {
61
- rules[_i - 1] = arguments[_i];
62
- }
63
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
64
- var res = runLazyRule(rule, value);
50
+ function noneOf(value, ...rules) {
51
+ return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
52
+ const res = runLazyRule(rule, value);
65
53
  breakout(res.pass, failing());
66
54
  }));
67
55
  }
@@ -71,15 +59,11 @@
71
59
  }
72
60
  vestUtils.bindNot(equals);
73
61
 
74
- var REQUIRED_COUNT = 1;
75
- function oneOf(value) {
76
- var rules = [];
77
- for (var _i = 1; _i < arguments.length; _i++) {
78
- rules[_i - 1] = arguments[_i];
79
- }
80
- var passingCount = 0;
81
- rules.some(function (rule) {
82
- 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);
83
67
  if (res.pass) {
84
68
  passingCount++;
85
69
  }
@@ -90,6 +74,6 @@
90
74
  return ruleReturn(equals(passingCount, REQUIRED_COUNT));
91
75
  }
92
76
 
93
- n4s.enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
77
+ n4s.enforce.extend({ allOf, anyOf, noneOf, oneOf });
94
78
 
95
- })));
79
+ }));
@@ -1 +1 @@
1
- "use strict";!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).n4s,n["vest-utils"])}(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)}}e.bindNot((function(n,e){return n===e})),n.enforce.extend({allOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];return e.defaultTo(e.mapFirst(f,(function(e,t){t(!(e=r(e,n)).pass,e)})),t(!0))},anyOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];return e.defaultTo(e.mapFirst(f,(function(e,t){t((e=r(e,n)).pass,e)})),t(!1))},noneOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];return e.defaultTo(e.mapFirst(f,(function(e,f){f((e=r(e,n)).pass,t(!1))})),t(!0))},oneOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];var o=0;return f.some((function(t){if(r(t,n).pass&&o++,e.greaterThan(o,1))return!1})),t(1===o)}})}));
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))}})}));
@@ -0,0 +1,190 @@
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 _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
8
+
9
+ function assertString(input) {
10
+ var isString = typeof input === 'string' || input instanceof String;
11
+
12
+ if (!isString) {
13
+ var invalidType = _typeof(input);
14
+
15
+ if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
16
+ throw new TypeError("Expected a string but received a ".concat(invalidType));
17
+ }
18
+ }
19
+
20
+ function toDate(date) {
21
+ assertString(date);
22
+ date = Date.parse(date);
23
+ return !isNaN(date) ? new Date(date) : null;
24
+ }
25
+
26
+ function isAfter(date, options) {
27
+ // For backwards compatibility:
28
+ // isAfter(str [, date]), i.e. `options` could be used as argument for the legacy `date`
29
+ var comparisonDate = (options === null || options === void 0 ? void 0 : options.comparisonDate) || options || Date().toString();
30
+ var comparison = toDate(comparisonDate);
31
+ var original = toDate(date);
32
+ return !!(original && comparison && original > comparison);
33
+ }
34
+
35
+ function isBefore(str) {
36
+ var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
37
+ assertString(str);
38
+ var comparison = toDate(date);
39
+ var original = toDate(str);
40
+ return !!(original && comparison && original < comparison);
41
+ }
42
+
43
+ function merge() {
44
+ var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
45
+ var defaults = arguments.length > 1 ? arguments[1] : undefined;
46
+
47
+ for (var key in defaults) {
48
+ if (typeof obj[key] === 'undefined') {
49
+ obj[key] = defaults[key];
50
+ }
51
+ }
52
+
53
+ return obj;
54
+ }
55
+
56
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
57
+
58
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
59
+
60
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
61
+
62
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
63
+
64
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
65
+
66
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
67
+
68
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
69
+ var default_date_options = {
70
+ format: 'YYYY/MM/DD',
71
+ delimiters: ['/', '-'],
72
+ strictMode: false
73
+ };
74
+
75
+ function isValidFormat(format) {
76
+ return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
77
+ }
78
+
79
+ function zip(date, format) {
80
+ var zippedArr = [],
81
+ len = Math.min(date.length, format.length);
82
+
83
+ for (var i = 0; i < len; i++) {
84
+ zippedArr.push([date[i], format[i]]);
85
+ }
86
+
87
+ return zippedArr;
88
+ }
89
+
90
+ function isDate(input, options) {
91
+ if (typeof options === 'string') {
92
+ // Allow backward compatbility for old format isDate(input [, format])
93
+ options = merge({
94
+ format: options
95
+ }, default_date_options);
96
+ } else {
97
+ options = merge(options, default_date_options);
98
+ }
99
+
100
+ if (typeof input === 'string' && isValidFormat(options.format)) {
101
+ var formatDelimiter = options.delimiters.find(function (delimiter) {
102
+ return options.format.indexOf(delimiter) !== -1;
103
+ });
104
+ var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
105
+ return input.indexOf(delimiter) !== -1;
106
+ });
107
+ var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
108
+ var dateObj = {};
109
+
110
+ var _iterator = _createForOfIteratorHelper(dateAndFormat),
111
+ _step;
112
+
113
+ try {
114
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
115
+ var _step$value = _slicedToArray(_step.value, 2),
116
+ dateWord = _step$value[0],
117
+ formatWord = _step$value[1];
118
+
119
+ if (dateWord.length !== formatWord.length) {
120
+ return false;
121
+ }
122
+
123
+ dateObj[formatWord.charAt(0)] = dateWord;
124
+ }
125
+ } catch (err) {
126
+ _iterator.e(err);
127
+ } finally {
128
+ _iterator.f();
129
+ }
130
+
131
+ return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d;
132
+ }
133
+
134
+ if (!options.strictMode) {
135
+ return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
136
+ }
137
+
138
+ return false;
139
+ }
140
+
141
+ /* eslint-disable max-len */
142
+ // from http://goo.gl/0ejHHW
143
+
144
+ var iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; // same as above, except with a strict 'T' separator between date and time
145
+
146
+ var iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
147
+ /* eslint-enable max-len */
148
+
149
+ var isValidDate = function isValidDate(str) {
150
+ // str must have passed the ISO8601 check
151
+ // this check is meant to catch invalid dates
152
+ // like 2009-02-31
153
+ // first check for ordinal dates
154
+ var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
155
+
156
+ if (ordinalMatch) {
157
+ var oYear = Number(ordinalMatch[1]);
158
+ var oDay = Number(ordinalMatch[2]); // if is leap year
159
+
160
+ if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
161
+ return oDay <= 365;
162
+ }
163
+
164
+ var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
165
+ var year = match[1];
166
+ var month = match[2];
167
+ var day = match[3];
168
+ var monthString = month ? "0".concat(month).slice(-2) : month;
169
+ var dayString = day ? "0".concat(day).slice(-2) : day; // create a date object and compare
170
+
171
+ var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
172
+
173
+ if (month && day) {
174
+ return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
175
+ }
176
+
177
+ return true;
178
+ };
179
+
180
+ function isISO8601(str) {
181
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
182
+ assertString(str);
183
+ var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
184
+ if (check && options.strict) return isValidDate(str);
185
+ return check;
186
+ }
187
+
188
+ n4s.enforce.extend({ isAfter, isBefore, isDate, isISO8601 });
189
+
190
+ }));
@@ -0,0 +1 @@
1
+ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(require("n4s")):"function"==typeof define&&define.amd?define(["n4s"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).n4s)}(this,(function(t){"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function r(t){if(!("string"==typeof t||t instanceof String)){var r=n(t);throw null===t?r="null":"object"===r&&(r=t.constructor.name),new TypeError("Expected a string but received a ".concat(r))}}function e(t){return r(t),t=Date.parse(t),isNaN(t)?null:new Date(t)}function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;for(var r in n)void 0===t[r]&&(t[r]=n[r]);return t}function i(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],e=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(r.push(a.value),!n||r.length!==n);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==u.return||u.return()}finally{if(o)throw i}}return r}(t,n)||a(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,n){if(t){if("string"==typeof t)return u(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(t,n):void 0}}function u(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}var f={format:"YYYY/MM/DD",delimiters:["/","-"],strictMode:!1};var c=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/,d=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/,l=function(t){var n=t.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);if(n){var r=Number(n[1]),e=Number(n[2]);return r%4==0&&r%100!=0||r%400==0?e<=366:e<=365}var o=t.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number),i=o[1],a=o[2],u=o[3],f=a?"0".concat(a).slice(-2):a,c=u?"0".concat(u).slice(-2):u,d=new Date("".concat(i,"-").concat(f||"01","-").concat(c||"01"));return!a||!u||d.getUTCFullYear()===i&&d.getUTCMonth()+1===a&&d.getUTCDate()===u};t.enforce.extend({isAfter:function(t,n){var r=e((null==n?void 0:n.comparisonDate)||n||Date().toString()),o=e(t);return!!(o&&r&&o>r)},isBefore:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);r(t);var o=e(n),i=e(t);return!!(i&&o&&i<o)},isDate:function(t,n){if(n=o("string"==typeof n?{format:n}:n,f),"string"==typeof t&&(v=n.format,/(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(v))){var r,e=n.delimiters.find((function(t){return-1!==n.format.indexOf(t)})),u=n.strictMode?e:n.delimiters.find((function(n){return-1!==t.indexOf(n)})),c=function(t,n){for(var r=[],e=Math.min(t.length,n.length),o=0;o<e;o++)r.push([t[o],n[o]]);return r}(t.split(u),n.format.toLowerCase().split(e)),d={},l=function(t,n){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=a(t))||n&&t&&"number"==typeof t.length){r&&(t=r);var e=0,o=function(){};return{s:o,n:function(){return e>=t.length?{done:!0}:{done:!1,value:t[e++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,f=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return u=t.done,t},e:function(t){f=!0,i=t},f:function(){try{u||null==r.return||r.return()}finally{if(f)throw i}}}}(c);try{for(l.s();!(r=l.n()).done;){var s=i(r.value,2),y=s[0],m=s[1];if(y.length!==m.length)return!1;d[m.charAt(0)]=y}}catch(t){l.e(t)}finally{l.f()}return new Date("".concat(d.m,"/").concat(d.d,"/").concat(d.y)).getDate()===+d.d}var v;return!n.strictMode&&("[object Date]"===Object.prototype.toString.call(t)&&isFinite(t))},isISO8601:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(t);var e=n.strictSeparator?d.test(t):c.test(t);return e&&n.strict?l(t):e}})}));