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