UNPKG

@amaui/utils

Version:
1,418 lines (1,139 loc) โ€ข 349 kB
/** @license AmauiUtils v1.1.40 * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.AmauiUtils = {})); })(this, (function (exports) { 'use strict'; const optionsDefault$s = {}; const isBrowser$1 = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isNodejs = !!(typeof global !== 'undefined' && typeof module !== 'undefined' && module.exports); // Multiple is methods instead of one, // so it's lighter for tree shaking usability reasons function is(type, value) { var _value$constructor; let options_ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; const options = { ...optionsDefault$s, ...options_ }; const { variant } = options; const prototype = value && typeof value === 'object' && Object.getPrototypeOf(value); switch (type) { case 'string': return typeof value === 'string'; case 'number': return typeof value === 'number' && !Number.isNaN(value); case 'boolean': return typeof value === 'boolean'; case 'array': return Array.isArray(value); case 'object': const isObject = typeof value === 'object' && !!value && value.constructor === Object; return isObject; // Map, null, WeakMap, Date, etc. case 'object-like': return typeof value === 'object' && (value === null || value.constructor !== Object); case 'class': return (typeof value === 'object' || typeof value === 'function') && (/class/gi.test(String(value)) || /class/gi.test(String(value === null || value === void 0 ? void 0 : value.constructor))); case 'function': return !!(value && value instanceof Function); case 'async': // If it's browser avoid calling the method // to see if it's async func or not, // where as in nodejs we have no other choice // that i know of when using transpilation // And also it might not be always correct, as // a method that returns a promise is also async // but we can't know that until the method is called and // we inspect the method's return value return !!(is('function', value) && (isBrowser$1 ? value.constructor.name === 'AsyncFunction' : value() instanceof Promise)); case 'map': return !!(prototype === Map.prototype); case 'weakmap': return !!(prototype === WeakMap.prototype); case 'set': return !!(prototype === Set.prototype); case 'weakset': return !!(prototype === WeakSet.prototype); case 'promise': return !!(prototype === Promise.prototype); case 'int8array': return !!(prototype === Int8Array.prototype); case 'uint8array': return !!(prototype === Uint8Array.prototype); case 'uint8clampedarray': return !!(prototype === Uint8ClampedArray.prototype); case 'int16array': return !!(prototype === Int16Array.prototype); case 'uint16array': return !!(prototype === Uint16Array.prototype); case 'int32array': return !!(prototype === Int32Array.prototype); case 'uint32array': return !!(prototype === Uint32Array.prototype); case 'float32array': return !!(prototype === Float32Array.prototype); case 'float64array': return !!(prototype === Float64Array.prototype); case 'bigint64array': return !!(prototype === BigInt64Array.prototype); case 'biguint64array': return !!(prototype === BigUint64Array.prototype); case 'typedarray': return is('int8array', value) || is('uint8array', value) || is('uint8clampedarray', value) || is('int16array', value) || is('uint16array', value) || is('int32array', value) || is('uint32array', value) || is('float32array', value) || is('float64array', value) || is('bigint64array', value) || is('biguint64array', value); case 'dataview': return !!(prototype === DataView.prototype); case 'arraybuffer': return !!(prototype === ArrayBuffer.prototype); case 'sharedarraybuffer': return typeof SharedArrayBuffer !== 'undefined' && !!(prototype === SharedArrayBuffer.prototype); case 'symbol': return !!(typeof value === 'symbol'); case 'error': return !!(value && value instanceof Error); case 'date': return !!(value && value instanceof Date); case 'regexp': return !!(value && value instanceof RegExp); case 'arguments': return !!(value && value.toString() === '[object Arguments]'); case 'null': return value === null; case 'undefined': return value === undefined; case 'blob': return isBrowser$1 && value instanceof Blob; case 'buffer': return !!(isNodejs && typeof (value === null || value === void 0 ? void 0 : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.isBuffer) === 'function' && value.constructor.isBuffer(value)); case 'element': if (value) { switch (variant) { case undefined: case 'html': case 'element': return isBrowser$1 && (typeof HTMLElement === 'object' ? value instanceof HTMLElement : value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); case 'node': return isBrowser$1 && (typeof Node === 'object' ? value instanceof Node : value && typeof value === 'object' && value !== null && typeof value.nodeType === 'number' && typeof value.nodeName === 'string'); case 'react': return value.elementType || value.hasOwnProperty('$$typeof'); default: return false; } } return false; case 'simple': return is('string', value, options) || is('number', value, options) || is('boolean', value, options) || is('undefined', value, options) || is('null', value, options); case 'not-array-object': return !is('array', value, options) && !is('object', value, options); default: return false; } } function isEnvironment(type, value) { let value_; switch (type) { case 'browser': return typeof window !== 'undefined' && typeof window.document !== 'undefined'; case 'worker': return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; case 'nodejs': return new Function('try {return this===global;}catch(e){return false;}')(); case 'localhost': value_ = value !== undefined ? value : isEnvironment('browser') && window.location.hostname; return is('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1); default: return false; } } function isBrowser(type, value) { var _value_$chrome, _value_$chrome2, _value_$opr, _value_$safari; let value_; switch (type) { case 'chrome': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (!!((_value_$chrome = value_['chrome']) !== null && _value_$chrome !== void 0 && _value_$chrome.webstore || (_value_$chrome2 = value_['chrome']) !== null && _value_$chrome2 !== void 0 && _value_$chrome2.runtime) || value_.navigator.userAgent.indexOf('Chrome') > -1); case 'opera': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (!!((_value_$opr = value_['opr']) !== null && _value_$opr !== void 0 && _value_$opr.addons) || !!value_['opera'] || value_.navigator.userAgent.indexOf(' OPR') > -1); case 'firefox': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (typeof value_['InstallTrigger'] !== 'undefined' || ['Firefox'].some(value__ => value_.navigator.userAgent.indexOf(value__) > -1)); case 'safari': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && function (p) { return p.toString() === '[object SafariRemoteNotification]'; }(!value_['safari'] || ((_value_$safari = value_['safari']) === null || _value_$safari === void 0 ? void 0 : _value_$safari.pushNotification)); case 'edge-chromium': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && isBrowser('chrome', value) && value_.navigator.userAgent.indexOf('Edg') > -1; case 'edge': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && !isBrowser('ie', value) && value_.navigator.userAgent.indexOf('Edg') > -1; case 'ie': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && ( /*@cc_on!@*/ !!value_.document['documentMode']); default: return false; } } function isExists(type) { switch (type) { case 'Intl': return typeof Intl !== 'undefined'; default: return false; } } function isOS(type, value) { let value_; switch (type) { case 'mac': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (/(Mac)/i.test(value_.navigator.platform) || value_.navigator.userAgent.indexOf('Mac OS') > -1); case 'mobile': return isOS('android') || isOS('ios'); case 'android': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (/(Android)/i.test(value_.navigator.platform) || ['Android', 'android'].some(value__ => value_.navigator.userAgent.indexOf(value__) > -1)); case 'ios': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (/(iPhone|iPod|iPad)/i.test(value_.navigator.platform) || ['iPhone', 'iPod', 'iPad'].some(value__ => value_.navigator.userAgent.indexOf(value__) > -1)); case 'windows': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (/(Win)/i.test(value_.navigator.platform) || value_.navigator.userAgent.indexOf('Win') > -1); case 'linux': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && (/(Linux|Unix)/i.test(value_.navigator.platform) || ['Linux', 'Unix'].some(value__ => value_.navigator.userAgent.indexOf(value__) > -1)); default: return false; } } function isResponsive(type, value) { let value_; switch (type) { case 'mobile': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && value_.matchMedia('only screen and (max-width: 767px)').matches; case 'tablet': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && value_.matchMedia('only screen and (min-width: 768px) and (max-width: 1279px)').matches; case 'laptop': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && value_.matchMedia('only screen and (min-width: 1280px) and (max-width: 1919px)').matches; case 'desktop': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && value_.matchMedia('only screen and (min-width: 1920px) and (max-width: 2559px)').matches; case 'tv': value_ = value !== undefined ? value : isEnvironment('browser') && window; return isEnvironment('browser') && value_.matchMedia('only screen and (min-width: 2560px)').matches; default: return false; } } function isState(type) { switch (type) { case 'online': return isEnvironment('browser') && window.navigator.onLine; case 'offline': return isEnvironment('browser') && !window.navigator.onLine; default: return false; } } // Unique ID creation requires a high quality random # generator. In the browser we therefore // require the crypto API and do not support built-in fallback to lower quality random number // generators (like Math.random()). var getRandomValues; var rnds8 = new Uint8Array(16); function rng() { // lazy load so that environments that need to polyfill have a chance to do so if (!getRandomValues) { // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, // find the complete implementation of crypto (msCrypto) on IE11. getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto); if (!getRandomValues) { throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); } } return getRandomValues(rnds8); } var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; function validate(uuid) { return typeof uuid === 'string' && REGEX.test(uuid); } /** * Convert array of 16 byte values to UUID string format of the form: * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */ var byteToHex = []; for (var i = 0; i < 256; ++i) { byteToHex.push((i + 0x100).toString(16).substr(1)); } function stringify$2(arr) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; // Note: Be careful editing this code! It's been tuned for performance // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one // of the following: // - One or more input array values don't map to a hex octet (leading to // "undefined" in the uuid) // - Invalid input values for the RFC `version` or `variant` fields if (!validate(uuid)) { throw TypeError('Stringified UUID is invalid'); } return uuid; } function v4(options, buf, offset) { options = options || {}; var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` rnds[6] = rnds[6] & 0x0f | 0x40; rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided if (buf) { offset = offset || 0; for (var i = 0; i < 16; ++i) { buf[offset + i] = rnds[i]; } return buf; } return stringify$2(rnds); } const isObjectLike = value => typeof value === 'object' && value !== null && !Array.isArray(value); const equalDeep = (valueA, valueB) => { if (valueA === valueB) return true; if (Number.isNaN(valueA) && Number.isNaN(valueB)) return true; if (typeof valueA !== typeof valueB && !(isObjectLike(valueA) && isObjectLike(valueB))) return false; if (Array.isArray(valueA) && valueA.length === valueB.length) return valueA.every((item, index) => equalDeep(item, valueB[index])); if (isObjectLike(valueA)) { const valueA_ = { ...valueA }; const valueB_ = { ...valueB }; return Object.keys(valueA_).every(key => equalDeep(valueA_[key], valueB_[key])); } return false; }; var equalDeep$1 = equalDeep; const optionsDefault$r = {}; function isValid(type, value) { var _value_; let options_ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; const options = { ...optionsDefault$r, ...options_ }; let valueA; let valueB; let operator; let operators; let pattern; let value_; switch (type) { case 'date': return isValid('timestamp', new Date(value).getTime()); case 'unix': return Number.isInteger(value) && String(value).length === 10 && new Date(value * 1000).getTime() > 0; case 'timestamp': return Number.isInteger(value) && String(value).length >= 10 && (new Date(value).getTime() > 0 || new Date(value * 1000).getTime() > 0); case 'uuid': return validate(value); case 'binary-string': value_ = ['0', '1']; return is('string', value) && [...value].every(item => value_.indexOf(item) > -1); case 'hexadecimal-string': value_ = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; return is('string', value) && [...value].every(item => value_.indexOf(item) > -1); case 'url': pattern = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/; return pattern.test(value); case 'url-path': pattern = /^\/([^\/][A-Za-z0-9\-._~!$&'()*+,;=:@\/?#%]*)?$/; return pattern.test(value); case 'domain-name': pattern = /^[a-z0-9\-]+$/; const valueCleanedUp = value.replace(/--/g, '-'); const length = value === null || value === void 0 ? void 0 : value.length; return pattern.test(value) && !value.startsWith('-') && !value.endsWith('-') && valueCleanedUp.length === value.length && length > 1 && length < 254; case 'compare': ({ valueA, valueB, operator } = options); operators = { 'less-than': valueA < valueB, 'less-than-equal': valueA <= valueB, 'equal': equalDeep$1(valueA, valueB), 'not-equal': !equalDeep$1(valueA, valueB), 'greater-than-equal': valueA >= valueB, 'greater-than': valueA > valueB, 'array-all': is('array', valueA) && is('array', valueB) && valueA.every((_, index) => equalDeep$1(valueA[index], valueB[index])), 'array-some': is('array', valueA) && is('array', valueB) && valueA.some((_, index) => equalDeep$1(valueA[index], valueB[index])), 'starts-with': is('string', valueA) && valueA.indexOf(valueB) === 0, 'contains': is('string', valueA) && valueA.indexOf(valueB) > -1 }; return operators[operator]; case 'semver': pattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; return pattern.test(value); case 'semver-compare': ({ valueA, valueB, operator } = options); if (!(isValid('semver', valueA) && isValid('semver', valueB))) return false; valueA = (valueA.match(/\d+(\.|\-|\+){0,1}/g) || []).map(item => item.replace(/[,\-\+\.]/g, '')); valueB = (valueB.match(/\d+(\.|\-|\+){0,1}/g) || []).map(item => item.replace(/[,\-\+\.]/g, '')); operators = { 'less-than': false, 'less-than-equal': false, 'equal': valueA.every((item, index) => item === valueB[index]), 'greater-than-equal': false, 'greater-than': false }; // Less then valueA.forEach((item, index) => { if (!operators['less-than']) operators['less-than'] = item < valueB[index]; }); // Greater then valueA.forEach((item, index) => { if (!operators['greater-than']) operators['greater-than'] = item > valueB[index]; }); // Other or operator values operators['less-than-equal'] = operators['less-than'] || operators['equal']; operators['greater-than-equal'] = operators['greater-than'] || operators['equal']; return operators[operator]; case 'mobile': pattern = /^(\+\d{1,2}\s?)?1?-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/; return pattern.test(value) && !Number.isInteger(value); case 'email': pattern = /\S+@\S+\.\S+/; return pattern.test(value); case 'password': const values = []; if (!is('string', value)) return false; const min_ = options.min !== undefined ? options.min : 7; const max_ = options.max !== undefined ? options.max : 440; // min 7, max 440 characters if (value.length >= min_ && value.length <= max_) values.push('length'); // lowercase characters if (value.match(/[a-z]+/)) values.push('lowercase'); // uppercase characters if (value.match(/[A-Z]+/)) values.push('uppercase'); // numbers if (value.match(/[0-9]+/)) values.push('number'); return options.variant === 'value' ? values : values.length >= 4; case 'hash': pattern = /^(0x)?[a-f0-9]{64}$/gi; return is('string', value) && pattern.test(value); case 'color': return isValid('color-rgb', value, options) || isValid('color-hex', value, options) || isValid('color-hsl', value, options); case 'color-rgb': // Matches rgb() and rgba(), with values divided with ',' and spaces (optionaly) pattern = /rgb(a)?\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(\.\d+)?,\s*(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(\.\d+)?,\s*(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(\.\d+)?(,\s*(?:0(?:\.[0-9]{1,2})?|1(?:\.00?)?))?\)/; return pattern.test(value); case 'color-hex': // Matches #nnn, #nnnnnn and #nnnnnnnn (where last nn's are for alpha (optionaly)) pattern = /^#((?:[0-9a-fA-F]){3}|(?:[0-9a-fA-F]){6}|(?:[0-9a-fA-F]){8})$/; return pattern.test(value); case 'color-hsl': // Matches hsl() and hsla(), with values divided with ',' and spaces (optionaly) pattern = /hsl(a)?\((0|[1-9][0-9]?|[12][0-9][0-9]|3[0-5][0-9])(\.\d+)?,\s*([0-9]|[1-9][0-9]|100)(\.\d+)?%,\s*([0-9]|[1-9][0-9]|100)(\.\d+)?%(,\s*(?:0(?:\.[0-9]{1,2})?|1(?:\.00?)?))?\)/; return pattern.test(value); case 'json': try { value_ = JSON.parse(value); } catch (error) { return false; } return is('object', value_, options) || is('array', value_, options); case 'min': return value >= options.min; case 'max': return value <= options.max; case 'min-max': return isValid('min', value, options) && isValid('max', value, options); case 'same-origin': try { value_ = new URL(value); } catch (error) {} return isEnvironment('browser') && (isValid('url-path', value, options) || window.location.hostname === ((_value_ = value_) === null || _value_ === void 0 ? void 0 : _value_.hostname)); case 'js-chunk': return is('object', value, options) && !!value.__esModule && (value.default instanceof Function || value.default instanceof Object); case 'http-method': const methods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH']; return is('string', value, options) && methods.indexOf(value.toUpperCase()) > -1; case 'base64': value_ = typeof value === 'string' ? value.trim() : value; return is('string', value_, options) && value_.length >= 1 && /^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?$/gi.test(value_); case 'datauri': value_ = typeof value === 'string' ? value.trim() : value; return is('string', value_, options) && /^data:\w+\/[-+.\w]+;base64,(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?$/gi.test(value_) || /^data:(\w+\/[-+.\w]+)?(;charset=[\w-]+)?,(.*)?/gi.test(value_); case 'pascal-case': pattern = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/; return pattern.test(value); case 'camel-case': pattern = /^[a-z]+(?:[A-Z][a-z]+)*$/; return pattern.test(value); default: return false; } } const optionsDefault$q = { decode: false, decodeMethod: decodeURIComponent }; const castParam = function (value) { let options_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; const options = { ...optionsDefault$q, ...options_ }; let newValue = value; try { if (is('string', value) && options.decode && is('function', options.decodeMethod)) newValue = options.decodeMethod(value); } catch (error) {} try { if (is('string', newValue)) { if ('undefined' === newValue) return undefined; if ('NaN' === newValue) return NaN; return JSON.parse(newValue); } return newValue; } catch (error) {} return newValue; }; var castParam$1 = castParam; const resolve = value => { if (value === undefined) return 'undefined'; if (value instanceof Function || value instanceof Object) return value.toString(); return value; }; const clean = value => { if (is('string', value)) return value.replace(/(\s|\r|\n)+/, ' '); return value; }; const serializeValue = (value_, method) => { let value = method(value_); // Ref circular value if (value === undefined) return ''; // Is object-like make into an object try { if (is('object-like', value) && is('not-array-object', value) && value !== null) value = { ...value }; } catch (error) {} if (is('object', value)) return "{".concat(Object.keys(value).sort().map(key => "\"".concat(key, "\":").concat(serializeValue(value[key], method))).filter(item => item.slice(-1) !== ':').join(','), "}"); if (is('array', value)) return "[".concat(value.map(value__ => serializeValue(value__, method)).filter(Boolean).join(','), "]"); if (is('string', value)) return "\"".concat(value, "\""); return clean(JSON.stringify(resolve(value))); }; const serialize$1 = value => { const values = new WeakSet(); const getValue = value_ => { if (typeof value_ === 'object' && value_ !== null) { if (values.has(value_)) return; values.add(value_); } return value_; }; return serializeValue(value, getValue); }; var serialize$2 = serialize$1; const deserialize = value => { if (is('string', value)) { try { return JSON.parse(value); } catch (error) {} } return value; }; var deserialize$1 = deserialize; const debounce = function (method_) { let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 140; let timeoutId; function method() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } clearTimeout(timeoutId); timeoutId = setTimeout(() => method_.apply(this, args), delay); } method.clear = () => clearTimeout(timeoutId); return method; }; var debounce$1 = debounce; const wait = function () { let milliseconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 400; return new Promise(resolve => setTimeout(resolve, milliseconds)); }; var wait$1 = wait; const capitalize = value => { if (is('string', value)) return "".concat(value.charAt(0).toUpperCase()).concat(value.slice(1)); return value; }; var capitalize$1 = capitalize; const isArray = value => Array.isArray(value); const isObject = value => typeof value === 'object' && !!value && value.constructor === Object; // It keeps the references of the methods and classes, // unlike JSON.stringify usually used for deep simple copy const copy = (value, values_) => { const values = !values_ ? new WeakSet() : values_; // Ref circular value if (values.has(value)) return value; if (isObject(value) || isArray(value)) values.add(value); if (isArray(value)) return value.map(item => copy(item, values)); if (isObject(value)) { const newValue = {}; Object.keys(value).forEach(key => newValue[key] = copy(value[key], values)); return newValue; } return value; }; var copy$1 = copy; const optionsDefault$p = { copy: false, merge: { array: false } }; const merge = function (target, source) { let options_ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; const options = { ...optionsDefault$p, ...options_ }; if (options.merge.array && is('array', target) && is('array', source)) { const length = Math.max(target.length, source.length); for (let i = 0; i < length; i++) { if (target[i] === undefined) target[i] = source[i]; if (is('object', target[i]) && is('object', source[i]) || is('array', target[i]) && is('array', source[i])) target[i] = merge(target[i], source[i], options); } } if (is('object', target) && is('object', source)) { Object.keys(source).forEach(key => { // We only care about direct target object properties // not about inherited properties from a prototype chain if (target.hasOwnProperty(key)) { if (is('object', target[key]) && is('object', source[key])) target[key] = merge(target[key], source[key], options); } else target[key] = options.copy ? copy$1(source[key]) : source[key]; }); } return target; }; var merge$1 = merge; const optionsDefault$o = { filters: [',', '.', '-', '_', '\s+'], replaceWith: ' ', trim: true }; const cleanValue = function (value_) { let options_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; try { const options = { ...optionsDefault$o, ...options_ }; // Few predefined options // for className cammel case to regular // css property names convert if (options.className) { options.replaceWith = '-'; options.cammelCaseTransform = true; options.lowercase = true; } if (is('string', value_)) { let value = value_; if (options.url) { const parts = value.split('?').filter(Boolean); let path = parts[0]; const query = parts[1]; if (path.slice(-1) === '/') path = path.slice(0, -1); value = query ? [path, query].join('?') : path; return value; } if (options.cammelCaseTransform) value = value.split(/(?=[A-Z])/g).join(options.replaceWith || ' '); options.filters.forEach(filter => { const expression = "\\".concat(filter); const regexp = new RegExp(expression, 'g'); value = value.replace(regexp, options.replaceWith || ' '); }); if (options.trim) value = value.trim(); if (options.capitalize) value = capitalize$1(value); if (options.lowercase) value = value.toLocaleLowerCase(); return value; } return value_; } catch (error) {} return value_; }; var cleanValue$1 = cleanValue; const flatten = function (object, output_) { let keys_ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; let key_ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; let value_ = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined; let includeObjects = arguments.length > 5 ? arguments[5] : undefined; if (!object) return object; const output = output_ || {}; const value = output_ === undefined ? object : value_; const keys = "".concat(keys_).concat(keys_ ? '.' : '').concat(key_).trim(); if (value !== undefined) { if (includeObjects || is('not-array-object', value)) output[keys] = value; if (!is('not-array-object', value)) { if (is('array', value)) value.forEach((item, index) => flatten(object, output, keys, index, item, includeObjects));else Object.keys(value).forEach(key => flatten(object, output, keys, key, value[key], includeObjects)); } } return output; }; const flattenObject = (object, includeObjects) => { return flatten(object, undefined, undefined, undefined, undefined, includeObjects); }; var flattenObject$1 = flattenObject; const binaryStringToHexadecimal = value_ => { if (isValid('binary-string', value_)) { let value = ''; const parts = value_.match(/.{1,4}/g) || []; for (const [index, part] of parts.entries()) { const decimal = [...part].reduce((result, item) => result = result * 2 + parseInt(item, 10), 0); const hexadecimal = decimal.toString(16); if (index === parts.length - 1) { if (part.length < 4) { if (part.length === 1 && ['0', '1'].indexOf(hexadecimal) > -1 || +hexadecimal > 1 && +hexadecimal <= 7) value = '02' + value + hexadecimal;else value = '1' + String(part.length) + value + part; } else value = '00' + value + hexadecimal; } else value += hexadecimal; } return value; } }; var binaryStringToHexadecimal$1 = binaryStringToHexadecimal; const hexadecimalStringToBinary = value_ => { if (isValid('hexadecimal-string', value_)) { let value = ''; const meta = value_.substring(0, 2); const values = value_.substring(2); const withoutPadding = meta === '02'; const remainAsIs = meta.indexOf('1') === 0 && meta.split('').map(item => +item); const lookup = { 0: '0000', 1: '0001', 2: '0010', 3: '0011', 4: '0100', 5: '0101', 6: '0110', 7: '0111', 8: '1000', 9: '1001', 'a': '1010', 'b': '1011', c: '1100', d: '1101', e: '1110', f: '1111' }; let parts = values.toLowerCase().split(''); if (remainAsIs) parts = parts.slice(0, -remainAsIs[1]); for (const [index, part] of parts.entries()) { value += !(index === parts.length - 1 && withoutPadding) ? lookup[part] : parseInt(lookup[part], 2).toString(2); } if (remainAsIs) value += values.slice(values.length - remainAsIs[1]); return value; } }; var hexadecimalStringToBinary$1 = hexadecimalStringToBinary; const optionsDefault$n = { valueOverride: false }; const setObjectValue = function (object) { let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; let options_ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; const options = { ...optionsDefault$n, ...options_ }; if (!(object || keys)) return object; if (is('string', keys)) { const keys_ = keys.split('.').filter(Boolean).map(key => castParam$1(key)); return setObjectValue(object, keys_, value, options); } if (is('array', keys)) { const key = keys[0]; const keyClean = cleanValue$1(String(key), { filters: ['.', ','], replaceWith: '' }); if (keys.length === 1) { if (is('array', object) && is('number', key) || is('object', object)) { // Add array or object as a value of the key, if that key doesn't exist atm if (!(object !== null && object !== void 0 && object.hasOwnProperty(key)) || options.valueOverride) object[keyClean] = is('number', keys[1]) ? [] : {}; object[is('string', key) ? keyClean : key] = value; } } else { if (is('array', object) && is('number', key) || is('object', object)) { // Add array or object as a value of the key, if that key doesn't exist atm if (!(object !== null && object !== void 0 && object.hasOwnProperty(key)) || options.valueOverride) object[keyClean] = is('number', keys[1]) ? [] : {}; } const value_ = object[keyClean]; // If we are trying to set a deeply nested value on a // simple value type, meaning if it's not an array or an object, // To override existing value use valueOverride: true option if (!(is('object', value_) || is('array', value_))) return object; return setObjectValue(object[key], keys.slice(1), value, options); } } return object; }; var setObjectValue$1 = setObjectValue; const unflattenObject = object => { if (is('object', object)) { const output = {}; Object.keys(object).forEach(key => setObjectValue$1(output, key, object[key])); return output; } return object; }; var unflattenObject$1 = unflattenObject; const getObjectProperties = function (object, path) { let unflatten = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; const values = []; // object or array if (!((is('array', object) || is('object', object)) && is('string', path) && !!path.length)) return values; const separator = '.'; // Flatten the object const flattened = flattenObject$1(object, true); const paths = Object.keys(flattened); let pathsToUse = paths.map(item => ({ path: item, value: undefined, usable: item, used: '' })); const parts = path.split(separator).filter(Boolean); if (!parts.length) return values; parts.forEach((part, index) => { // ** // find all paths to use whose // usable path includes the first next part const partNext = parts[index + 1]; const indexLast = parts.length - 1 === index; if (part === '**') { pathsToUse = pathsToUse.filter(item => { // If no part next // ie. a.** // all are usable if (!partNext) return item; let itemParts = item.usable.split(separator).filter(Boolean); const index_ = itemParts.findIndex(itemPart => itemPart === partNext); const use = index_ > -1; // update // usable path if (use) { itemParts = itemParts.slice(index_); item.usable = itemParts.join(separator); item.used += "".concat(!item.used ? '' : '.').concat(part); return item; } return false; }); } // * // use all the properties // ignore their first usable property // ie. object property or index else if (part === '*') { pathsToUse = pathsToUse.filter(item => { const itemNew = item; const itemParts = itemNew.usable.split(separator).filter(Boolean); // only use // exact path items if (indexLast) return itemParts.length === 1; // remove the first prop // object property or index itemParts.shift(); itemNew.usable = itemParts.join(separator); item.used += "".concat(!item.used ? '' : '.').concat(part); return true; }); } // regular // whose first usable item is // equal to part else { pathsToUse = pathsToUse.filter(item => { if (!item.usable.length) return false; const itemParts = item.usable.split(separator).filter(Boolean); const use = itemParts[0] === part; // update // usable path if (use) { itemParts.shift(); item.usable = itemParts.join(separator); item.used += "".concat(!item.used ? '' : '.').concat(part); } // if last index // only return items // whose usable path // matches exactly if (indexLast) return !item.usable.length; return use; }); } }); const value = {}; pathsToUse.forEach(item => value[item.path] = item.value !== undefined ? item.value : flattened[item.path]); return !unflatten ? value : unflattenObject$1(value); }; var getObjectProperties$1 = getObjectProperties; const getObjectPropertyValue = (object, keys) => { if (!object || !keys) return; if (is('string', keys)) { const keys_ = keys.split('.').filter(Boolean).map(key => castParam$1(key)); return getObjectPropertyValue(object, keys_); } if (is('array', keys)) { const key = keys[0]; if (keys.length === 1) return object[key]; if (object.hasOwnProperty(key)) return getObjectPropertyValue(object[key], keys.slice(1)); } }; var getObjectPropertyValue$1 = getObjectPropertyValue; const getObjectValue = function (object) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } if (!object || !args.length) return; let value; const keys = args.filter(Boolean); for (const key of keys) { value = getObjectPropertyValue$1(object, key); if (value !== undefined) return value; } }; var getObjectValue$1 = getObjectValue; const hasObjectPropertyValue = (object, keys) => { if (!object || !keys) return false; if (is('string', keys)) { const keys_ = keys.split('.').filter(Boolean).map(key => castParam$1(key)); return hasObjectPropertyValue(object, keys_); } if (is('array', keys)) { const key = keys[0]; if (keys.length === 1) return object.hasOwnProperty(key); if (object.hasOwnProperty(key)) return hasObjectPropertyValue(object[key], keys.slice(1)); } return false; }; var hasObjectPropertyValue$1 = hasObjectPropertyValue; const hasObjectProperty = function (object) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } if (!object || !args.length) return false; let value; const keys = args.filter(Boolean); for (const key of keys) { value = hasObjectPropertyValue$1(object, key); if (value === true) return true; } return false; }; var hasObjectProperty$1 = hasObjectProperty; const removeObjectValue = (object, keys) => { if (!(object || keys)) return object; if (is('string', keys)) { const keys_ = keys.split('.').filter(Boolean).map(key => castParam$1(key)); return removeObjectValue(object, keys_); } if (is('array', keys)) { const key = keys[0]; // If object or array doesn't have the above key // then there's no point in moving forward if (object.hasOwnProperty(key)) { if (keys.length === 1) { if (is('array', object) && is('number', key)) object.splice(key, 1); if (is('object', object) && is('string', key)) delete object[key]; } else removeObjectValue(object[key], keys.slice(1)); } } return object; }; var removeObjectValue$1 = removeObjectValue; /** * It returns an array with unique simple values * and / or array and object values. * * Referenced values are only compared based on * values in those reference type values based on array * of keys provided in the second argument in the method. * * Uniqueness of array and object values is separatelly * evaluated based on keys value and returned in the result. */ const unique = function (object) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } const cache = { simple: [], array: [], object: [] }; const output = []; if (is('array', object)) { object.forEach(item => { const isNotArrayObject = is('not-array-object', item); const isArray = is('array', item); const value = isNotArrayObject || !args.length ? item : getObjectValue$1(item, ...args); const cacheArray = cache[isNotArrayObject ? 'simple' : isArray ? 'array' : 'object']; const exists = cacheArray.find(cacheItem => value === cacheItem); if (!exists && value !== undefined) { output.push(item); cache[isNotArrayObject ? 'simple' : isArray ? 'array' : 'object'].push(value); } }); } return output; }; var unique$1 = unique; const optionsDefault$m = { onlySufix: false }; const getOrdinalNumber = function (value_) { let options_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; const options = { ...optionsDefault$m, ...options_ }; const value = castParam$1(value_); if (is('number', value)) { let sufix = 'th'; const string = String(value); if (value === 1 || value > 20 && string[string.length - 1] === '1') sufix = 'st';else if (value === 2 || value > 20 && string[string.length - 1] === '2') sufix = 'nd';else if (value === 3 || value > 20 && string[string.length - 1] === '3') sufix = 'rd'; if (options.onlySufix) return sufix; return "".concat(value).concat(sufix); } }; var getOrdinalNumber$1 = getOrdinalNumber; const optionsDefault$l = { leadingZeros: 1 }; const getLeadingZerosNumber = function (value_) { let options_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; const options = { ...optionsDefault$l, ...options_ }; const value = castParam$1(value_); if (is('number', value) && value >= 0) { let leadingZeros = ''; const string = String(value); const leadingZerosToAdd = options.leadingZeros + 1 - string.length; if (leadingZerosToAdd > 0) for (const _ of new Array(leadingZerosToAdd)) leadingZeros += '0'; return "".concat(leadingZeros).concat(string); } return String(value_); }; var getLeadingZerosNumber$1 = getLeadingZerosNumber; const countries = [{ "flag": "๐Ÿ‡ฆ๐Ÿ‡ซ", "name": "Afghanistan", "full_name": "The Islamic Republic of Afghanistan", "sovereignty": "UN member state", "alpha-2": "AF", "alpha-3": "AFG", "numeric": "004", "subdivision": "ISO 3166-2:AF", "tlds": ["af"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ฝ", "name": "ร…land Islands", "full_name": "ร…land", "sovereignty": "Finland", "alpha-2": "AX", "alpha-3": "ALA", "numeric": "248", "subdivision": "ISO 3166-2:AX", "tlds": ["ax"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ฑ", "name": "Albania", "full_name": "The Republic of Albania", "sovereignty": "UN member state", "alpha-2": "AL", "alpha-3": "ALB", "numeric": "008", "subdivision": "ISO 3166-2:AL", "tlds": ["al"] }, { "flag": "๐Ÿ‡ฉ๐Ÿ‡ฟ", "name": "Algeria", "full_name": "The People's Democratic Republic of Algeria", "sovereignty": "UN member state", "alpha-2": "DZ", "alpha-3": "DZA", "numeric": "012", "subdivision": "ISO 3166-2:DZ", "tlds": ["dz"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ธ", "name": "American Samoa", "full_name": "The Territory of American Samoa", "sovereignty": "United States", "alpha-2": "AS", "alpha-3": "ASM", "numeric": "016", "subdivision": "ISO 3166-2:AS", "tlds": ["as"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ฉ", "name": "Andorra", "full_name": "The Principality of Andorra", "sovereignty": "UN member state", "alpha-2": "AD", "alpha-3": "AND", "numeric": "020", "subdivision": "ISO 3166-2:AD", "tlds": ["ad"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ด", "name": "Angola", "full_name": "The Republic of Angola", "sovereignty": "UN member state", "alpha-2": "AO", "alpha-3": "AGO", "numeric": "024", "subdivision": "ISO 3166-2:AO", "tlds": ["ao"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ฎ", "name": "Anguilla", "full_name": "Anguilla", "sovereignty": "United Kingdom", "alpha-2": "AI", "alpha-3": "AIA", "numeric": "660", "subdivision": "ISO 3166-2:AI", "tlds": ["ai"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ถ", "name": "Antarctica", "full_name": "All land and ice shelves south of the 60th parallel south", "sovereignty": "Antarctic Treaty", "alpha-2": "AQ", "alpha-3": "ATA", "numeric": "010", "subdivision": "ISO 3166-2:AQ", "tlds": ["aq"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ฌ", "name": "Antigua and Barbuda", "full_name": "Antigua and Barbuda", "sovereignty": "UN member state", "alpha-2": "AG", "alpha-3": "ATG", "numeric": "028", "subdivision": "ISO 3166-2:AG", "tlds": ["ag"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ท", "name": "Argentina", "full_name": "The Argentine Republic", "sovereignty": "UN member state", "alpha-2": "AR", "alpha-3": "ARG", "numeric": "032", "subdivision": "ISO 3166-2:AR", "tlds": ["ar"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ฒ", "name": "Armenia", "full_name": "The Republic of Armenia", "sovereignty": "UN member state", "alpha-2": "AM", "alpha-3": "ARM", "numeric": "051", "subdivision": "ISO 3166-2:AM", "tlds": ["am"] }, { "flag": "๐Ÿ‡ฆ๐Ÿ‡ผ", "name": "Aruba", "full_name": "Aruba", "sovereignty": "Netherlands", "alpha-2": "AW", "a