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
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Enforce - n4s
2
2
 
3
+ [![Join Discord](https://badgen.net/discord/online-members/WmADZpJnSe?icon=discord&label=Discord)](https://discord.gg/WmADZpJnSe) [![Version](https://badgen.net/npm/v/vest?&icon=npm)](https://www.npmjs.com/package/n4s) [![Downloads](https://badgen.net/npm/dt/n4s?label=Downloads)](https://www.npmjs.com/package/n4s) [![bundlephobia](https://badgen.net/bundlephobia/minzip/n4s)](https://bundlephobia.com/package/n4s) [![Status](https://badgen.net/github/status/ealush/vest)](https://github.com/ealush/vest/actions)
4
+
3
5
  Enforce is a validations assertions library. It provides rules that you can test your data against.
4
6
 
5
7
  By default, enforce throws an error when your validations fail. These errors should be caught by a validation testing framework such as [Vest](https://github.com/ealush/vest).
@@ -0,0 +1,9 @@
1
+ {
2
+ "main": "../dist/cjs/date.js",
3
+ "module": "../dist/es/date.production.js",
4
+ "unpkg": "../dist/umd/date.production.js",
5
+ "jsdelivr": "../dist/umd/date.production.js",
6
+ "name": "date",
7
+ "types": "../types/date.d.ts",
8
+ "private": true
9
+ }
@@ -4,7 +4,7 @@ var n4s = require('n4s');
4
4
  var vestUtils = require('vest-utils');
5
5
 
6
6
  function ruleReturn(pass, message) {
7
- var output = { pass: pass };
7
+ const output = { pass };
8
8
  if (message) {
9
9
  output.message = message;
10
10
  }
@@ -30,27 +30,23 @@ function runLazyRule(lazyRule, currentValue) {
30
30
  }
31
31
 
32
32
  /* eslint-disable max-lines-per-function */
33
- function compose() {
34
- var composites = [];
35
- for (var _i = 0; _i < arguments.length; _i++) {
36
- composites[_i] = arguments[_i];
37
- }
38
- return vestUtils.assign(function (value) {
39
- var res = run(value);
33
+ function compose(...composites) {
34
+ return vestUtils.assign((value) => {
35
+ const res = run(value);
40
36
  vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
41
37
  }, {
42
- run: run,
43
- test: function (value) { return run(value).pass; }
38
+ run,
39
+ test: (value) => run(value).pass,
44
40
  });
45
41
  function run(value) {
46
- return n4s.ctx.run({ value: value }, function () {
47
- return defaultToPassing(vestUtils.mapFirst(composites, function (composite, breakout) {
42
+ return n4s.ctx.run({ value }, () => {
43
+ return defaultToPassing(vestUtils.mapFirst(composites, (composite, breakout) => {
48
44
  /* HACK: Just a small white lie. ~~HELP WANTED~~.
49
45
  The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
50
46
  The problem is that lazy rules can't really be passed to this function due to some generic hell
51
47
  so we're limiting it to a small set of functions.
52
48
  */
53
- var res = runLazyRule(composite, value);
49
+ const res = runLazyRule(composite, value);
54
50
  breakout(!res.pass, res);
55
51
  }));
56
52
  });
@@ -1,5 +1,4 @@
1
1
  'use strict'
2
-
3
2
  if (process.env.NODE_ENV === 'production') {
4
3
  module.exports = require('./compose.production.js');
5
4
  } else {
@@ -1 +1 @@
1
- "use strict";var n=require("n4s"),t=require("vest-utils");function r(n,t){return n={pass:n},t&&(n.message=t),n}function u(n){return t.defaultTo(n,r(!0))}function e(n,t){try{return n.run(t)}catch(n){return r(!1)}}module.exports=function(){function r(r){return n.ctx.run({value:r},(function(){return u(t.mapFirst(s,(function(n,t){t(!(n=e(n,r)).pass,n)})))}))}for(var s=[],i=0;i<arguments.length;i++)s[i]=arguments[i];return t.assign((function(n){n=r(n),t.invariant(n.pass,t.StringObject(n.message))}),{run:r,test:function(n){return r(n).pass}})};
1
+ "use strict";var t=require("n4s"),n=require("vest-utils");function r(t,n){const r={pass:t};return n&&(r.message=n),r}function s(t){return n.defaultTo(t,r(!0))}function e(t,n){try{return t.run(n)}catch(t){return r(!1)}}module.exports=function(...r){return n.assign((t=>{const r=u(t);n.invariant(r.pass,n.StringObject(r.message))}),{run:u,test:t=>u(t).pass});function u(u){return t.ctx.run({value:u},(()=>s(n.mapFirst(r,((t,n)=>{const r=e(t,u);n(!r.pass,r)})))))}};
@@ -4,7 +4,7 @@ var n4s = require('n4s');
4
4
  var vestUtils = require('vest-utils');
5
5
 
6
6
  function ruleReturn(pass, message) {
7
- var output = { pass: pass };
7
+ const output = { pass };
8
8
  if (message) {
9
9
  output.message = message;
10
10
  }
@@ -32,35 +32,23 @@ function runLazyRule(lazyRule, currentValue) {
32
32
  }
33
33
  }
34
34
 
35
- function allOf(value) {
36
- var rules = [];
37
- for (var _i = 1; _i < arguments.length; _i++) {
38
- rules[_i - 1] = arguments[_i];
39
- }
40
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
41
- var res = runLazyRule(rule, value);
35
+ function allOf(value, ...rules) {
36
+ return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
37
+ const res = runLazyRule(rule, value);
42
38
  breakout(!res.pass, res);
43
39
  }));
44
40
  }
45
41
 
46
- function anyOf(value) {
47
- var rules = [];
48
- for (var _i = 1; _i < arguments.length; _i++) {
49
- rules[_i - 1] = arguments[_i];
50
- }
51
- return defaultToFailing(vestUtils.mapFirst(rules, function (rule, breakout) {
52
- var res = runLazyRule(rule, value);
42
+ function anyOf(value, ...rules) {
43
+ return defaultToFailing(vestUtils.mapFirst(rules, (rule, breakout) => {
44
+ const res = runLazyRule(rule, value);
53
45
  breakout(res.pass, res);
54
46
  }));
55
47
  }
56
48
 
57
- function noneOf(value) {
58
- var rules = [];
59
- for (var _i = 1; _i < arguments.length; _i++) {
60
- rules[_i - 1] = arguments[_i];
61
- }
62
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
63
- var res = runLazyRule(rule, value);
49
+ function noneOf(value, ...rules) {
50
+ return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
51
+ const res = runLazyRule(rule, value);
64
52
  breakout(res.pass, failing());
65
53
  }));
66
54
  }
@@ -70,15 +58,11 @@ function equals(value, arg1) {
70
58
  }
71
59
  vestUtils.bindNot(equals);
72
60
 
73
- var REQUIRED_COUNT = 1;
74
- function oneOf(value) {
75
- var rules = [];
76
- for (var _i = 1; _i < arguments.length; _i++) {
77
- rules[_i - 1] = arguments[_i];
78
- }
79
- var passingCount = 0;
80
- rules.some(function (rule) {
81
- var res = runLazyRule(rule, value);
61
+ const REQUIRED_COUNT = 1;
62
+ function oneOf(value, ...rules) {
63
+ let passingCount = 0;
64
+ rules.some(rule => {
65
+ const res = runLazyRule(rule, value);
82
66
  if (res.pass) {
83
67
  passingCount++;
84
68
  }
@@ -89,4 +73,4 @@ function oneOf(value) {
89
73
  return ruleReturn(equals(passingCount, REQUIRED_COUNT));
90
74
  }
91
75
 
92
- n4s.enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
76
+ n4s.enforce.extend({ allOf, anyOf, noneOf, oneOf });
@@ -1,5 +1,4 @@
1
1
  'use strict'
2
-
3
2
  if (process.env.NODE_ENV === 'production') {
4
3
  module.exports = require('./compounds.production.js');
5
4
  } else {
@@ -1 +1 @@
1
- "use strict";var n=require("n4s"),r=require("vest-utils");function t(n,r){return n={pass:n},r&&(n.message=r),n}function e(){return t(!1)}function u(n){return r.defaultTo(n,e())}function f(n){return r.defaultTo(n,t(!0))}function o(n,r){try{return n.run(r)}catch(n){return e()}}function i(n,r){return n===r}r.bindNot(i);n.enforce.extend({allOf:function(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return f(r.mapFirst(t,(function(r,t){t(!(r=o(r,n)).pass,r)})))},anyOf:function(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return u(r.mapFirst(t,(function(r,t){t((r=o(r,n)).pass,r)})))},noneOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return f(r.mapFirst(t,(function(r,t){t((r=o(r,n)).pass,e())})))},oneOf:function(n){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];var f=0;return e.some((function(t){if(o(t,n).pass&&f++,r.greaterThan(f,1))return!1})),t(i(f,1))}});
1
+ "use strict";var n=require("n4s"),t=require("vest-utils");function r(n,t){const r={pass:n};return t&&(r.message=t),r}function e(){return r(!1)}function u(n){return t.defaultTo(n,r(!0))}function s(n,t){try{return n.run(t)}catch(n){return e()}}function o(n,t){return n===t}t.bindNot(o);n.enforce.extend({allOf:function(n,...r){return u(t.mapFirst(r,((t,r)=>{const e=s(t,n);r(!e.pass,e)})))},anyOf:function(n,...r){return u=t.mapFirst(r,((t,r)=>{const e=s(t,n);r(e.pass,e)})),t.defaultTo(u,e());var u},noneOf:function(n,...r){return u(t.mapFirst(r,((t,r)=>{r(s(t,n).pass,e())})))},oneOf:function(n,...e){let u=0;return e.some((r=>{if(s(r,n).pass&&u++,t.greaterThan(u,1))return!1})),r(o(u,1))}});
@@ -0,0 +1,186 @@
1
+ 'use strict';
2
+
3
+ var n4s = require('n4s');
4
+
5
+ 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); }
6
+
7
+ function assertString(input) {
8
+ var isString = typeof input === 'string' || input instanceof String;
9
+
10
+ if (!isString) {
11
+ var invalidType = _typeof(input);
12
+
13
+ if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
14
+ throw new TypeError("Expected a string but received a ".concat(invalidType));
15
+ }
16
+ }
17
+
18
+ function toDate(date) {
19
+ assertString(date);
20
+ date = Date.parse(date);
21
+ return !isNaN(date) ? new Date(date) : null;
22
+ }
23
+
24
+ function isAfter(date, options) {
25
+ // For backwards compatibility:
26
+ // isAfter(str [, date]), i.e. `options` could be used as argument for the legacy `date`
27
+ var comparisonDate = (options === null || options === void 0 ? void 0 : options.comparisonDate) || options || Date().toString();
28
+ var comparison = toDate(comparisonDate);
29
+ var original = toDate(date);
30
+ return !!(original && comparison && original > comparison);
31
+ }
32
+
33
+ function isBefore(str) {
34
+ var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
35
+ assertString(str);
36
+ var comparison = toDate(date);
37
+ var original = toDate(str);
38
+ return !!(original && comparison && original < comparison);
39
+ }
40
+
41
+ function merge() {
42
+ var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
43
+ var defaults = arguments.length > 1 ? arguments[1] : undefined;
44
+
45
+ for (var key in defaults) {
46
+ if (typeof obj[key] === 'undefined') {
47
+ obj[key] = defaults[key];
48
+ }
49
+ }
50
+
51
+ return obj;
52
+ }
53
+
54
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
55
+
56
+ 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."); }
57
+
58
+ 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; }
59
+
60
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
61
+
62
+ 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; } } }; }
63
+
64
+ 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); }
65
+
66
+ 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; }
67
+ var default_date_options = {
68
+ format: 'YYYY/MM/DD',
69
+ delimiters: ['/', '-'],
70
+ strictMode: false
71
+ };
72
+
73
+ function isValidFormat(format) {
74
+ 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);
75
+ }
76
+
77
+ function zip(date, format) {
78
+ var zippedArr = [],
79
+ len = Math.min(date.length, format.length);
80
+
81
+ for (var i = 0; i < len; i++) {
82
+ zippedArr.push([date[i], format[i]]);
83
+ }
84
+
85
+ return zippedArr;
86
+ }
87
+
88
+ function isDate(input, options) {
89
+ if (typeof options === 'string') {
90
+ // Allow backward compatbility for old format isDate(input [, format])
91
+ options = merge({
92
+ format: options
93
+ }, default_date_options);
94
+ } else {
95
+ options = merge(options, default_date_options);
96
+ }
97
+
98
+ if (typeof input === 'string' && isValidFormat(options.format)) {
99
+ var formatDelimiter = options.delimiters.find(function (delimiter) {
100
+ return options.format.indexOf(delimiter) !== -1;
101
+ });
102
+ var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
103
+ return input.indexOf(delimiter) !== -1;
104
+ });
105
+ var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
106
+ var dateObj = {};
107
+
108
+ var _iterator = _createForOfIteratorHelper(dateAndFormat),
109
+ _step;
110
+
111
+ try {
112
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
113
+ var _step$value = _slicedToArray(_step.value, 2),
114
+ dateWord = _step$value[0],
115
+ formatWord = _step$value[1];
116
+
117
+ if (dateWord.length !== formatWord.length) {
118
+ return false;
119
+ }
120
+
121
+ dateObj[formatWord.charAt(0)] = dateWord;
122
+ }
123
+ } catch (err) {
124
+ _iterator.e(err);
125
+ } finally {
126
+ _iterator.f();
127
+ }
128
+
129
+ return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d;
130
+ }
131
+
132
+ if (!options.strictMode) {
133
+ return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
134
+ }
135
+
136
+ return false;
137
+ }
138
+
139
+ /* eslint-disable max-len */
140
+ // from http://goo.gl/0ejHHW
141
+
142
+ 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
143
+
144
+ 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)?)?)?)?$/;
145
+ /* eslint-enable max-len */
146
+
147
+ var isValidDate = function isValidDate(str) {
148
+ // str must have passed the ISO8601 check
149
+ // this check is meant to catch invalid dates
150
+ // like 2009-02-31
151
+ // first check for ordinal dates
152
+ var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
153
+
154
+ if (ordinalMatch) {
155
+ var oYear = Number(ordinalMatch[1]);
156
+ var oDay = Number(ordinalMatch[2]); // if is leap year
157
+
158
+ if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
159
+ return oDay <= 365;
160
+ }
161
+
162
+ var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
163
+ var year = match[1];
164
+ var month = match[2];
165
+ var day = match[3];
166
+ var monthString = month ? "0".concat(month).slice(-2) : month;
167
+ var dayString = day ? "0".concat(day).slice(-2) : day; // create a date object and compare
168
+
169
+ var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
170
+
171
+ if (month && day) {
172
+ return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
173
+ }
174
+
175
+ return true;
176
+ };
177
+
178
+ function isISO8601(str) {
179
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
180
+ assertString(str);
181
+ var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
182
+ if (check && options.strict) return isValidDate(str);
183
+ return check;
184
+ }
185
+
186
+ n4s.enforce.extend({ isAfter, isBefore, isDate, isISO8601 });
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+ if (process.env.NODE_ENV === 'production') {
3
+ module.exports = require('./date.production.js');
4
+ } else {
5
+ module.exports = require('./date.development.js');
6
+ }
@@ -0,0 +1 @@
1
+ "use strict";var t=require("n4s");function r(t){return r="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},r(t)}function n(t){if(!("string"==typeof t||t instanceof String)){var n=r(t);throw null===t?n="null":"object"===n&&(n=t.constructor.name),new TypeError("Expected a string but received a ".concat(n))}}function e(t){return n(t),t=Date.parse(t),isNaN(t)?null:new Date(t)}function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;for(var n in r)void 0===t[n]&&(t[n]=r[n]);return t}function i(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],e=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(n.push(a.value),!r||n.length!==r);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==u.return||u.return()}finally{if(o)throw i}}return n}(t,r)||a(t,r)||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,r){if(t){if("string"==typeof t)return u(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,r):void 0}}function u(t,r){(null==r||r>t.length)&&(r=t.length);for(var n=0,e=new Array(r);n<r;n++)e[n]=t[n];return e}var c={format:"YYYY/MM/DD",delimiters:["/","-"],strictMode:!1};var f=/^([\+-]?\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 r=t.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);if(r){var n=Number(r[1]),e=Number(r[2]);return n%4==0&&n%100!=0||n%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],c=a?"0".concat(a).slice(-2):a,f=u?"0".concat(u).slice(-2):u,d=new Date("".concat(i,"-").concat(c||"01","-").concat(f||"01"));return!a||!u||d.getUTCFullYear()===i&&d.getUTCMonth()+1===a&&d.getUTCDate()===u};t.enforce.extend({isAfter:function(t,r){var n=e((null==r?void 0:r.comparisonDate)||r||Date().toString()),o=e(t);return!!(o&&n&&o>n)},isBefore:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);n(t);var o=e(r),i=e(t);return!!(i&&o&&i<o)},isDate:function(t,r){if(r=o("string"==typeof r?{format:r}:r,c),"string"==typeof t&&(v=r.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 n,e=r.delimiters.find((function(t){return-1!==r.format.indexOf(t)})),u=r.strictMode?e:r.delimiters.find((function(r){return-1!==t.indexOf(r)})),f=function(t,r){for(var n=[],e=Math.min(t.length,r.length),o=0;o<e;o++)n.push([t[o],r[o]]);return n}(t.split(u),r.format.toLowerCase().split(e)),d={},l=function(t,r){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=a(t))||r&&t&&"number"==typeof t.length){n&&(t=n);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,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return u=t.done,t},e:function(t){c=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(c)throw i}}}}(f);try{for(l.s();!(n=l.n()).done;){var s=i(n.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!r.strictMode&&("[object Date]"===Object.prototype.toString.call(t)&&isFinite(t))},isISO8601:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(t);var e=r.strictSeparator?d.test(t):f.test(t);return e&&r.strict?l(t):e}});