UNPKG

@onesy/log

Version:

Log utils, very readable and clean logs

1,061 lines (1,016 loc) 77.6 kB
/** @license Log v1.0.3 * * 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' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Log = factory()); })(this, (function () { 'use strict'; function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var global$1 = (typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var is$4 = {exports: {}}; (function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); const optionsDefault = {}; const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isNodejs = !!(typeof global$1 !== 'undefined' && 'object' !== 'undefined' && module.exports); // Multiple is methods instead of one, // so it's lighter for tree shaking usability reasons function is(type, value, options_ = {}) { var _a; const options = Object.assign(Object.assign({}, optionsDefault), 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 ? 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 && value instanceof Blob; case 'buffer': return !!(isNodejs && typeof ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === 'function' && value.constructor.isBuffer(value)); case 'element': if (value) { switch (variant) { case undefined: case 'html': case 'element': return isBrowser && (typeof HTMLElement === 'object' ? value instanceof HTMLElement : value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); case 'node': return isBrowser && (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; } } exports.default = is; }(is$4, is$4.exports)); var is$3 = /*@__PURE__*/getDefaultExportFromCjs(is$4.exports); var isEnvironment$1 = {}; var __importDefault$c = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(isEnvironment$1, "__esModule", { value: true }); const is_1$9 = __importDefault$c(is$4.exports); 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 (0, is_1$9.default)('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1); default: return false; } } var _default$6 = isEnvironment$1.default = isEnvironment; var merge$3 = {}; var copy$5 = {}; Object.defineProperty(copy$5, "__esModule", { value: true }); const isArray$2 = value => Array.isArray(value); const isObject$2 = 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$4 = (value, values_) => { const values = !values_ ? new WeakSet() : values_; // Ref circular value if (values.has(value)) return value; if (isObject$2(value) || isArray$2(value)) values.add(value); if (isArray$2(value)) return value.map(item => copy$4(item, values)); if (isObject$2(value)) { const newValue = {}; Object.keys(value).forEach(key => newValue[key] = copy$4(value[key], values)); return newValue; } return value; }; var _default$5 = copy$5.default = copy$4; var __importDefault$b = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(merge$3, "__esModule", { value: true }); const is_1$8 = __importDefault$b(is$4.exports); const copy_1$1 = __importDefault$b(copy$5); const optionsDefault$9 = { copy: false, merge: { array: false, }, }; const merge$2 = (target, source, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$9), options_); if (options.merge.array && (0, is_1$8.default)('array', target) && (0, is_1$8.default)('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 (((0, is_1$8.default)('object', target[i]) && (0, is_1$8.default)('object', source[i])) || (0, is_1$8.default)('array', target[i]) && (0, is_1$8.default)('array', source[i])) target[i] = merge$2(target[i], source[i], options); } } if ((0, is_1$8.default)('object', target) && (0, is_1$8.default)('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 ((0, is_1$8.default)('object', target[key]) && (0, is_1$8.default)('object', source[key])) target[key] = merge$2(target[key], source[key], options); } else target[key] = options.copy ? (0, copy_1$1.default)(source[key]) : source[key]; }); } return target; }; var _default$4 = merge$3.default = merge$2; var stringify$1 = {}; Object.defineProperty(stringify$1, "__esModule", { value: true }); // Fix for undefined // + ref circular values const method = () => { const values = new WeakSet(); return (property, value) => { // Ref circular values const getValue = (property_, value_) => { if (typeof value_ === 'object' && value_ !== null) { if (values.has(value_)) return; values.add(value_); } return value_; }; if (getValue(property, value) === undefined || value === undefined) return undefined; return value; }; }; const stringify = (value_, spaces = 2, replacer = method()) => { try { let value = JSON.stringify(value_, replacer, spaces); // Array circular ref value update // value = value // // first item // .replace(/(?!\[)\n* *null,/g, '') // // index 1+ // .replace(/,\n* *null/g, ''); return value; } catch (error) { } return String(value_); }; var _default$3 = stringify$1.default = stringify; var OnesyDate$1 = {}; var merge$1 = {}; var is$2 = {exports: {}}; (function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); const optionsDefault = {}; const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isNodejs = !!(typeof global$1 !== 'undefined' && 'object' !== 'undefined' && module.exports); // Multiple is methods instead of one, // so it's lighter for tree shaking usability reasons function is(type, value, options_ = {}) { var _a; const options = Object.assign(Object.assign({}, optionsDefault), 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 ? 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 && value instanceof Blob; case 'buffer': return !!(isNodejs && typeof ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === 'function' && value.constructor.isBuffer(value)); case 'element': if (value) { switch (variant) { case undefined: case 'html': case 'element': return isBrowser && (typeof HTMLElement === 'object' ? value instanceof HTMLElement : value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); case 'node': return isBrowser && (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; } } exports.default = is; }(is$2, is$2.exports)); var copy$3 = {}; Object.defineProperty(copy$3, "__esModule", { value: true }); const isArray$1 = value => Array.isArray(value); const isObject$1 = 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$2 = (value, values_) => { const values = !values_ ? new WeakSet() : values_; // Ref circular value if (values.has(value)) return value; if (isObject$1(value) || isArray$1(value)) values.add(value); if (isArray$1(value)) return value.map(item => copy$2(item, values)); if (isObject$1(value)) { const newValue = {}; Object.keys(value).forEach(key => newValue[key] = copy$2(value[key], values)); return newValue; } return value; }; copy$3.default = copy$2; var __importDefault$a = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(merge$1, "__esModule", { value: true }); const is_1$7 = __importDefault$a(is$2.exports); const copy_1 = __importDefault$a(copy$3); const optionsDefault$8 = { copy: false, merge: { array: false, }, }; const merge = (target, source, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$8), options_); if (options.merge.array && (0, is_1$7.default)('array', target) && (0, is_1$7.default)('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 (((0, is_1$7.default)('object', target[i]) && (0, is_1$7.default)('object', source[i])) || (0, is_1$7.default)('array', target[i]) && (0, is_1$7.default)('array', source[i])) target[i] = merge(target[i], source[i], options); } } if ((0, is_1$7.default)('object', target) && (0, is_1$7.default)('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 ((0, is_1$7.default)('object', target[key]) && (0, is_1$7.default)('object', source[key])) target[key] = merge(target[key], source[key], options); } else target[key] = options.copy ? (0, copy_1.default)(source[key]) : source[key]; }); } return target; }; merge$1.default = merge; (function (exports) { var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.daysWeekAbr = exports.daysWeek = exports.monthsAbr = exports.months = exports.units = void 0; const merge_1 = __importDefault(merge$1); const optionsDefault = {}; exports.units = ['millisecond', 'milliseconds', 'second', 'minute', 'minutes', 'hour', 'hours', 'day', 'days', 'dayWeek', 'dayYear', 'week', 'weeks', 'month', 'months', 'year']; exports.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; exports.monthsAbr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; exports.daysWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; exports.daysWeekAbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; class OnesyDate { constructor(value_ = new Date(), options = {}) { this.value_ = value_; this.options = options; this.init(); } static get utc() { return new OnesyDate(new Date(), { utc: true }); } static get daysInMonth() { return new OnesyDate().daysInMonth; } static get valueOf() { return new OnesyDate().valueOf; } static get unix() { return new OnesyDate().unix; } static get milliseconds() { return new OnesyDate().milliseconds; } static get iso() { return new OnesyDate().iso; } static get onesyDate() { return new OnesyDate(); } static get local() { return new OnesyDate().local; } init() { // Merge options with option defaults this.options = (0, merge_1.default)(this.options, optionsDefault); // Make a date object from it this.value = new Date((this.value_.valid ? this.value_.value : this.value_)); if (this.valid) { this.millisecond = this.value[this.options.utc ? 'getUTCMilliseconds' : 'getMilliseconds'](); this.milliseconds = this.value.getTime(); this.second = this.value[this.options.utc ? 'getUTCSeconds' : 'getSeconds'](); this.minute = this.value[this.options.utc ? 'getUTCMinutes' : 'getMinutes'](); this.minutes = Math.ceil(this.milliseconds / (1e3 * 60)); this.hour = this.value[this.options.utc ? 'getUTCHours' : 'getHours'](); this.hours = Math.ceil(this.milliseconds / (1e3 * 60 * 60)); this.day = this.value[this.options.utc ? 'getUTCDate' : 'getDate'](); this.days = Math.ceil(this.milliseconds / (1e3 * 60 * 60 * 24)); this.dayWeek = this.value[this.options.utc ? 'getUTCDay' : 'getDay'](); // https://stackoverflow.com/a/64293860 ty this.weeks = Math.ceil(((this.milliseconds / 1000) + 345600) / 604800); this.month = this.value[this.options.utc ? 'getUTCMonth' : 'getMonth']() + 1; this.year = this.value[this.options.utc ? 'getUTCFullYear' : 'getFullYear'](); this.dayYear = Math.ceil((this.milliseconds - Number(new Date(this.year, 0, 0))) / 1000 / 60 / 60 / 24); this.months = ((this.year - 1970) * 12) - (12 - this.month); this.weekValue(); } } weekValue() { const WEEK_MILLISECONDS = 604800000; const firstDayOfWeek = 1; const startOfYear = new Date(this.year, 0, 1); startOfYear.setDate(startOfYear.getDate() + (firstDayOfWeek - (startOfYear.getDay() % 7))); this.week = Math.round((Number(this.value) - Number(startOfYear)) / WEEK_MILLISECONDS) + 1; return this.week; } get monthsNames() { var _a; return ((_a = this.options.overrides) === null || _a === void 0 ? void 0 : _a.months) || exports.months; } get monthsAbr() { var _a; return ((_a = this.options.overrides) === null || _a === void 0 ? void 0 : _a.monthsAbr) || exports.monthsAbr; } get daysWeek() { var _a; return ((_a = this.options.overrides) === null || _a === void 0 ? void 0 : _a.daysWeek) || exports.daysWeek; } get daysWeekAbr() { var _a; return ((_a = this.options.overrides) === null || _a === void 0 ? void 0 : _a.daysWeekAbr) || exports.daysWeekAbr; } get valid() { var _a; return (this.value_ === undefined || this.value_ instanceof Date || this.value_ instanceof OnesyDate || typeof this.value_ === 'number') && !Number.isNaN(Math.ceil(((_a = this.value) === null || _a === void 0 ? void 0 : _a.getTime()) / 1000)); } get local() { if (this.valid) return new OnesyDate(new Date(this.value.toLocaleString('en-us'))); } get utc() { return new OnesyDate(this.value, { utc: true }); } get iso() { if (this.valid) return this.value.toISOString(); } get daysInMonth() { return new Date(this.year, this.month, 0).getDate(); } get weeksInYear() { const date = new Date(this.year, 0, 1); const isLeapYear = new Date(this.year, 1, 29).getMonth() === 1; return (date.getDay() === 4 || isLeapYear && date.getDay() === 3) ? 53 : 52; } get valueOf() { return this.milliseconds; } get unix() { if (this.valid) return Math.floor(this.value.getTime() / 1000); } timezone(value) { if (this.valid && value) return new OnesyDate(this.value.toLocaleString('en-us', { timeZone: value })); } } exports.default = OnesyDate; }(OnesyDate$1)); var OnesyDate = /*@__PURE__*/getDefaultExportFromCjs(OnesyDate$1); var format$1 = {}; var getStringVariables$1 = {}; var __importDefault$9 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(getStringVariables$1, "__esModule", { value: true }); const is_1$6 = __importDefault$9(is$2.exports); const optionsDefault$7 = { variablesRegExp: /(\{.*?\}|\[.*?\])/g, cleanVariables: true, placeholderPrefix: '_', }; const getStringVariables = (value, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$7), options_); let valueWithPlaceholders = value; if ((0, is_1$6.default)('string', value)) { let variables = value.match(options.variablesRegExp) || []; variables.forEach((variable, index) => valueWithPlaceholders = valueWithPlaceholders.replace(variable, `${options.placeholderPrefix}${index}`)); if (options.cleanVariables) variables = variables.map(variable => variable.slice(1, variable.length - 1)); return { value, variables, valueWithPlaceholders, }; } }; getStringVariables$1.default = getStringVariables; var setStringVariables$1 = {}; var __importDefault$8 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(setStringVariables$1, "__esModule", { value: true }); const is_1$5 = __importDefault$8(is$2.exports); const getStringVariables_1$1 = __importDefault$8(getStringVariables$1); const optionsDefault$6 = { getVariables: true, cleanVariables: true, placeholderPrefix: '_', }; const setStringVariables = (value, variablesToValue = [], options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$6), options_); if ((0, is_1$5.default)('string', value)) { let newValue = value; let stringVariables = { variables: variablesToValue.map(variable => variable.key) }; if (options.getVariables) { stringVariables = (0, getStringVariables_1$1.default)(value, { cleanVariables: options.cleanVariables, placeholderPrefix: options.placeholderPrefix, }); newValue = stringVariables.valueWithPlaceholders; } stringVariables.variables.forEach((variable, index) => { const variableItem = variablesToValue.find(item => item.key === variable); if (variableItem) { const variableValue = variableItem.value; if (variableValue !== undefined) newValue = newValue.replace(new RegExp(`\\${options.placeholderPrefix}${index}`), variableValue); } }); return newValue; } }; setStringVariables$1.default = setStringVariables; var formats$1 = {}; var getLeadingZerosNumber = {}; var castParam$3 = {}; var __importDefault$7 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(castParam$3, "__esModule", { value: true }); const is_1$4 = __importDefault$7(is$2.exports); const optionsDefault$5 = { decode: false, decodeMethod: decodeURIComponent, }; const castParam$2 = (value, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$5), options_); let newValue = value; try { if ((0, is_1$4.default)('string', value) && options.decode && (0, is_1$4.default)('function', options.decodeMethod)) newValue = options.decodeMethod(value); } catch (error) { } try { if ((0, is_1$4.default)('string', newValue)) { if ('undefined' === newValue) return undefined; if ('NaN' === newValue) return NaN; return JSON.parse(newValue); } return newValue; } catch (error) { } return newValue; }; castParam$3.default = castParam$2; (function (exports) { var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLeadingZerosNumber = void 0; const is_1 = __importDefault(is$2.exports); const castParam_1 = __importDefault(castParam$3); const optionsDefault = { leadingZeros: 1, }; const getLeadingZerosNumber = (value_, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault), options_); const value = (0, castParam_1.default)(value_); if ((0, is_1.default)('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 `${leadingZeros}${string}`; } return String(value_); }; exports.getLeadingZerosNumber = getLeadingZerosNumber; exports.default = exports.getLeadingZerosNumber; }(getLeadingZerosNumber)); var getOrdinalNumber = {}; (function (exports) { var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOrdinalNumber = void 0; const is_1 = __importDefault(is$2.exports); const castParam_1 = __importDefault(castParam$3); const optionsDefault = { onlySufix: false, }; const getOrdinalNumber = (value_, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault), options_); const value = (0, castParam_1.default)(value_); if ((0, is_1.default)('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 `${value}${sufix}`; } }; exports.getOrdinalNumber = getOrdinalNumber; exports.default = exports.getOrdinalNumber; }(getOrdinalNumber)); var getTimezoneOffset$1 = {}; var __importDefault$6 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(getTimezoneOffset$1, "__esModule", { value: true }); const getLeadingZerosNumber_1$1 = __importDefault$6(getLeadingZerosNumber); const OnesyDate_1$2 = __importDefault$6(OnesyDate$1); function getTimezoneOffset(value = new OnesyDate_1$2.default(), divider = ':') { if (value && value.valid) { const timezoneOffset = value.value.getTimezoneOffset(); const sign = timezoneOffset < 0 ? '+' : '-'; const difference = Math.abs(timezoneOffset) / 60; const items = String(difference).split('.').filter(Boolean); const hours = (0, getLeadingZerosNumber_1$1.default)(parseInt(items[0], 10)); const minutes = items[1] && (parseInt(items[1], 10) * 10); return `${sign}${hours}${divider}${minutes ? minutes : '00'}`; } } getTimezoneOffset$1.default = getTimezoneOffset; var myTimezoneAbbr$1 = {}; Object.defineProperty(myTimezoneAbbr$1, "__esModule", { value: true }); function myTimezoneAbbr() { let timezoneAbr = new Date().toLocaleTimeString('en-us', { timeZoneName: 'short' }); if (timezoneAbr) timezoneAbr = timezoneAbr.split(' ')[2]; return timezoneAbr; } myTimezoneAbbr$1.default = myTimezoneAbbr; var __importDefault$5 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(formats$1, "__esModule", { value: true }); const getLeadingZerosNumber_1 = __importDefault$5(getLeadingZerosNumber); const getOrdinalNumber_1 = __importDefault$5(getOrdinalNumber); const OnesyDate_1$1 = __importDefault$5(OnesyDate$1); const getTimezoneOffset_1 = __importDefault$5(getTimezoneOffset$1); const myTimezoneAbbr_1 = __importDefault$5(myTimezoneAbbr$1); function formats(onesyDate = OnesyDate_1$1.default.onesyDate) { const timezoneAbbr = (0, myTimezoneAbbr_1.default)(); return [ // Milliseconds { abr: 'SSSS', value: (0, getLeadingZerosNumber_1.default)(onesyDate.millisecond, { leadingZeros: 3 }).slice(0, 4) }, { abr: 'SSS', value: (0, getLeadingZerosNumber_1.default)(onesyDate.millisecond, { leadingZeros: 2 }).slice(0, 3) }, { abr: 'SS', value: (0, getLeadingZerosNumber_1.default)(onesyDate.millisecond, { leadingZeros: 1 }).slice(0, 2) }, { abr: 'S', value: (0, getLeadingZerosNumber_1.default)(onesyDate.millisecond, { leadingZeros: 0 }).slice(0, 1) }, // Seconds { abr: 'ss', value: (0, getLeadingZerosNumber_1.default)(onesyDate.second) }, { abr: 's', value: String(onesyDate.second) }, // Minutes { abr: 'mm', value: (0, getLeadingZerosNumber_1.default)(onesyDate.minute) }, { abr: 'm', value: String(onesyDate.minute) }, // Hours { abr: 'HH', value: (0, getLeadingZerosNumber_1.default)(onesyDate.hour) }, { abr: 'H', value: String(onesyDate.hour) }, { abr: 'hh', value: (0, getLeadingZerosNumber_1.default)(onesyDate.hour > 12 ? onesyDate.hour - 12 : onesyDate.hour) }, { abr: 'h', value: String(onesyDate.hour > 12 ? onesyDate.hour - 12 : onesyDate.hour) }, // Day { abr: 'Do', value: (0, getOrdinalNumber_1.default)(onesyDate.day) }, { abr: 'DD', value: (0, getLeadingZerosNumber_1.default)(onesyDate.day) }, { abr: 'D', value: String(onesyDate.day) }, { abr: 'dd', value: onesyDate.daysWeek[onesyDate.dayWeek - 1 < 0 ? onesyDate.daysWeek.length - 1 : onesyDate.dayWeek - 1] }, { abr: 'd', value: onesyDate.daysWeekAbr[onesyDate.dayWeek - 1 < 0 ? onesyDate.daysWeekAbr.length - 1 : onesyDate.dayWeek - 1] }, // Month { abr: 'Mo', value: (0, getOrdinalNumber_1.default)(onesyDate.month) }, { abr: 'MMMM', value: onesyDate.monthsNames[onesyDate.month - 1 < 0 ? onesyDate.monthsNames.length - 1 : onesyDate.month - 1] }, { abr: 'MMM', value: onesyDate.monthsAbr[onesyDate.month - 1 < 0 ? onesyDate.monthsAbr.length - 1 : onesyDate.month - 1] }, { abr: 'MM', value: (0, getLeadingZerosNumber_1.default)(onesyDate.month) }, { abr: 'M', value: String(onesyDate.month) }, // Year { abr: 'YYYY', value: String(onesyDate.year) }, // AM / PM { abr: 'A', value: onesyDate.hour < 12 ? 'AM' : 'PM' }, { abr: 'a', value: onesyDate.hour < 12 ? 'am' : 'pm' }, // Timezone offset { abr: 'ZZ', value: (0, getTimezoneOffset_1.default)(onesyDate, '') }, { abr: 'Z', value: (0, getTimezoneOffset_1.default)(onesyDate) }, // Timezone abr { abr: 'z', value: timezoneAbbr }, // Unix { abr: 'X', value: String(onesyDate.unix) }, { abr: 'x', value: String(onesyDate.value.getTime()) }, ]; } formats$1.default = formats; var __importDefault$4 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(format$1, "__esModule", { value: true }); const getStringVariables_1 = __importDefault$4(getStringVariables$1); const setStringVariables_1 = __importDefault$4(setStringVariables$1); const OnesyDate_1 = __importDefault$4(OnesyDate$1); const formats_1 = __importDefault$4(formats$1); function format(onesyDate = OnesyDate_1.default.onesyDate, value_ = `YYYY-MM-DDTHH:mm:ss`, options) { const l = (options === null || options === void 0 ? void 0 : options.l) || (value => value); if (onesyDate && onesyDate.valid) { let value = value_; const formatValues = (0, formats_1.default)(onesyDate); const abrs = formatValues.map(item => item.abr); // Extract and save all words quoted with: '', "", ``, {} or [], // in a string, so adding abr values doesn't override 'em const words = (0, getStringVariables_1.default)(value, { variablesRegExp: /('.*?'|".*?"|`.*?`|\{.*?\}|\[.*?\])/g, }); // Add placeholders before adding all abr values value = words.valueWithPlaceholders; // Replace all abr values // tslint:disable-next-line const reAbr = abrs.reduce((result, current, index) => result += `${current}${index !== abrs.length - 1 ? '|' : ''}`, ''); const abrVariables = (0, getStringVariables_1.default)(value, { variablesRegExp: new RegExp(reAbr, 'g'), cleanVariables: false, placeholderPrefix: '__', }); // Add placeholders for matches prior to adding all abr values value = abrVariables.valueWithPlaceholders; const abrVariablesToValue = []; abrVariables.variables.forEach(variable => { const format_ = formatValues.find(item => item.abr === variable); abrVariablesToValue.push({ key: variable, value: l(format_.value) }); }); // Replace abr variables with appropriate values value = (0, setStringVariables_1.default)(value, abrVariablesToValue, { getVariables: false, placeholderPrefix: '__', }); // Revert back all the saved words const wordsVariablesToValue = []; words.variables.forEach(variable => wordsVariablesToValue.push({ key: variable, value: variable })); value = (0, setStringVariables_1.default)(value, wordsVariablesToValue, { getVariables: false }); return value; } } var _default$2 = format$1.default = format; var is$1 = {exports: {}}; (function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); const optionsDefault = {}; const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isNodejs = !!(typeof global$1 !== 'undefined' && 'object' !== 'undefined' && module.exports); // Multiple is methods instead of one, // so it's lighter for tree shaking usability reasons function is(type, value, options_ = {}) { var _a; const options = Object.assign(Object.assign({}, optionsDefault), 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 ? 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 && value instanceof Blob; case 'buffer': return !!(isNodejs && typeof ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === 'function' && value.constructor.isBuffer(value)); case 'element': if (value) { switch (variant) { case undefined: case 'html': case 'element': return isBrowser && (typeof HTMLElement === 'object' ? value instanceof HTMLElement : value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); case 'node': return isBrowser && (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');