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.
Files changed (80) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/README.md +2 -0
  3. package/compose/package.json +2 -0
  4. package/compounds/package.json +2 -0
  5. package/date/package.json +9 -0
  6. package/dist/cjs/compose.development.js +14 -97
  7. package/dist/cjs/compose.js +0 -1
  8. package/dist/cjs/compose.production.js +1 -1
  9. package/dist/cjs/compounds.development.js +30 -86
  10. package/dist/cjs/compounds.js +0 -1
  11. package/dist/cjs/compounds.production.js +1 -1
  12. package/dist/cjs/date.development.js +186 -0
  13. package/dist/cjs/date.js +6 -0
  14. package/dist/cjs/date.production.js +1 -0
  15. package/dist/cjs/email.development.js +363 -0
  16. package/dist/cjs/email.js +6 -0
  17. package/dist/cjs/email.production.js +1 -0
  18. package/dist/cjs/isURL.development.js +353 -0
  19. package/dist/cjs/isURL.js +6 -0
  20. package/dist/cjs/isURL.production.js +1 -0
  21. package/dist/cjs/n4s.development.js +205 -387
  22. package/dist/cjs/n4s.js +0 -1
  23. package/dist/cjs/n4s.production.js +1 -1
  24. package/dist/cjs/schema.development.js +19 -80
  25. package/dist/cjs/schema.js +0 -1
  26. package/dist/cjs/schema.production.js +1 -1
  27. package/dist/es/compose.development.js +14 -97
  28. package/dist/es/compose.production.js +1 -1
  29. package/dist/es/compounds.development.js +28 -84
  30. package/dist/es/compounds.production.js +1 -1
  31. package/dist/es/date.development.js +184 -0
  32. package/dist/es/date.production.js +1 -0
  33. package/dist/es/email.development.js +361 -0
  34. package/dist/es/email.production.js +1 -0
  35. package/dist/es/isURL.development.js +351 -0
  36. package/dist/es/isURL.production.js +1 -0
  37. package/dist/es/n4s.development.js +192 -372
  38. package/dist/es/n4s.production.js +1 -1
  39. package/dist/es/schema.development.js +16 -75
  40. package/dist/es/schema.production.js +1 -1
  41. package/dist/umd/compose.development.js +18 -102
  42. package/dist/umd/compose.production.js +1 -1
  43. package/dist/umd/compounds.development.js +34 -91
  44. package/dist/umd/compounds.production.js +1 -1
  45. package/dist/umd/date.development.js +190 -0
  46. package/dist/umd/date.production.js +1 -0
  47. package/dist/umd/email.development.js +367 -0
  48. package/dist/umd/email.production.js +1 -0
  49. package/dist/umd/isURL.development.js +357 -0
  50. package/dist/umd/isURL.production.js +1 -0
  51. package/dist/umd/n4s.development.js +209 -392
  52. package/dist/umd/n4s.production.js +1 -1
  53. package/dist/umd/schema.development.js +23 -85
  54. package/dist/umd/schema.production.js +1 -1
  55. package/email/package.json +9 -0
  56. package/isURL/package.json +9 -0
  57. package/package.json +162 -55
  58. package/schema/package.json +2 -0
  59. package/testUtils/TEnforceMock.ts +3 -0
  60. package/types/compose.d.ts +46 -55
  61. package/types/compose.d.ts.map +1 -0
  62. package/types/compounds.d.ts +50 -62
  63. package/types/compounds.d.ts.map +1 -0
  64. package/types/date.d.ts +18 -0
  65. package/types/date.d.ts.map +1 -0
  66. package/types/email.d.ts +12 -0
  67. package/types/email.d.ts.map +1 -0
  68. package/types/isURL.d.ts +12 -0
  69. package/types/isURL.d.ts.map +1 -0
  70. package/types/n4s.d.ts +62 -73
  71. package/types/n4s.d.ts.map +1 -0
  72. package/types/schema.d.ts +55 -63
  73. package/types/schema.d.ts.map +1 -0
  74. package/docs/.nojekyll +0 -0
  75. package/docs/README.md +0 -44
  76. package/docs/_sidebar.md +0 -5
  77. package/docs/external.md +0 -27
  78. package/docs/index.html +0 -32
  79. package/docs/rules.md +0 -1282
  80. package/tsconfig.json +0 -8
@@ -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}})}));
@@ -0,0 +1,367 @@
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$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
8
+
9
+ function assertString(input) {
10
+ var isString = typeof input === 'string' || input instanceof String;
11
+
12
+ if (!isString) {
13
+ var invalidType = _typeof$1(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 merge() {
21
+ var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
22
+ var defaults = arguments.length > 1 ? arguments[1] : undefined;
23
+
24
+ for (var key in defaults) {
25
+ if (typeof obj[key] === 'undefined') {
26
+ obj[key] = defaults[key];
27
+ }
28
+ }
29
+
30
+ return obj;
31
+ }
32
+
33
+ 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); }
34
+ /* eslint-disable prefer-rest-params */
35
+
36
+ function isByteLength(str, options) {
37
+ assertString(str);
38
+ var min;
39
+ var max;
40
+
41
+ if (_typeof(options) === 'object') {
42
+ min = options.min || 0;
43
+ max = options.max;
44
+ } else {
45
+ // backwards compatibility: isByteLength(str, min [, max])
46
+ min = arguments[1];
47
+ max = arguments[2];
48
+ }
49
+
50
+ var len = encodeURI(str).split(/%..|./).length - 1;
51
+ return len >= min && (typeof max === 'undefined' || len <= max);
52
+ }
53
+
54
+ var default_fqdn_options = {
55
+ require_tld: true,
56
+ allow_underscores: false,
57
+ allow_trailing_dot: false,
58
+ allow_numeric_tld: false,
59
+ allow_wildcard: false,
60
+ ignore_max_length: false
61
+ };
62
+ function isFQDN(str, options) {
63
+ assertString(str);
64
+ options = merge(options, default_fqdn_options);
65
+ /* Remove the optional trailing dot before checking validity */
66
+
67
+ if (options.allow_trailing_dot && str[str.length - 1] === '.') {
68
+ str = str.substring(0, str.length - 1);
69
+ }
70
+ /* Remove the optional wildcard before checking validity */
71
+
72
+
73
+ if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
74
+ str = str.substring(2);
75
+ }
76
+
77
+ var parts = str.split('.');
78
+ var tld = parts[parts.length - 1];
79
+
80
+ if (options.require_tld) {
81
+ // disallow fqdns without tld
82
+ if (parts.length < 2) {
83
+ return false;
84
+ }
85
+
86
+ if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
87
+ return false;
88
+ } // disallow spaces
89
+
90
+
91
+ if (/\s/.test(tld)) {
92
+ return false;
93
+ }
94
+ } // reject numeric TLDs
95
+
96
+
97
+ if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
98
+ return false;
99
+ }
100
+
101
+ return parts.every(function (part) {
102
+ if (part.length > 63 && !options.ignore_max_length) {
103
+ return false;
104
+ }
105
+
106
+ if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
107
+ return false;
108
+ } // disallow full-width chars
109
+
110
+
111
+ if (/[\uff01-\uff5e]/.test(part)) {
112
+ return false;
113
+ } // disallow parts starting or ending with hyphen
114
+
115
+
116
+ if (/^-|-$/.test(part)) {
117
+ return false;
118
+ }
119
+
120
+ if (!options.allow_underscores && /_/.test(part)) {
121
+ return false;
122
+ }
123
+
124
+ return true;
125
+ });
126
+ }
127
+
128
+ /**
129
+ 11.3. Examples
130
+
131
+ The following addresses
132
+
133
+ fe80::1234 (on the 1st link of the node)
134
+ ff02::5678 (on the 5th link of the node)
135
+ ff08::9abc (on the 10th organization of the node)
136
+
137
+ would be represented as follows:
138
+
139
+ fe80::1234%1
140
+ ff02::5678%5
141
+ ff08::9abc%10
142
+
143
+ (Here we assume a natural translation from a zone index to the
144
+ <zone_id> part, where the Nth zone of any scope is translated into
145
+ "N".)
146
+
147
+ If we use interface names as <zone_id>, those addresses could also be
148
+ represented as follows:
149
+
150
+ fe80::1234%ne0
151
+ ff02::5678%pvc1.3
152
+ ff08::9abc%interface10
153
+
154
+ where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
155
+ to the 5th link, and "interface10" belongs to the 10th organization.
156
+ * * */
157
+
158
+ var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
159
+ var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
160
+ var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
161
+ var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
162
+ var IPv6AddressRegExp = new RegExp('^(' + "(?:".concat(IPv6SegmentFormat, ":){7}(?:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){6}(?:").concat(IPv4AddressFormat, "|:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){5}(?::").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,2}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){4}(?:(:").concat(IPv6SegmentFormat, "){0,1}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,3}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){3}(?:(:").concat(IPv6SegmentFormat, "){0,2}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,4}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){2}(?:(:").concat(IPv6SegmentFormat, "){0,3}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,5}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){1}(?:(:").concat(IPv6SegmentFormat, "){0,4}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,6}|:)|") + "(?::((?::".concat(IPv6SegmentFormat, "){0,5}:").concat(IPv4AddressFormat, "|(?::").concat(IPv6SegmentFormat, "){1,7}|:))") + ')(%[0-9a-zA-Z-.:]{1,})?$');
163
+ function isIP(str) {
164
+ var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
165
+ assertString(str);
166
+ version = String(version);
167
+
168
+ if (!version) {
169
+ return isIP(str, 4) || isIP(str, 6);
170
+ }
171
+
172
+ if (version === '4') {
173
+ return IPv4AddressRegExp.test(str);
174
+ }
175
+
176
+ if (version === '6') {
177
+ return IPv6AddressRegExp.test(str);
178
+ }
179
+
180
+ return false;
181
+ }
182
+
183
+ var default_email_options = {
184
+ allow_display_name: false,
185
+ require_display_name: false,
186
+ allow_utf8_local_part: true,
187
+ require_tld: true,
188
+ blacklisted_chars: '',
189
+ ignore_max_length: false,
190
+ host_blacklist: [],
191
+ host_whitelist: []
192
+ };
193
+ /* eslint-disable max-len */
194
+
195
+ /* eslint-disable no-control-regex */
196
+
197
+ var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
198
+ var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
199
+ var gmailUserPart = /^[a-z\d]+$/;
200
+ var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
201
+ var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
202
+ var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
203
+ var defaultMaxEmailLength = 254;
204
+ /* eslint-enable max-len */
205
+
206
+ /* eslint-enable no-control-regex */
207
+
208
+ /**
209
+ * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
210
+ * @param {String} display_name
211
+ */
212
+
213
+ function validateDisplayName(display_name) {
214
+ var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1'); // display name with only spaces is not valid
215
+
216
+ if (!display_name_without_quotes.trim()) {
217
+ return false;
218
+ } // check whether display name contains illegal character
219
+
220
+
221
+ var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
222
+
223
+ if (contains_illegal) {
224
+ // if contains illegal characters,
225
+ // must to be enclosed in double-quotes, otherwise it's not a valid display name
226
+ if (display_name_without_quotes === display_name) {
227
+ return false;
228
+ } // the quotes in display name must start with character symbol \
229
+
230
+
231
+ var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
232
+
233
+ if (!all_start_with_back_slash) {
234
+ return false;
235
+ }
236
+ }
237
+
238
+ return true;
239
+ }
240
+
241
+ function isEmail(str, options) {
242
+ assertString(str);
243
+ options = merge(options, default_email_options);
244
+
245
+ if (options.require_display_name || options.allow_display_name) {
246
+ var display_email = str.match(splitNameAddress);
247
+
248
+ if (display_email) {
249
+ var display_name = display_email[1]; // Remove display name and angle brackets to get email address
250
+ // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
251
+
252
+ str = str.replace(display_name, '').replace(/(^<|>$)/g, ''); // sometimes need to trim the last space to get the display name
253
+ // because there may be a space between display name and email address
254
+ // eg. myname <address@gmail.com>
255
+ // the display name is `myname` instead of `myname `, so need to trim the last space
256
+
257
+ if (display_name.endsWith(' ')) {
258
+ display_name = display_name.slice(0, -1);
259
+ }
260
+
261
+ if (!validateDisplayName(display_name)) {
262
+ return false;
263
+ }
264
+ } else if (options.require_display_name) {
265
+ return false;
266
+ }
267
+ }
268
+
269
+ if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
270
+ return false;
271
+ }
272
+
273
+ var parts = str.split('@');
274
+ var domain = parts.pop();
275
+ var lower_domain = domain.toLowerCase();
276
+
277
+ if (options.host_blacklist.includes(lower_domain)) {
278
+ return false;
279
+ }
280
+
281
+ if (options.host_whitelist.length > 0 && !options.host_whitelist.includes(lower_domain)) {
282
+ return false;
283
+ }
284
+
285
+ var user = parts.join('@');
286
+
287
+ if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
288
+ /*
289
+ Previously we removed dots for gmail addresses before validating.
290
+ This was removed because it allows `multiple..dots@gmail.com`
291
+ to be reported as valid, but it is not.
292
+ Gmail only normalizes single dots, removing them from here is pointless,
293
+ should be done in normalizeEmail
294
+ */
295
+ user = user.toLowerCase(); // Removing sub-address from username before gmail validation
296
+
297
+ var username = user.split('+')[0]; // Dots are not included in gmail length restriction
298
+
299
+ if (!isByteLength(username.replace(/\./g, ''), {
300
+ min: 6,
301
+ max: 30
302
+ })) {
303
+ return false;
304
+ }
305
+
306
+ var _user_parts = username.split('.');
307
+
308
+ for (var i = 0; i < _user_parts.length; i++) {
309
+ if (!gmailUserPart.test(_user_parts[i])) {
310
+ return false;
311
+ }
312
+ }
313
+ }
314
+
315
+ if (options.ignore_max_length === false && (!isByteLength(user, {
316
+ max: 64
317
+ }) || !isByteLength(domain, {
318
+ max: 254
319
+ }))) {
320
+ return false;
321
+ }
322
+
323
+ if (!isFQDN(domain, {
324
+ require_tld: options.require_tld,
325
+ ignore_max_length: options.ignore_max_length
326
+ })) {
327
+ if (!options.allow_ip_domain) {
328
+ return false;
329
+ }
330
+
331
+ if (!isIP(domain)) {
332
+ if (!domain.startsWith('[') || !domain.endsWith(']')) {
333
+ return false;
334
+ }
335
+
336
+ var noBracketdomain = domain.slice(1, -1);
337
+
338
+ if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
339
+ return false;
340
+ }
341
+ }
342
+ }
343
+
344
+ if (user[0] === '"') {
345
+ user = user.slice(1, user.length - 1);
346
+ return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
347
+ }
348
+
349
+ var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
350
+ var user_parts = user.split('.');
351
+
352
+ for (var _i = 0; _i < user_parts.length; _i++) {
353
+ if (!pattern.test(user_parts[_i])) {
354
+ return false;
355
+ }
356
+ }
357
+
358
+ if (options.blacklisted_chars) {
359
+ if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
360
+ }
361
+
362
+ return true;
363
+ }
364
+
365
+ n4s.enforce.extend({ isEmail });
366
+
367
+ }));
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("n4s")):"function"==typeof define&&define.amd?define(["n4s"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).n4s)}(this,(function(t){"use strict";function e(t){return e="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},e(t)}function n(t){if(!("string"==typeof t||t instanceof String)){var n=e(t);throw null===t?n="null":"object"===n&&(n=t.constructor.name),new TypeError("Expected a string but received a ".concat(n))}}function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;for(var n in e)void 0===t[n]&&(t[n]=e[n]);return t}function o(t){return o="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},o(t)}function i(t,e){var r,i;n(t),"object"===o(e)?(r=e.min||0,i=e.max):(r=arguments[1],i=arguments[2]);var a=encodeURI(t).split(/%..|./).length-1;return a>=r&&(void 0===i||a<=i)}var a={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_numeric_tld:!1,allow_wildcard:!1,ignore_max_length:!1};var c="(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])",l="(".concat(c,"[.]){3}").concat(c),u=new RegExp("^".concat(l,"$")),f="(?:[0-9a-fA-F]{1,4})",s=new RegExp("^("+"(?:".concat(f,":){7}(?:").concat(f,"|:)|")+"(?:".concat(f,":){6}(?:").concat(l,"|:").concat(f,"|:)|")+"(?:".concat(f,":){5}(?::").concat(l,"|(:").concat(f,"){1,2}|:)|")+"(?:".concat(f,":){4}(?:(:").concat(f,"){0,1}:").concat(l,"|(:").concat(f,"){1,3}|:)|")+"(?:".concat(f,":){3}(?:(:").concat(f,"){0,2}:").concat(l,"|(:").concat(f,"){1,4}|:)|")+"(?:".concat(f,":){2}(?:(:").concat(f,"){0,3}:").concat(l,"|(:").concat(f,"){1,5}|:)|")+"(?:".concat(f,":){1}(?:(:").concat(f,"){0,4}:").concat(l,"|(:").concat(f,"){1,6}|:)|")+"(?::((?::".concat(f,"){0,5}:").concat(l,"|(?::").concat(f,"){1,7}|:))")+")(%[0-9a-zA-Z-.:]{1,})?$");function _(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return n(t),(e=String(e))?"4"===e?u.test(t):"6"===e&&s.test(t):_(t,4)||_(t,6)}var x={allow_display_name:!1,require_display_name:!1,allow_utf8_local_part:!0,require_tld:!0,blacklisted_chars:"",ignore_max_length:!1,host_blacklist:[],host_whitelist:[]},d=/^([^\x00-\x1F\x7F-\x9F\cX]+)</i,g=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,p=/^[a-z\d]+$/,m=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,h=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,F=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;t.enforce.extend({isEmail:function(t,e){if(n(t),(e=r(e,x)).require_display_name||e.allow_display_name){var o=t.match(d);if(o){var c=o[1];if(t=t.replace(c,"").replace(/(^<|>$)/g,""),c.endsWith(" ")&&(c=c.slice(0,-1)),!function(t){var e=t.replace(/^"(.+)"$/,"$1");if(!e.trim())return!1;if(/[\.";<>]/.test(e)){if(e===t)return!1;if(e.split('"').length!==e.split('\\"').length)return!1}return!0}(c))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&t.length>254)return!1;var l=t.split("@"),u=l.pop(),f=u.toLowerCase();if(e.host_blacklist.includes(f))return!1;if(e.host_whitelist.length>0&&!e.host_whitelist.includes(f))return!1;var s=l.join("@");if(e.domain_specific_validation&&("gmail.com"===f||"googlemail.com"===f)){var y=(s=s.toLowerCase()).split("+")[0];if(!i(y.replace(/\./g,""),{min:6,max:30}))return!1;for(var b=y.split("."),v=0;v<b.length;v++)if(!p.test(b[v]))return!1}if(!(!1!==e.ignore_max_length||i(s,{max:64})&&i(u,{max:254})))return!1;if(!function(t,e){n(t),(e=r(e,a)).allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),!0===e.allow_wildcard&&0===t.indexOf("*.")&&(t=t.substring(2));var o=t.split("."),i=o[o.length-1];if(e.require_tld){if(o.length<2)return!1;if(!e.allow_numeric_tld&&!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1;if(/\s/.test(i))return!1}return!(!e.allow_numeric_tld&&/^\d+$/.test(i))&&o.every((function(t){return!(t.length>63&&!e.ignore_max_length||!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(t)||/[\uff01-\uff5e]/.test(t)||/^-|-$/.test(t)||!e.allow_underscores&&/_/.test(t))}))}(u,{require_tld:e.require_tld,ignore_max_length:e.ignore_max_length})){if(!e.allow_ip_domain)return!1;if(!_(u)){if(!u.startsWith("[")||!u.endsWith("]"))return!1;var w=u.slice(1,-1);if(0===w.length||!_(w))return!1}}if('"'===s[0])return s=s.slice(1,s.length-1),e.allow_utf8_local_part?F.test(s):m.test(s);for(var $=e.allow_utf8_local_part?h:g,D=s.split("."),S=0;S<D.length;S++)if(!$.test(D[S]))return!1;return!e.blacklisted_chars||-1===s.search(new RegExp("[".concat(e.blacklisted_chars,"]+"),"g"))}})}));