Travis build: 857 [ci skip]
This commit is contained in:
443
dist/_30s.es5.js
vendored
443
dist/_30s.es5.js
vendored
@ -4,6 +4,33 @@
|
|||||||
(global._30s = factory());
|
(global._30s = factory());
|
||||||
}(this, (function () { 'use strict';
|
}(this, (function () { 'use strict';
|
||||||
|
|
||||||
|
var JSONToDate = function JSONToDate(arr) {
|
||||||
|
var dt = new Date(parseInt(arr.toString().substr(6)));
|
||||||
|
return dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear();
|
||||||
|
};
|
||||||
|
|
||||||
|
var fs = typeof require !== "undefined" && require('fs');
|
||||||
|
var JSONToFile = function JSONToFile(obj, filename) {
|
||||||
|
return fs.writeFile(filename + ".json", JSON.stringify(obj, null, 2));
|
||||||
|
};
|
||||||
|
|
||||||
|
var RGBToHex = function RGBToHex(r, g, b) {
|
||||||
|
return ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
||||||
|
};
|
||||||
|
|
||||||
|
var UUIDGeneratorBrowser = function UUIDGeneratorBrowser() {
|
||||||
|
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
|
||||||
|
return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var crypto$1 = typeof require !== "undefined" && require('crypto');
|
||||||
|
var UUIDGeneratorNode = function UUIDGeneratorNode() {
|
||||||
|
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
|
||||||
|
return (c ^ crypto$1.randomBytes(1)[0] & 15 >> c / 4).toString(16);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var anagrams = function anagrams(str) {
|
var anagrams = function anagrams(str) {
|
||||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||||
return str.split('').reduce(function (acc, letter, i) {
|
return str.split('').reduce(function (acc, letter, i) {
|
||||||
@ -95,6 +122,10 @@ var cleanObj = function cleanObj(obj) {
|
|||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var cloneRegExp = function cloneRegExp(regExp) {
|
||||||
|
return new RegExp(regExp.source, regExp.flags);
|
||||||
|
};
|
||||||
|
|
||||||
var coalesce = function coalesce() {
|
var coalesce = function coalesce() {
|
||||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||||
args[_key] = arguments[_key];
|
args[_key] = arguments[_key];
|
||||||
@ -145,6 +176,23 @@ var compose = function compose() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var copyToClipboard = function copyToClipboard(str) {
|
||||||
|
var el = document.createElement('textarea');
|
||||||
|
el.value = str;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
document.body.appendChild(el);
|
||||||
|
var selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
if (selected) {
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
document.getSelection().addRange(selected);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var countOccurrences = function countOccurrences(arr, value) {
|
var countOccurrences = function countOccurrences(arr, value) {
|
||||||
return arr.reduce(function (a, v) {
|
return arr.reduce(function (a, v) {
|
||||||
return v === value ? a + 1 : a + 0;
|
return v === value ? a + 1 : a + 0;
|
||||||
@ -178,6 +226,14 @@ var deepFlatten = function deepFlatten(arr) {
|
|||||||
})));
|
})));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var defer = function defer(fn) {
|
||||||
|
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||||
|
args[_key - 1] = arguments[_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return setTimeout.apply(undefined, [fn, 1].concat(args));
|
||||||
|
};
|
||||||
|
|
||||||
var detectDeviceType = function detectDeviceType() {
|
var detectDeviceType = function detectDeviceType() {
|
||||||
return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 'Mobile' : 'Desktop'
|
return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 'Mobile' : 'Desktop'
|
||||||
);
|
);
|
||||||
@ -243,6 +299,24 @@ var elementIsVisibleInViewport = function elementIsVisibleInViewport(el) {
|
|||||||
return partiallyVisible ? (top > 0 && top < innerHeight || bottom > 0 && bottom < innerHeight) && (left > 0 && left < innerWidth || right > 0 && right < innerWidth) : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
return partiallyVisible ? (top > 0 && top < innerHeight || bottom > 0 && bottom < innerHeight) && (left > 0 && left < innerWidth || right > 0 && right < innerWidth) : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _slicedToArray = function () { function sliceIterator(arr, i) { 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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||||||
|
|
||||||
|
var elo = function elo(_ref) {
|
||||||
|
var _ref2 = _slicedToArray(_ref, 2),
|
||||||
|
a = _ref2[0],
|
||||||
|
b = _ref2[1];
|
||||||
|
|
||||||
|
var kFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32;
|
||||||
|
|
||||||
|
var expectedScore = function expectedScore(self, opponent) {
|
||||||
|
return 1 / (1 + Math.pow(10, (opponent - self) / 400));
|
||||||
|
};
|
||||||
|
var newRating = function newRating(rating, i) {
|
||||||
|
return rating + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
||||||
|
};
|
||||||
|
return [newRating(a, 1), newRating(b, 0)];
|
||||||
|
};
|
||||||
|
|
||||||
var escapeHTML = function escapeHTML(str) {
|
var escapeHTML = function escapeHTML(str) {
|
||||||
return str.replace(/[&<>'"]/g, function (tag) {
|
return str.replace(/[&<>'"]/g, function (tag) {
|
||||||
return {
|
return {
|
||||||
@ -391,6 +465,16 @@ var hasClass = function hasClass(el, className) {
|
|||||||
return el.classList.contains(className);
|
return el.classList.contains(className);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var hasFlags = function hasFlags() {
|
||||||
|
for (var _len = arguments.length, flags = Array(_len), _key = 0; _key < _len; _key++) {
|
||||||
|
flags[_key] = arguments[_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags.every(function (flag) {
|
||||||
|
return process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var head = function head(arr) {
|
var head = function head(arr) {
|
||||||
return arr[0];
|
return arr[0];
|
||||||
};
|
};
|
||||||
@ -421,6 +505,13 @@ var httpsRedirect = function httpsRedirect() {
|
|||||||
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var inRange = function inRange(n, start) {
|
||||||
|
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
||||||
|
|
||||||
|
if (end && start > end) end = [start, start = end][0];
|
||||||
|
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
||||||
|
};
|
||||||
|
|
||||||
var initial = function initial(arr) {
|
var initial = function initial(arr) {
|
||||||
return arr.slice(0, -1);
|
return arr.slice(0, -1);
|
||||||
};
|
};
|
||||||
@ -444,13 +535,6 @@ var initializeArrayWithValues = function initializeArrayWithValues(n) {
|
|||||||
return Array(n).fill(value);
|
return Array(n).fill(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
var inRange = function inRange(n, start) {
|
|
||||||
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
||||||
|
|
||||||
if (end && start > end) end = [start, start = end][0];
|
|
||||||
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
|
||||||
};
|
|
||||||
|
|
||||||
var intersection = function intersection(a, b) {
|
var intersection = function intersection(a, b) {
|
||||||
var s = new Set(b);
|
var s = new Set(b);
|
||||||
return a.filter(function (x) {
|
return a.filter(function (x) {
|
||||||
@ -458,6 +542,18 @@ var intersection = function intersection(a, b) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var invertKeyValues = function invertKeyValues(obj) {
|
||||||
|
return Object.keys(obj).reduce(function (acc, key) {
|
||||||
|
acc[obj[key]] = key;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
var isAbsoluteURL = function isAbsoluteURL(str) {
|
||||||
|
return (/^[a-z][a-z0-9+.-]*:/.test(str)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
var isArmstrongNumber = function isArmstrongNumber(digits) {
|
var isArmstrongNumber = function isArmstrongNumber(digits) {
|
||||||
return function (arr) {
|
return function (arr) {
|
||||||
return arr.reduce(function (a, d) {
|
return arr.reduce(function (a, d) {
|
||||||
@ -470,6 +566,16 @@ var isArray = function isArray(val) {
|
|||||||
return !!val && Array.isArray(val);
|
return !!val && Array.isArray(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function _toConsumableArray$5(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
|
var isArrayLike = function isArrayLike(val) {
|
||||||
|
try {
|
||||||
|
return [].concat(_toConsumableArray$5(val)), true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var isBoolean = function isBoolean(val) {
|
var isBoolean = function isBoolean(val) {
|
||||||
return typeof val === 'boolean';
|
return typeof val === 'boolean';
|
||||||
};
|
};
|
||||||
@ -486,35 +592,97 @@ var isFunction = function isFunction(val) {
|
|||||||
return val && typeof val === 'function';
|
return val && typeof val === 'function';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var isNull = function isNull(val) {
|
||||||
|
return val === null;
|
||||||
|
};
|
||||||
|
|
||||||
var isNumber = function isNumber(val) {
|
var isNumber = function isNumber(val) {
|
||||||
return typeof val === 'number';
|
return typeof val === 'number';
|
||||||
};
|
};
|
||||||
|
|
||||||
var isPrime = function isPrime(num) {
|
var isPrime = function isPrime(num) {
|
||||||
var boundary = Math.floor(Math.sqrt(num));
|
var boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i * i <= boundary; i++) {
|
for (var i = 2; i <= boundary; i++) {
|
||||||
if (num % i == 0) return false;
|
if (num % i == 0) return false;
|
||||||
}return num >= 2;
|
}return num >= 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||||
|
|
||||||
|
var isPrimitive = function isPrimitive(val) {
|
||||||
|
return !['object', 'function'].includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val === null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||||
|
|
||||||
|
var isPromiseLike = function isPromiseLike(obj) {
|
||||||
|
return obj !== null && ((typeof obj === 'undefined' ? 'undefined' : _typeof$1(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
||||||
|
};
|
||||||
|
|
||||||
|
var _slicedToArray$1 = function () { function sliceIterator(arr, i) { 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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||||||
|
|
||||||
|
var isSorted = function isSorted(arr) {
|
||||||
|
var direction = arr[0] > arr[1] ? -1 : 1;
|
||||||
|
var _iteratorNormalCompletion = true;
|
||||||
|
var _didIteratorError = false;
|
||||||
|
var _iteratorError = undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (var _iterator = arr.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||||
|
var _ref = _step.value;
|
||||||
|
|
||||||
|
var _ref2 = _slicedToArray$1(_ref, 2);
|
||||||
|
|
||||||
|
var i = _ref2[0];
|
||||||
|
var val = _ref2[1];
|
||||||
|
|
||||||
|
if (i === arr.length - 1) return direction;else if ((val - arr[i + 1]) * direction > 0) return 0;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
_didIteratorError = true;
|
||||||
|
_iteratorError = err;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||||
|
_iterator.return();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (_didIteratorError) {
|
||||||
|
throw _iteratorError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var isString = function isString(val) {
|
var isString = function isString(val) {
|
||||||
return typeof val === 'string';
|
return typeof val === 'string';
|
||||||
};
|
};
|
||||||
|
|
||||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||||
|
|
||||||
var isSymbol = function isSymbol(val) {
|
var isSymbol = function isSymbol(val) {
|
||||||
return (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'symbol';
|
return (typeof val === 'undefined' ? 'undefined' : _typeof$2(val)) === 'symbol';
|
||||||
};
|
};
|
||||||
|
|
||||||
var JSONToDate = function JSONToDate(arr) {
|
var isTravisCI = function isTravisCI() {
|
||||||
var dt = new Date(parseInt(arr.toString().substr(6)));
|
return 'TRAVIS' in process.env && 'CI' in process.env;
|
||||||
return dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var fs = typeof require !== "undefined" && require('fs');
|
var isValidJSON = function isValidJSON(obj) {
|
||||||
var JSONToFile = function JSONToFile(obj, filename) {
|
try {
|
||||||
return fs.writeFile(filename + ".json", JSON.stringify(obj, null, 2));
|
JSON.parse(obj);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var join = function join(arr) {
|
||||||
|
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
|
||||||
|
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : separator;
|
||||||
|
return arr.reduce(function (acc, val, i) {
|
||||||
|
return i == arr.length - 2 ? acc + val + end : i == arr.length - 1 ? acc + val : acc + val + separator;
|
||||||
|
}, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
var last = function last(arr) {
|
var last = function last(arr) {
|
||||||
@ -550,30 +718,43 @@ var mapObject = function mapObject(arr, fn) {
|
|||||||
}();
|
}();
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$5(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
var mask = function mask(cc) {
|
||||||
|
var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
|
||||||
var max = function max() {
|
var mask = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '*';
|
||||||
var _ref;
|
return ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
|
||||||
|
|
||||||
return Math.max.apply(Math, _toConsumableArray$5((_ref = []).concat.apply(_ref, arguments)));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$6(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
function _toConsumableArray$6(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
|
var max = function max() {
|
||||||
|
var _ref;
|
||||||
|
|
||||||
|
return Math.max.apply(Math, _toConsumableArray$6((_ref = []).concat.apply(_ref, arguments)));
|
||||||
|
};
|
||||||
|
|
||||||
|
function _toConsumableArray$7(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var median = function median(arr) {
|
var median = function median(arr) {
|
||||||
var mid = Math.floor(arr.length / 2),
|
var mid = Math.floor(arr.length / 2),
|
||||||
nums = [].concat(_toConsumableArray$6(arr)).sort(function (a, b) {
|
nums = [].concat(_toConsumableArray$7(arr)).sort(function (a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$7(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
var memoize = function memoize(fn) {
|
||||||
|
var cache = Object.create(null);
|
||||||
|
return function (value) {
|
||||||
|
return cache[value] || (cache[value] = fn(value));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function _toConsumableArray$8(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var min = function min(arr) {
|
var min = function min(arr) {
|
||||||
var _ref;
|
var _ref;
|
||||||
|
|
||||||
return Math.min.apply(Math, _toConsumableArray$7((_ref = []).concat.apply(_ref, _toConsumableArray$7(arr))));
|
return Math.min.apply(Math, _toConsumableArray$8((_ref = []).concat.apply(_ref, _toConsumableArray$8(arr))));
|
||||||
};
|
};
|
||||||
|
|
||||||
var negate = function negate(func) {
|
var negate = function negate(func) {
|
||||||
@ -613,16 +794,30 @@ var onUserInputChange = function onUserInputChange(callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var _slicedToArray = function () { function sliceIterator(arr, i) { 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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
var once = function once(fn) {
|
||||||
|
var called = false;
|
||||||
|
return function () {
|
||||||
|
if (called) return;
|
||||||
|
called = true;
|
||||||
|
|
||||||
function _toConsumableArray$8(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||||
|
args[_key] = arguments[_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return fn.apply(this, args);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var _slicedToArray$2 = function () { function sliceIterator(arr, i) { 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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||||||
|
|
||||||
|
function _toConsumableArray$9(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var orderBy = function orderBy(arr, props, orders) {
|
var orderBy = function orderBy(arr, props, orders) {
|
||||||
return [].concat(_toConsumableArray$8(arr)).sort(function (a, b) {
|
return [].concat(_toConsumableArray$9(arr)).sort(function (a, b) {
|
||||||
return props.reduce(function (acc, prop, i) {
|
return props.reduce(function (acc, prop, i) {
|
||||||
if (acc === 0) {
|
if (acc === 0) {
|
||||||
var _ref = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]],
|
var _ref = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]],
|
||||||
_ref2 = _slicedToArray(_ref, 2),
|
_ref2 = _slicedToArray$2(_ref, 2),
|
||||||
p1 = _ref2[0],
|
p1 = _ref2[0],
|
||||||
p2 = _ref2[1];
|
p2 = _ref2[1];
|
||||||
|
|
||||||
@ -670,6 +865,17 @@ var powerset = function powerset(arr) {
|
|||||||
}, [[]]);
|
}, [[]]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var prettyBytes = function prettyBytes(num) {
|
||||||
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
||||||
|
var addSpace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||||
|
|
||||||
|
var UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
if (Math.abs(num) < 1) return num + (addSpace ? ' ' : '') + UNITS[0];
|
||||||
|
var exponent = Math.min(Math.floor(Math.log10(num < 0 ? -num : num) / 3), UNITS.length - 1);
|
||||||
|
var n = Number(((num < 0 ? -num : num) / Math.pow(1000, exponent)).toPrecision(precision));
|
||||||
|
return (num < 0 ? '-' : '') + n + (addSpace ? ' ' : '') + UNITS[exponent];
|
||||||
|
};
|
||||||
|
|
||||||
var primes = function primes(num) {
|
var primes = function primes(num) {
|
||||||
var arr = Array.from({ length: num - 1 }).map(function (x, i) {
|
var arr = Array.from({ length: num - 1 }).map(function (x, i) {
|
||||||
return i + 2;
|
return i + 2;
|
||||||
@ -744,7 +950,7 @@ var pullAtValue = function pullAtValue(arr, pullArr) {
|
|||||||
return removed;
|
return removed;
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$9(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
function _toConsumableArray$10(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
function _toArray$1(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
function _toArray$1(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
||||||
|
|
||||||
@ -753,9 +959,9 @@ var quickSort = function quickSort(_ref, desc) {
|
|||||||
n = _ref2[0],
|
n = _ref2[0],
|
||||||
nums = _ref2.slice(1);
|
nums = _ref2.slice(1);
|
||||||
|
|
||||||
return isNaN(n) ? [] : [].concat(_toConsumableArray$9(quickSort(nums.filter(function (v) {
|
return isNaN(n) ? [] : [].concat(_toConsumableArray$10(quickSort(nums.filter(function (v) {
|
||||||
return desc ? v > n : v <= n;
|
return desc ? v > n : v <= n;
|
||||||
}), desc)), [n], _toConsumableArray$9(quickSort(nums.filter(function (v) {
|
}), desc)), [n], _toConsumableArray$10(quickSort(nums.filter(function (v) {
|
||||||
return !desc ? v > n : v <= n;
|
return !desc ? v > n : v <= n;
|
||||||
}), desc)));
|
}), desc)));
|
||||||
};
|
};
|
||||||
@ -783,6 +989,15 @@ var redirect = function redirect(url) {
|
|||||||
return asLink ? window.location.href = url : window.location.replace(url);
|
return asLink ? window.location.href = url : window.location.replace(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var reducedFilter = function reducedFilter(data, keys, fn) {
|
||||||
|
return data.filter(fn).map(function (el) {
|
||||||
|
return keys.reduce(function (acc, key) {
|
||||||
|
acc[key] = el[key];
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var remove = function remove(arr, func) {
|
var remove = function remove(arr, func) {
|
||||||
return Array.isArray(arr) ? arr.filter(func).reduce(function (acc, val) {
|
return Array.isArray(arr) ? arr.filter(func).reduce(function (acc, val) {
|
||||||
arr.splice(arr.indexOf(val), 1);
|
arr.splice(arr.indexOf(val), 1);
|
||||||
@ -801,15 +1016,28 @@ var reverseString = function reverseString(str) {
|
|||||||
return str.split('').reverse().join('');
|
return str.split('').reverse().join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
var RGBToHex = function RGBToHex(r, g, b) {
|
|
||||||
return ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
|
||||||
};
|
|
||||||
|
|
||||||
var round = function round(n) {
|
var round = function round(n) {
|
||||||
var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
||||||
return Number(Math.round(n + "e" + decimals) + "e-" + decimals);
|
return Number(Math.round(n + "e" + decimals) + "e-" + decimals);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var runAsync = function runAsync(fn) {
|
||||||
|
var blob = '\n var fn = ' + fn.toString() + ';\n this.postMessage(fn());\n ';
|
||||||
|
var worker = new Worker(URL.createObjectURL(new Blob([blob]), {
|
||||||
|
type: 'application/javascript; charset=utf-8'
|
||||||
|
}));
|
||||||
|
return new Promise(function (res, rej) {
|
||||||
|
worker.onmessage = function (_ref) {
|
||||||
|
var data = _ref.data;
|
||||||
|
|
||||||
|
res(data), worker.terminate();
|
||||||
|
};
|
||||||
|
worker.onerror = function (err) {
|
||||||
|
rej(err), worker.terminate();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var runPromisesInSeries = function runPromisesInSeries(ps) {
|
var runPromisesInSeries = function runPromisesInSeries(ps) {
|
||||||
return ps.reduce(function (p, next) {
|
return ps.reduce(function (p, next) {
|
||||||
return p.then(next);
|
return p.then(next);
|
||||||
@ -820,6 +1048,24 @@ var sample = function sample(arr) {
|
|||||||
return arr[Math.floor(Math.random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function _toArray$2(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
||||||
|
|
||||||
|
var sampleSize = function sampleSize(_ref) {
|
||||||
|
var _ref2 = _toArray$2(_ref),
|
||||||
|
arr = _ref2.slice(0);
|
||||||
|
|
||||||
|
var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
||||||
|
|
||||||
|
var m = arr.length;
|
||||||
|
while (m) {
|
||||||
|
var i = Math.floor(Math.random() * m--);
|
||||||
|
var _ref3 = [arr[i], arr[m]];
|
||||||
|
arr[m] = _ref3[0];
|
||||||
|
arr[i] = _ref3[1];
|
||||||
|
}
|
||||||
|
return arr.slice(0, n);
|
||||||
|
};
|
||||||
|
|
||||||
var scrollToTop = function scrollToTop() {
|
var scrollToTop = function scrollToTop() {
|
||||||
var c = document.documentElement.scrollTop || document.body.scrollTop;
|
var c = document.documentElement.scrollTop || document.body.scrollTop;
|
||||||
if (c > 0) {
|
if (c > 0) {
|
||||||
@ -859,10 +1105,10 @@ var show = function show() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toArray$2(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
function _toArray$3(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
||||||
|
|
||||||
var shuffle = function shuffle(_ref) {
|
var shuffle = function shuffle(_ref) {
|
||||||
var _ref2 = _toArray$2(_ref),
|
var _ref2 = _toArray$3(_ref),
|
||||||
arr = _ref2.slice(0);
|
arr = _ref2.slice(0);
|
||||||
|
|
||||||
var m = arr.length;
|
var m = arr.length;
|
||||||
@ -881,18 +1127,72 @@ var similarity = function similarity(arr, values) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _typeof$3 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||||
|
|
||||||
|
var size = function size(value) {
|
||||||
|
return Array.isArray(value) ? value.length : value && (typeof value === 'undefined' ? 'undefined' : _typeof$3(value)) === 'object' ? value.size || value.length || Object.keys(value).length : typeof value === 'string' ? new Blob([value]).size : 0;
|
||||||
|
};
|
||||||
|
|
||||||
var sleep = function sleep(ms) {
|
var sleep = function sleep(ms) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
return setTimeout(resolve, ms);
|
return setTimeout(resolve, ms);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var solveRPN = function solveRPN(rpn) {
|
||||||
|
var OPERATORS = {
|
||||||
|
'*': function _(a, b) {
|
||||||
|
return a * b;
|
||||||
|
},
|
||||||
|
'+': function _(a, b) {
|
||||||
|
return a + b;
|
||||||
|
},
|
||||||
|
'-': function _(a, b) {
|
||||||
|
return a - b;
|
||||||
|
},
|
||||||
|
'/': function _(a, b) {
|
||||||
|
return a / b;
|
||||||
|
},
|
||||||
|
'**': function _(a, b) {
|
||||||
|
return Math.pow(a, b);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var _ref = [[], rpn.replace(/\^/g, '**').split(/\s+/g).filter(function (el) {
|
||||||
|
return !/\s+/.test(el) && el !== '';
|
||||||
|
})],
|
||||||
|
stack = _ref[0],
|
||||||
|
solve = _ref[1];
|
||||||
|
|
||||||
|
solve.forEach(function (symbol) {
|
||||||
|
if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {
|
||||||
|
stack.push(symbol);
|
||||||
|
} else if (Object.keys(OPERATORS).includes(symbol)) {
|
||||||
|
var _ref2 = [stack.pop(), stack.pop()],
|
||||||
|
a = _ref2[0],
|
||||||
|
b = _ref2[1];
|
||||||
|
|
||||||
|
stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
|
||||||
|
} else {
|
||||||
|
throw symbol + ' is not a recognized symbol';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (stack.length === 1) return stack.pop();else throw rpn + ' is not a proper RPN. Please check it and try again';
|
||||||
|
};
|
||||||
|
|
||||||
var sortCharactersInString = function sortCharactersInString(str) {
|
var sortCharactersInString = function sortCharactersInString(str) {
|
||||||
return str.split('').sort(function (a, b) {
|
return str.split('').sort(function (a, b) {
|
||||||
return a.localeCompare(b);
|
return a.localeCompare(b);
|
||||||
}).join('');
|
}).join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var sortedIndex = function sortedIndex(arr, n) {
|
||||||
|
var isDescending = arr[0] > arr[arr.length - 1];
|
||||||
|
var index = arr.findIndex(function (el) {
|
||||||
|
return isDescending ? n >= el : n <= el;
|
||||||
|
});
|
||||||
|
return index === -1 ? arr.length : index;
|
||||||
|
};
|
||||||
|
|
||||||
var speechSynthesis = function speechSynthesis(message) {
|
var speechSynthesis = function speechSynthesis(message) {
|
||||||
var msg = new SpeechSynthesisUtterance(message);
|
var msg = new SpeechSynthesisUtterance(message);
|
||||||
msg.voice = window.speechSynthesis.getVoices()[0];
|
msg.voice = window.speechSynthesis.getVoices()[0];
|
||||||
@ -903,11 +1203,11 @@ var splitLines = function splitLines(str) {
|
|||||||
return str.split(/\r?\n/);
|
return str.split(/\r?\n/);
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$10(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
function _toConsumableArray$11(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var spreadOver = function spreadOver(fn) {
|
var spreadOver = function spreadOver(fn) {
|
||||||
return function (argsArr) {
|
return function (argsArr) {
|
||||||
return fn.apply(undefined, _toConsumableArray$10(argsArr));
|
return fn.apply(undefined, _toConsumableArray$11(argsArr));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -932,14 +1232,24 @@ var sum = function sum() {
|
|||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$11(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
var sumPower = function sumPower(end) {
|
||||||
|
var power = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
||||||
|
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
||||||
|
return Array(end + 1 - start).fill(0).map(function (x, i) {
|
||||||
|
return Math.pow(i + start, power);
|
||||||
|
}).reduce(function (a, b) {
|
||||||
|
return a + b;
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
function _toConsumableArray$12(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var symmetricDifference = function symmetricDifference(a, b) {
|
var symmetricDifference = function symmetricDifference(a, b) {
|
||||||
var sA = new Set(a),
|
var sA = new Set(a),
|
||||||
sB = new Set(b);
|
sB = new Set(b);
|
||||||
return [].concat(_toConsumableArray$11(a.filter(function (x) {
|
return [].concat(_toConsumableArray$12(a.filter(function (x) {
|
||||||
return !sB.has(x);
|
return !sB.has(x);
|
||||||
})), _toConsumableArray$11(b.filter(function (x) {
|
})), _toConsumableArray$12(b.filter(function (x) {
|
||||||
return !sA.has(x);
|
return !sA.has(x);
|
||||||
})));
|
})));
|
||||||
};
|
};
|
||||||
@ -982,20 +1292,12 @@ var toEnglishDate = function toEnglishDate(time) {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var toggleClass = function toggleClass(el, className) {
|
|
||||||
return el.classList.toggle(className);
|
|
||||||
};
|
|
||||||
|
|
||||||
var toKebabCase = function toKebabCase(str) {
|
var toKebabCase = function toKebabCase(str) {
|
||||||
return str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function (x) {
|
return str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function (x) {
|
||||||
return x.toLowerCase();
|
return x.toLowerCase();
|
||||||
}).join('-');
|
}).join('-');
|
||||||
};
|
};
|
||||||
|
|
||||||
var tomorrow = function tomorrow() {
|
|
||||||
return new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
var toOrdinalSuffix = function toOrdinalSuffix(num) {
|
var toOrdinalSuffix = function toOrdinalSuffix(num) {
|
||||||
var int = parseInt(num),
|
var int = parseInt(num),
|
||||||
digits = [int % 10, int % 100],
|
digits = [int % 10, int % 100],
|
||||||
@ -1006,11 +1308,19 @@ var toOrdinalSuffix = function toOrdinalSuffix(num) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var toSnakeCase = function toSnakeCase(str) {
|
var toSnakeCase = function toSnakeCase(str) {
|
||||||
str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function (x) {
|
return str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function (x) {
|
||||||
return x.toLowerCase();
|
return x.toLowerCase();
|
||||||
}).join('_');
|
}).join('_');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var toggleClass = function toggleClass(el, className) {
|
||||||
|
return el.classList.toggle(className);
|
||||||
|
};
|
||||||
|
|
||||||
|
var tomorrow = function tomorrow() {
|
||||||
|
return new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
var truncateString = function truncateString(str, num) {
|
var truncateString = function truncateString(str, num) {
|
||||||
return str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
|
return str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
|
||||||
};
|
};
|
||||||
@ -1033,23 +1343,14 @@ var unescapeHTML = function unescapeHTML(str) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$12(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
function _toConsumableArray$13(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var union = function union(a, b) {
|
var union = function union(a, b) {
|
||||||
return Array.from(new Set([].concat(_toConsumableArray$12(a), _toConsumableArray$12(b))));
|
return Array.from(new Set([].concat(_toConsumableArray$13(a), _toConsumableArray$13(b))));
|
||||||
};
|
};
|
||||||
|
|
||||||
var UUIDGeneratorBrowser = function UUIDGeneratorBrowser() {
|
var untildify = function untildify(str) {
|
||||||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
|
return str.replace(/^~($|\/|\\)/, (typeof require !== "undefined" && require('os').homedir()) + "$1");
|
||||||
return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var crypto$1 = typeof require !== "undefined" && require('crypto');
|
|
||||||
var UUIDGeneratorNode = function UUIDGeneratorNode() {
|
|
||||||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
|
|
||||||
return (c ^ crypto$1.randomBytes(1)[0] & 15 >> c / 4).toString(16);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var validateNumber = function validateNumber(n) {
|
var validateNumber = function validateNumber(n) {
|
||||||
@ -1071,14 +1372,20 @@ var words = function words(str) {
|
|||||||
return str.split(pattern).filter(Boolean);
|
return str.split(pattern).filter(Boolean);
|
||||||
};
|
};
|
||||||
|
|
||||||
function _toConsumableArray$13(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
var yesNo = function yesNo(val) {
|
||||||
|
var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||||
|
return (/^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function _toConsumableArray$14(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
var zip = function zip() {
|
var zip = function zip() {
|
||||||
for (var _len = arguments.length, arrays = Array(_len), _key = 0; _key < _len; _key++) {
|
for (var _len = arguments.length, arrays = Array(_len), _key = 0; _key < _len; _key++) {
|
||||||
arrays[_key] = arguments[_key];
|
arrays[_key] = arguments[_key];
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxLength = Math.max.apply(Math, _toConsumableArray$13(arrays.map(function (x) {
|
var maxLength = Math.max.apply(Math, _toConsumableArray$14(arrays.map(function (x) {
|
||||||
return x.length;
|
return x.length;
|
||||||
})));
|
})));
|
||||||
return Array.from({ length: maxLength }).map(function (_, i) {
|
return Array.from({ length: maxLength }).map(function (_, i) {
|
||||||
@ -1094,7 +1401,7 @@ var zipObject = function zipObject(props, values) {
|
|||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
var imports = { anagrams: anagrams, arrayToHtmlList: arrayToHtmlList, average: average, bottomVisible: bottomVisible, byteSize: byteSize, call: call, capitalize: capitalize, capitalizeEveryWord: capitalizeEveryWord, chainAsync: chainAsync, chunk: chunk, clampNumber: clampNumber, cleanObj: cleanObj, coalesce: coalesce, coalesceFactory: coalesceFactory, collatz: collatz, collectInto: collectInto, compact: compact, compose: compose, countOccurrences: countOccurrences, countVowels: countVowels, currentURL: currentURL, curry: curry, deepFlatten: deepFlatten, detectDeviceType: detectDeviceType, difference: difference, differenceWith: differenceWith, digitize: digitize, distance: distance, distinctValuesOfArray: distinctValuesOfArray, dropElements: dropElements, dropRight: dropRight, elementIsVisibleInViewport: elementIsVisibleInViewport, escapeHTML: escapeHTML, escapeRegExp: escapeRegExp, everyNth: everyNth, extendHex: extendHex, factorial: factorial, fibonacci: fibonacci, fibonacciCountUntilNum: fibonacciCountUntilNum, fibonacciUntilNum: fibonacciUntilNum, filterNonUnique: filterNonUnique, flatten: flatten, flattenDepth: flattenDepth, flip: flip, fromCamelCase: fromCamelCase, functionName: functionName, gcd: gcd, getDaysDiffBetweenDates: getDaysDiffBetweenDates, getScrollPosition: getScrollPosition, getStyle: getStyle, getType: getType, getURLParameters: getURLParameters, groupBy: groupBy, hammingDistance: hammingDistance, hasClass: hasClass, head: head, hexToRGB: hexToRGB, hide: hide, httpsRedirect: httpsRedirect, initial: initial, initialize2DArray: initialize2DArray, initializeArrayWithRange: initializeArrayWithRange, initializeArrayWithValues: initializeArrayWithValues, inRange: inRange, intersection: intersection, isArmstrongNumber: isArmstrongNumber, isArray: isArray, isBoolean: isBoolean, isDivisible: isDivisible, isEven: isEven, isFunction: isFunction, isNumber: isNumber, isPrime: isPrime, isString: isString, isSymbol: isSymbol, JSONToDate: JSONToDate, JSONToFile: JSONToFile, last: last, lcm: lcm, lowercaseKeys: lowercaseKeys, mapObject: mapObject, max: max, median: median, min: min, negate: negate, nthElement: nthElement, objectFromPairs: objectFromPairs, objectToPairs: objectToPairs, onUserInputChange: onUserInputChange, orderBy: orderBy, palindrome: palindrome, percentile: percentile, pick: pick, pipeFunctions: pipeFunctions, powerset: powerset, primes: primes, promisify: promisify, pull: pull, pullAtIndex: pullAtIndex, pullAtValue: pullAtValue, quickSort: quickSort, randomHexColorCode: randomHexColorCode, randomIntegerInRange: randomIntegerInRange, randomNumberInRange: randomNumberInRange, readFileLines: readFileLines, redirect: redirect, remove: remove, repeatString: repeatString, reverseString: reverseString, RGBToHex: RGBToHex, round: round, runPromisesInSeries: runPromisesInSeries, sample: sample, scrollToTop: scrollToTop, sdbm: sdbm, select: select, setStyle: setStyle, shallowClone: shallowClone, show: show, shuffle: shuffle, similarity: similarity, sleep: sleep, sortCharactersInString: sortCharactersInString, speechSynthesis: speechSynthesis, splitLines: splitLines, spreadOver: spreadOver, standardDeviation: standardDeviation, sum: sum, symmetricDifference: symmetricDifference, tail: tail, take: take, takeRight: takeRight, timeTaken: timeTaken, toCamelCase: toCamelCase, toDecimalMark: toDecimalMark, toEnglishDate: toEnglishDate, toggleClass: toggleClass, toKebabCase: toKebabCase, tomorrow: tomorrow, toOrdinalSuffix: toOrdinalSuffix, toSnakeCase: toSnakeCase, truncateString: truncateString, truthCheckCollection: truthCheckCollection, unescapeHTML: unescapeHTML, union: union, UUIDGeneratorBrowser: UUIDGeneratorBrowser, UUIDGeneratorNode: UUIDGeneratorNode, validateNumber: validateNumber, without: without, words: words, zip: zip, zipObject: zipObject };
|
var imports = { JSONToDate: JSONToDate, JSONToFile: JSONToFile, RGBToHex: RGBToHex, UUIDGeneratorBrowser: UUIDGeneratorBrowser, UUIDGeneratorNode: UUIDGeneratorNode, anagrams: anagrams, arrayToHtmlList: arrayToHtmlList, average: average, bottomVisible: bottomVisible, byteSize: byteSize, call: call, capitalize: capitalize, capitalizeEveryWord: capitalizeEveryWord, chainAsync: chainAsync, chunk: chunk, clampNumber: clampNumber, cleanObj: cleanObj, cloneRegExp: cloneRegExp, coalesce: coalesce, coalesceFactory: coalesceFactory, collatz: collatz, collectInto: collectInto, compact: compact, compose: compose, copyToClipboard: copyToClipboard, countOccurrences: countOccurrences, countVowels: countVowels, currentURL: currentURL, curry: curry, deepFlatten: deepFlatten, defer: defer, detectDeviceType: detectDeviceType, difference: difference, differenceWith: differenceWith, digitize: digitize, distance: distance, distinctValuesOfArray: distinctValuesOfArray, dropElements: dropElements, dropRight: dropRight, elementIsVisibleInViewport: elementIsVisibleInViewport, elo: elo, escapeHTML: escapeHTML, escapeRegExp: escapeRegExp, everyNth: everyNth, extendHex: extendHex, factorial: factorial, fibonacci: fibonacci, fibonacciCountUntilNum: fibonacciCountUntilNum, fibonacciUntilNum: fibonacciUntilNum, filterNonUnique: filterNonUnique, flatten: flatten, flattenDepth: flattenDepth, flip: flip, fromCamelCase: fromCamelCase, functionName: functionName, gcd: gcd, getDaysDiffBetweenDates: getDaysDiffBetweenDates, getScrollPosition: getScrollPosition, getStyle: getStyle, getType: getType, getURLParameters: getURLParameters, groupBy: groupBy, hammingDistance: hammingDistance, hasClass: hasClass, hasFlags: hasFlags, head: head, hexToRGB: hexToRGB, hide: hide, httpsRedirect: httpsRedirect, inRange: inRange, initial: initial, initialize2DArray: initialize2DArray, initializeArrayWithRange: initializeArrayWithRange, initializeArrayWithValues: initializeArrayWithValues, intersection: intersection, invertKeyValues: invertKeyValues, isAbsoluteURL: isAbsoluteURL, isArmstrongNumber: isArmstrongNumber, isArray: isArray, isArrayLike: isArrayLike, isBoolean: isBoolean, isDivisible: isDivisible, isEven: isEven, isFunction: isFunction, isNull: isNull, isNumber: isNumber, isPrime: isPrime, isPrimitive: isPrimitive, isPromiseLike: isPromiseLike, isSorted: isSorted, isString: isString, isSymbol: isSymbol, isTravisCI: isTravisCI, isValidJSON: isValidJSON, join: join, last: last, lcm: lcm, lowercaseKeys: lowercaseKeys, mapObject: mapObject, mask: mask, max: max, median: median, memoize: memoize, min: min, negate: negate, nthElement: nthElement, objectFromPairs: objectFromPairs, objectToPairs: objectToPairs, onUserInputChange: onUserInputChange, once: once, orderBy: orderBy, palindrome: palindrome, percentile: percentile, pick: pick, pipeFunctions: pipeFunctions, powerset: powerset, prettyBytes: prettyBytes, primes: primes, promisify: promisify, pull: pull, pullAtIndex: pullAtIndex, pullAtValue: pullAtValue, quickSort: quickSort, randomHexColorCode: randomHexColorCode, randomIntegerInRange: randomIntegerInRange, randomNumberInRange: randomNumberInRange, readFileLines: readFileLines, redirect: redirect, reducedFilter: reducedFilter, remove: remove, repeatString: repeatString, reverseString: reverseString, round: round, runAsync: runAsync, runPromisesInSeries: runPromisesInSeries, sample: sample, sampleSize: sampleSize, scrollToTop: scrollToTop, sdbm: sdbm, select: select, setStyle: setStyle, shallowClone: shallowClone, show: show, shuffle: shuffle, similarity: similarity, size: size, sleep: sleep, solveRPN: solveRPN, sortCharactersInString: sortCharactersInString, sortedIndex: sortedIndex, speechSynthesis: speechSynthesis, splitLines: splitLines, spreadOver: spreadOver, standardDeviation: standardDeviation, sum: sum, sumPower: sumPower, symmetricDifference: symmetricDifference, tail: tail, take: take, takeRight: takeRight, timeTaken: timeTaken, toCamelCase: toCamelCase, toDecimalMark: toDecimalMark, toEnglishDate: toEnglishDate, toKebabCase: toKebabCase, toOrdinalSuffix: toOrdinalSuffix, toSnakeCase: toSnakeCase, toggleClass: toggleClass, tomorrow: tomorrow, truncateString: truncateString, truthCheckCollection: truthCheckCollection, unescapeHTML: unescapeHTML, union: union, untildify: untildify, validateNumber: validateNumber, without: without, words: words, yesNo: yesNo, zip: zip, zipObject: zipObject };
|
||||||
|
|
||||||
return imports;
|
return imports;
|
||||||
|
|
||||||
|
|||||||
2
dist/_30s.es5.min.js
vendored
2
dist/_30s.es5.min.js
vendored
File diff suppressed because one or more lines are too long
273
dist/_30s.esm.js
vendored
273
dist/_30s.esm.js
vendored
@ -1,3 +1,25 @@
|
|||||||
|
const JSONToDate = arr => {
|
||||||
|
const dt = new Date(parseInt(arr.toString().substr(6)));
|
||||||
|
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fs = typeof require !== "undefined" && require('fs');
|
||||||
|
const JSONToFile = (obj, filename) =>
|
||||||
|
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
||||||
|
|
||||||
|
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
||||||
|
|
||||||
|
const UUIDGeneratorBrowser = () =>
|
||||||
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
|
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
||||||
|
);
|
||||||
|
|
||||||
|
const crypto$1 = typeof require !== "undefined" && require('crypto');
|
||||||
|
const UUIDGeneratorNode = () =>
|
||||||
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
|
(c ^ (crypto$1.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
||||||
|
);
|
||||||
|
|
||||||
const anagrams = str => {
|
const anagrams = str => {
|
||||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||||
return str
|
return str
|
||||||
@ -54,6 +76,8 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
|||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||||
|
|
||||||
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
||||||
|
|
||||||
const coalesceFactory = valid => (...args) => args.find(valid);
|
const coalesceFactory = valid => (...args) => args.find(valid);
|
||||||
@ -66,6 +90,24 @@ const compact = arr => arr.filter(Boolean);
|
|||||||
|
|
||||||
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
||||||
|
|
||||||
|
const copyToClipboard = str => {
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = str;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
document.body.appendChild(el);
|
||||||
|
const selected =
|
||||||
|
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
if (selected) {
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
document.getSelection().addRange(selected);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const countOccurrences = (arr, value) => arr.reduce((a, v) => (v === value ? a + 1 : a + 0), 0);
|
const countOccurrences = (arr, value) => arr.reduce((a, v) => (v === value ? a + 1 : a + 0), 0);
|
||||||
|
|
||||||
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
||||||
@ -77,6 +119,8 @@ const curry = (fn, arity = fn.length, ...args) =>
|
|||||||
|
|
||||||
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||||
|
|
||||||
|
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
|
|
||||||
const detectDeviceType = () =>
|
const detectDeviceType = () =>
|
||||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||||
? 'Mobile'
|
? 'Mobile'
|
||||||
@ -111,6 +155,12 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
|||||||
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const elo = ([a, b], kFactor = 32) => {
|
||||||
|
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||||
|
const newRating = (rating, i) => rating + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
||||||
|
return [newRating(a, 1), newRating(b, 0)];
|
||||||
|
};
|
||||||
|
|
||||||
const escapeHTML = str =>
|
const escapeHTML = str =>
|
||||||
str.replace(
|
str.replace(
|
||||||
/[&<>'"]/g,
|
/[&<>'"]/g,
|
||||||
@ -213,6 +263,9 @@ const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) |
|
|||||||
|
|
||||||
const hasClass = (el, className) => el.classList.contains(className);
|
const hasClass = (el, className) => el.classList.contains(className);
|
||||||
|
|
||||||
|
const hasFlags = (...flags) =>
|
||||||
|
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
||||||
|
|
||||||
const head = arr => arr[0];
|
const head = arr => arr[0];
|
||||||
|
|
||||||
const hexToRGB = hex => {
|
const hexToRGB = hex => {
|
||||||
@ -241,6 +294,11 @@ const httpsRedirect = () => {
|
|||||||
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const inRange = (n, start, end = null) => {
|
||||||
|
if (end && start > end) end = [start, (start = end)][0];
|
||||||
|
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
||||||
|
};
|
||||||
|
|
||||||
const initial = arr => arr.slice(0, -1);
|
const initial = arr => arr.slice(0, -1);
|
||||||
|
|
||||||
const initialize2DArray = (w, h, val = null) =>
|
const initialize2DArray = (w, h, val = null) =>
|
||||||
@ -253,23 +311,34 @@ const initializeArrayWithRange = (end, start = 0) =>
|
|||||||
|
|
||||||
const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
||||||
|
|
||||||
const inRange = (n, start, end = null) => {
|
|
||||||
if (end && start > end) end = [start, (start = end)][0];
|
|
||||||
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
|
||||||
};
|
|
||||||
|
|
||||||
const intersection = (a, b) => {
|
const intersection = (a, b) => {
|
||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => s.has(x));
|
return a.filter(x => s.has(x));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const invertKeyValues = obj =>
|
||||||
|
Object.keys(obj).reduce((acc, key) => {
|
||||||
|
acc[obj[key]] = key;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||||
|
|
||||||
const isArmstrongNumber = digits =>
|
const isArmstrongNumber = digits =>
|
||||||
(arr => arr.reduce((a, d) => a + Math.pow(parseInt(d), arr.length), 0) == digits)(
|
(arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(
|
||||||
(digits + '').split('')
|
(digits + '').split('')
|
||||||
);
|
);
|
||||||
|
|
||||||
const isArray = val => !!val && Array.isArray(val);
|
const isArray = val => !!val && Array.isArray(val);
|
||||||
|
|
||||||
|
const isArrayLike = val => {
|
||||||
|
try {
|
||||||
|
return [...val], true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const isBoolean = val => typeof val === 'boolean';
|
const isBoolean = val => typeof val === 'boolean';
|
||||||
|
|
||||||
const isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
const isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
||||||
@ -278,26 +347,53 @@ const isEven = num => num % 2 === 0;
|
|||||||
|
|
||||||
const isFunction = val => val && typeof val === 'function';
|
const isFunction = val => val && typeof val === 'function';
|
||||||
|
|
||||||
|
const isNull = val => val === null;
|
||||||
|
|
||||||
const isNumber = val => typeof val === 'number';
|
const isNumber = val => typeof val === 'number';
|
||||||
|
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
const boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
|
for (var i = 2; i <= boundary; i++) if (num % i == 0) return false;
|
||||||
return num >= 2;
|
return num >= 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
|
||||||
|
|
||||||
|
const isPromiseLike = obj =>
|
||||||
|
obj !== null &&
|
||||||
|
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||||
|
typeof obj.then === 'function';
|
||||||
|
|
||||||
|
const isSorted = arr => {
|
||||||
|
const direction = arr[0] > arr[1] ? -1 : 1;
|
||||||
|
for (let [i, val] of arr.entries())
|
||||||
|
if (i === arr.length - 1) return direction;
|
||||||
|
else if ((val - arr[i + 1]) * direction > 0) return 0;
|
||||||
|
};
|
||||||
|
|
||||||
const isString = val => typeof val === 'string';
|
const isString = val => typeof val === 'string';
|
||||||
|
|
||||||
const isSymbol = val => typeof val === 'symbol';
|
const isSymbol = val => typeof val === 'symbol';
|
||||||
|
|
||||||
const JSONToDate = arr => {
|
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
||||||
const dt = new Date(parseInt(arr.toString().substr(6)));
|
|
||||||
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
const isValidJSON = obj => {
|
||||||
|
try {
|
||||||
|
JSON.parse(obj);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fs = typeof require !== "undefined" && require('fs');
|
const join = (arr, separator = ',', end = separator) =>
|
||||||
const JSONToFile = (obj, filename) =>
|
arr.reduce(
|
||||||
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
(acc, val, i) =>
|
||||||
|
i == arr.length - 2
|
||||||
|
? acc + val + end
|
||||||
|
: i == arr.length - 1 ? acc + val : acc + val + separator,
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
const last = arr => arr[arr.length - 1];
|
const last = arr => arr[arr.length - 1];
|
||||||
|
|
||||||
@ -317,6 +413,9 @@ const mapObject = (arr, fn) =>
|
|||||||
(a => (
|
(a => (
|
||||||
a = [arr, arr.map(fn)], a[0].reduce((acc, val, ind) => (acc[val] = a[1][ind], acc), {})))();
|
a = [arr, arr.map(fn)], a[0].reduce((acc, val, ind) => (acc[val] = a[1][ind], acc), {})))();
|
||||||
|
|
||||||
|
const mask = (cc, num = 4, mask = '*') =>
|
||||||
|
('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
|
||||||
|
|
||||||
const max = (...arr) => Math.max(...[].concat(...arr));
|
const max = (...arr) => Math.max(...[].concat(...arr));
|
||||||
|
|
||||||
const median = arr => {
|
const median = arr => {
|
||||||
@ -325,6 +424,11 @@ const median = arr => {
|
|||||||
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const memoize = fn => {
|
||||||
|
const cache = Object.create(null);
|
||||||
|
return value => cache[value] || (cache[value] = fn(value));
|
||||||
|
};
|
||||||
|
|
||||||
const min = arr => Math.min(...[].concat(...arr));
|
const min = arr => Math.min(...[].concat(...arr));
|
||||||
|
|
||||||
const negate = func => (...args) => !func(...args);
|
const negate = func => (...args) => !func(...args);
|
||||||
@ -350,6 +454,15 @@ const onUserInputChange = callback => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const once = fn => {
|
||||||
|
let called = false;
|
||||||
|
return function(...args) {
|
||||||
|
if (called) return;
|
||||||
|
called = true;
|
||||||
|
return fn.apply(this, args);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const orderBy = (arr, props, orders) =>
|
const orderBy = (arr, props, orders) =>
|
||||||
[...arr].sort((a, b) =>
|
[...arr].sort((a, b) =>
|
||||||
props.reduce((acc, prop, i) => {
|
props.reduce((acc, prop, i) => {
|
||||||
@ -382,6 +495,14 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)
|
|||||||
|
|
||||||
const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]);
|
const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]);
|
||||||
|
|
||||||
|
const prettyBytes = (num, precision = 3, addSpace = true) => {
|
||||||
|
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
if (Math.abs(num) < 1) return num + (addSpace ? ' ' : '') + UNITS[0];
|
||||||
|
const exponent = Math.min(Math.floor(Math.log10(num < 0 ? -num : num) / 3), UNITS.length - 1);
|
||||||
|
const n = Number(((num < 0 ? -num : num) / 1000 ** exponent).toPrecision(precision));
|
||||||
|
return (num < 0 ? '-' : '') + n + (addSpace ? ' ' : '') + UNITS[exponent];
|
||||||
|
};
|
||||||
|
|
||||||
const primes = num => {
|
const primes = num => {
|
||||||
let arr = Array.from({ length: num - 1 }).map((x, i) => i + 2),
|
let arr = Array.from({ length: num - 1 }).map((x, i) => i + 2),
|
||||||
sqroot = Math.floor(Math.sqrt(num)),
|
sqroot = Math.floor(Math.sqrt(num)),
|
||||||
@ -449,6 +570,14 @@ const readFileLines = filename =>
|
|||||||
const redirect = (url, asLink = true) =>
|
const redirect = (url, asLink = true) =>
|
||||||
asLink ? (window.location.href = url) : window.location.replace(url);
|
asLink ? (window.location.href = url) : window.location.replace(url);
|
||||||
|
|
||||||
|
const reducedFilter = (data, keys, fn) =>
|
||||||
|
data.filter(fn).map(el =>
|
||||||
|
keys.reduce((acc, key) => {
|
||||||
|
acc[key] = el[key];
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
|
||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
Array.isArray(arr)
|
Array.isArray(arr)
|
||||||
? arr.filter(func).reduce((acc, val) => {
|
? arr.filter(func).reduce((acc, val) => {
|
||||||
@ -467,14 +596,41 @@ const reverseString = str =>
|
|||||||
.reverse()
|
.reverse()
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
|
||||||
|
|
||||||
const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
|
const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
|
||||||
|
|
||||||
|
const runAsync = fn => {
|
||||||
|
const blob = `
|
||||||
|
var fn = ${fn.toString()};
|
||||||
|
this.postMessage(fn());
|
||||||
|
`;
|
||||||
|
const worker = new Worker(
|
||||||
|
URL.createObjectURL(new Blob([blob]), {
|
||||||
|
type: 'application/javascript; charset=utf-8'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
worker.onmessage = ({ data }) => {
|
||||||
|
res(data), worker.terminate();
|
||||||
|
};
|
||||||
|
worker.onerror = err => {
|
||||||
|
rej(err), worker.terminate();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
|
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
|
||||||
|
|
||||||
const sample = arr => arr[Math.floor(Math.random() * arr.length)];
|
const sample = arr => arr[Math.floor(Math.random() * arr.length)];
|
||||||
|
|
||||||
|
const sampleSize = ([...arr], n = 1) => {
|
||||||
|
let m = arr.length;
|
||||||
|
while (m) {
|
||||||
|
const i = Math.floor(Math.random() * m--);
|
||||||
|
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||||
|
}
|
||||||
|
return arr.slice(0, n);
|
||||||
|
};
|
||||||
|
|
||||||
const scrollToTop = () => {
|
const scrollToTop = () => {
|
||||||
const c = document.documentElement.scrollTop || document.body.scrollTop;
|
const c = document.documentElement.scrollTop || document.body.scrollTop;
|
||||||
if (c > 0) {
|
if (c > 0) {
|
||||||
@ -512,14 +668,56 @@ const shuffle = ([...arr]) => {
|
|||||||
|
|
||||||
const similarity = (arr, values) => arr.filter(v => values.includes(v));
|
const similarity = (arr, values) => arr.filter(v => values.includes(v));
|
||||||
|
|
||||||
|
const size = value =>
|
||||||
|
Array.isArray(value)
|
||||||
|
? value.length
|
||||||
|
: value && typeof value === 'object'
|
||||||
|
? value.size || value.length || Object.keys(value).length
|
||||||
|
: typeof value === 'string' ? new Blob([value]).size : 0;
|
||||||
|
|
||||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
const solveRPN = rpn => {
|
||||||
|
const OPERATORS = {
|
||||||
|
'*': (a, b) => a * b,
|
||||||
|
'+': (a, b) => a + b,
|
||||||
|
'-': (a, b) => a - b,
|
||||||
|
'/': (a, b) => a / b,
|
||||||
|
'**': (a, b) => a ** b
|
||||||
|
};
|
||||||
|
const [stack, solve] = [
|
||||||
|
[],
|
||||||
|
rpn
|
||||||
|
.replace(/\^/g, '**')
|
||||||
|
.split(/\s+/g)
|
||||||
|
.filter(el => !/\s+/.test(el) && el !== '')
|
||||||
|
];
|
||||||
|
solve.forEach(symbol => {
|
||||||
|
if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {
|
||||||
|
stack.push(symbol);
|
||||||
|
} else if (Object.keys(OPERATORS).includes(symbol)) {
|
||||||
|
const [a, b] = [stack.pop(), stack.pop()];
|
||||||
|
stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
|
||||||
|
} else {
|
||||||
|
throw `${symbol} is not a recognized symbol`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (stack.length === 1) return stack.pop();
|
||||||
|
else throw `${rpn} is not a proper RPN. Please check it and try again`;
|
||||||
|
};
|
||||||
|
|
||||||
const sortCharactersInString = str =>
|
const sortCharactersInString = str =>
|
||||||
str
|
str
|
||||||
.split('')
|
.split('')
|
||||||
.sort((a, b) => a.localeCompare(b))
|
.sort((a, b) => a.localeCompare(b))
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
|
const sortedIndex = (arr, n) => {
|
||||||
|
const isDescending = arr[0] > arr[arr.length - 1];
|
||||||
|
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||||
|
return index === -1 ? arr.length : index;
|
||||||
|
};
|
||||||
|
|
||||||
const speechSynthesis = message => {
|
const speechSynthesis = message => {
|
||||||
const msg = new SpeechSynthesisUtterance(message);
|
const msg = new SpeechSynthesisUtterance(message);
|
||||||
msg.voice = window.speechSynthesis.getVoices()[0];
|
msg.voice = window.speechSynthesis.getVoices()[0];
|
||||||
@ -533,15 +731,19 @@ const spreadOver = fn => argsArr => fn(...argsArr);
|
|||||||
const standardDeviation = (arr, usePopulation = false) => {
|
const standardDeviation = (arr, usePopulation = false) => {
|
||||||
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
||||||
return Math.sqrt(
|
return Math.sqrt(
|
||||||
arr
|
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
|
||||||
.reduce((acc, val) => acc.concat(Math.pow(val - mean, 2)), [])
|
|
||||||
.reduce((acc, val) => acc + val, 0) /
|
|
||||||
(arr.length - (usePopulation ? 0 : 1))
|
(arr.length - (usePopulation ? 0 : 1))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
|
const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
|
||||||
|
|
||||||
|
const sumPower = (end, power = 2, start = 1) =>
|
||||||
|
Array(end + 1 - start)
|
||||||
|
.fill(0)
|
||||||
|
.map((x, i) => (i + start) ** power)
|
||||||
|
.reduce((a, b) => a + b, 0);
|
||||||
|
|
||||||
const symmetricDifference = (a, b) => {
|
const symmetricDifference = (a, b) => {
|
||||||
const sA = new Set(a),
|
const sA = new Set(a),
|
||||||
sB = new Set(b);
|
sB = new Set(b);
|
||||||
@ -582,8 +784,6 @@ const toEnglishDate = time => {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleClass = (el, className) => el.classList.toggle(className);
|
|
||||||
|
|
||||||
const toKebabCase = str =>
|
const toKebabCase = str =>
|
||||||
str &&
|
str &&
|
||||||
str
|
str
|
||||||
@ -591,8 +791,6 @@ const toKebabCase = str =>
|
|||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('-');
|
.join('-');
|
||||||
|
|
||||||
const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
|
||||||
|
|
||||||
const toOrdinalSuffix = num => {
|
const toOrdinalSuffix = num => {
|
||||||
const int = parseInt(num),
|
const int = parseInt(num),
|
||||||
digits = [int % 10, int % 100],
|
digits = [int % 10, int % 100],
|
||||||
@ -604,13 +802,16 @@ const toOrdinalSuffix = num => {
|
|||||||
: int + ordinals[3];
|
: int + ordinals[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
const toSnakeCase = str => {
|
const toSnakeCase = str =>
|
||||||
str &&
|
str &&
|
||||||
str
|
str
|
||||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('_');
|
.join('_');
|
||||||
};
|
|
||||||
|
const toggleClass = (el, className) => el.classList.toggle(className);
|
||||||
|
|
||||||
|
const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
||||||
|
|
||||||
const truncateString = (str, num) =>
|
const truncateString = (str, num) =>
|
||||||
str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
|
str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
|
||||||
@ -632,16 +833,7 @@ const unescapeHTML = str =>
|
|||||||
|
|
||||||
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
||||||
|
|
||||||
const UUIDGeneratorBrowser = () =>
|
const untildify = str => str.replace(/^~($|\/|\\)/, `${typeof require !== "undefined" && require('os').homedir()}$1`);
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
||||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
|
||||||
);
|
|
||||||
|
|
||||||
const crypto$1 = typeof require !== "undefined" && require('crypto');
|
|
||||||
const UUIDGeneratorNode = () =>
|
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
||||||
(c ^ (crypto$1.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
|
||||||
);
|
|
||||||
|
|
||||||
const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
|
const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
|
||||||
|
|
||||||
@ -649,6 +841,9 @@ const without = (arr, ...args) => arr.filter(v => !args.includes(v));
|
|||||||
|
|
||||||
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
||||||
|
|
||||||
|
const yesNo = (val, def = false) =>
|
||||||
|
/^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
|
||||||
|
|
||||||
const zip = (...arrays) => {
|
const zip = (...arrays) => {
|
||||||
const maxLength = Math.max(...arrays.map(x => x.length));
|
const maxLength = Math.max(...arrays.map(x => x.length));
|
||||||
return Array.from({ length: maxLength }).map((_, i) => {
|
return Array.from({ length: maxLength }).map((_, i) => {
|
||||||
@ -659,6 +854,6 @@ const zip = (...arrays) => {
|
|||||||
const zipObject = (props, values) =>
|
const zipObject = (props, values) =>
|
||||||
props.reduce((obj, prop, index) => (obj[prop] = values[index], obj), {});
|
props.reduce((obj, prop, index) => (obj[prop] = values[index], obj), {});
|
||||||
|
|
||||||
var imports = {anagrams,arrayToHtmlList,average,bottomVisible,byteSize,call,capitalize,capitalizeEveryWord,chainAsync,chunk,clampNumber,cleanObj,coalesce,coalesceFactory,collatz,collectInto,compact,compose,countOccurrences,countVowels,currentURL,curry,deepFlatten,detectDeviceType,difference,differenceWith,digitize,distance,distinctValuesOfArray,dropElements,dropRight,elementIsVisibleInViewport,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,fibonacciCountUntilNum,fibonacciUntilNum,filterNonUnique,flatten,flattenDepth,flip,fromCamelCase,functionName,gcd,getDaysDiffBetweenDates,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,head,hexToRGB,hide,httpsRedirect,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithValues,inRange,intersection,isArmstrongNumber,isArray,isBoolean,isDivisible,isEven,isFunction,isNumber,isPrime,isString,isSymbol,JSONToDate,JSONToFile,last,lcm,lowercaseKeys,mapObject,max,median,min,negate,nthElement,objectFromPairs,objectToPairs,onUserInputChange,orderBy,palindrome,percentile,pick,pipeFunctions,powerset,primes,promisify,pull,pullAtIndex,pullAtValue,quickSort,randomHexColorCode,randomIntegerInRange,randomNumberInRange,readFileLines,redirect,remove,repeatString,reverseString,RGBToHex,round,runPromisesInSeries,sample,scrollToTop,sdbm,select,setStyle,shallowClone,show,shuffle,similarity,sleep,sortCharactersInString,speechSynthesis,splitLines,spreadOver,standardDeviation,sum,symmetricDifference,tail,take,takeRight,timeTaken,toCamelCase,toDecimalMark,toEnglishDate,toggleClass,toKebabCase,tomorrow,toOrdinalSuffix,toSnakeCase,truncateString,truthCheckCollection,unescapeHTML,union,UUIDGeneratorBrowser,UUIDGeneratorNode,validateNumber,without,words,zip,zipObject,}
|
var imports = {JSONToDate,JSONToFile,RGBToHex,UUIDGeneratorBrowser,UUIDGeneratorNode,anagrams,arrayToHtmlList,average,bottomVisible,byteSize,call,capitalize,capitalizeEveryWord,chainAsync,chunk,clampNumber,cleanObj,cloneRegExp,coalesce,coalesceFactory,collatz,collectInto,compact,compose,copyToClipboard,countOccurrences,countVowels,currentURL,curry,deepFlatten,defer,detectDeviceType,difference,differenceWith,digitize,distance,distinctValuesOfArray,dropElements,dropRight,elementIsVisibleInViewport,elo,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,fibonacciCountUntilNum,fibonacciUntilNum,filterNonUnique,flatten,flattenDepth,flip,fromCamelCase,functionName,gcd,getDaysDiffBetweenDates,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,head,hexToRGB,hide,httpsRedirect,inRange,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithValues,intersection,invertKeyValues,isAbsoluteURL,isArmstrongNumber,isArray,isArrayLike,isBoolean,isDivisible,isEven,isFunction,isNull,isNumber,isPrime,isPrimitive,isPromiseLike,isSorted,isString,isSymbol,isTravisCI,isValidJSON,join,last,lcm,lowercaseKeys,mapObject,mask,max,median,memoize,min,negate,nthElement,objectFromPairs,objectToPairs,onUserInputChange,once,orderBy,palindrome,percentile,pick,pipeFunctions,powerset,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,quickSort,randomHexColorCode,randomIntegerInRange,randomNumberInRange,readFileLines,redirect,reducedFilter,remove,repeatString,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,select,setStyle,shallowClone,show,shuffle,similarity,size,sleep,solveRPN,sortCharactersInString,sortedIndex,speechSynthesis,splitLines,spreadOver,standardDeviation,sum,sumPower,symmetricDifference,tail,take,takeRight,timeTaken,toCamelCase,toDecimalMark,toEnglishDate,toKebabCase,toOrdinalSuffix,toSnakeCase,toggleClass,tomorrow,truncateString,truthCheckCollection,unescapeHTML,union,untildify,validateNumber,without,words,yesNo,zip,zipObject,}
|
||||||
|
|
||||||
export default imports;
|
export default imports;
|
||||||
|
|||||||
273
dist/_30s.js
vendored
273
dist/_30s.js
vendored
@ -4,6 +4,28 @@
|
|||||||
(global._30s = factory());
|
(global._30s = factory());
|
||||||
}(this, (function () { 'use strict';
|
}(this, (function () { 'use strict';
|
||||||
|
|
||||||
|
const JSONToDate = arr => {
|
||||||
|
const dt = new Date(parseInt(arr.toString().substr(6)));
|
||||||
|
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fs = typeof require !== "undefined" && require('fs');
|
||||||
|
const JSONToFile = (obj, filename) =>
|
||||||
|
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
||||||
|
|
||||||
|
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
||||||
|
|
||||||
|
const UUIDGeneratorBrowser = () =>
|
||||||
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
|
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
||||||
|
);
|
||||||
|
|
||||||
|
const crypto$1 = typeof require !== "undefined" && require('crypto');
|
||||||
|
const UUIDGeneratorNode = () =>
|
||||||
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
|
(c ^ (crypto$1.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
||||||
|
);
|
||||||
|
|
||||||
const anagrams = str => {
|
const anagrams = str => {
|
||||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||||
return str
|
return str
|
||||||
@ -60,6 +82,8 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
|||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||||
|
|
||||||
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
||||||
|
|
||||||
const coalesceFactory = valid => (...args) => args.find(valid);
|
const coalesceFactory = valid => (...args) => args.find(valid);
|
||||||
@ -72,6 +96,24 @@ const compact = arr => arr.filter(Boolean);
|
|||||||
|
|
||||||
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
||||||
|
|
||||||
|
const copyToClipboard = str => {
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = str;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
document.body.appendChild(el);
|
||||||
|
const selected =
|
||||||
|
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
if (selected) {
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
document.getSelection().addRange(selected);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const countOccurrences = (arr, value) => arr.reduce((a, v) => (v === value ? a + 1 : a + 0), 0);
|
const countOccurrences = (arr, value) => arr.reduce((a, v) => (v === value ? a + 1 : a + 0), 0);
|
||||||
|
|
||||||
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
||||||
@ -83,6 +125,8 @@ const curry = (fn, arity = fn.length, ...args) =>
|
|||||||
|
|
||||||
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||||
|
|
||||||
|
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
|
|
||||||
const detectDeviceType = () =>
|
const detectDeviceType = () =>
|
||||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||||
? 'Mobile'
|
? 'Mobile'
|
||||||
@ -117,6 +161,12 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
|||||||
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const elo = ([a, b], kFactor = 32) => {
|
||||||
|
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||||
|
const newRating = (rating, i) => rating + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
||||||
|
return [newRating(a, 1), newRating(b, 0)];
|
||||||
|
};
|
||||||
|
|
||||||
const escapeHTML = str =>
|
const escapeHTML = str =>
|
||||||
str.replace(
|
str.replace(
|
||||||
/[&<>'"]/g,
|
/[&<>'"]/g,
|
||||||
@ -219,6 +269,9 @@ const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) |
|
|||||||
|
|
||||||
const hasClass = (el, className) => el.classList.contains(className);
|
const hasClass = (el, className) => el.classList.contains(className);
|
||||||
|
|
||||||
|
const hasFlags = (...flags) =>
|
||||||
|
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
||||||
|
|
||||||
const head = arr => arr[0];
|
const head = arr => arr[0];
|
||||||
|
|
||||||
const hexToRGB = hex => {
|
const hexToRGB = hex => {
|
||||||
@ -247,6 +300,11 @@ const httpsRedirect = () => {
|
|||||||
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const inRange = (n, start, end = null) => {
|
||||||
|
if (end && start > end) end = [start, (start = end)][0];
|
||||||
|
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
||||||
|
};
|
||||||
|
|
||||||
const initial = arr => arr.slice(0, -1);
|
const initial = arr => arr.slice(0, -1);
|
||||||
|
|
||||||
const initialize2DArray = (w, h, val = null) =>
|
const initialize2DArray = (w, h, val = null) =>
|
||||||
@ -259,23 +317,34 @@ const initializeArrayWithRange = (end, start = 0) =>
|
|||||||
|
|
||||||
const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
||||||
|
|
||||||
const inRange = (n, start, end = null) => {
|
|
||||||
if (end && start > end) end = [start, (start = end)][0];
|
|
||||||
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
|
||||||
};
|
|
||||||
|
|
||||||
const intersection = (a, b) => {
|
const intersection = (a, b) => {
|
||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => s.has(x));
|
return a.filter(x => s.has(x));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const invertKeyValues = obj =>
|
||||||
|
Object.keys(obj).reduce((acc, key) => {
|
||||||
|
acc[obj[key]] = key;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||||
|
|
||||||
const isArmstrongNumber = digits =>
|
const isArmstrongNumber = digits =>
|
||||||
(arr => arr.reduce((a, d) => a + Math.pow(parseInt(d), arr.length), 0) == digits)(
|
(arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(
|
||||||
(digits + '').split('')
|
(digits + '').split('')
|
||||||
);
|
);
|
||||||
|
|
||||||
const isArray = val => !!val && Array.isArray(val);
|
const isArray = val => !!val && Array.isArray(val);
|
||||||
|
|
||||||
|
const isArrayLike = val => {
|
||||||
|
try {
|
||||||
|
return [...val], true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const isBoolean = val => typeof val === 'boolean';
|
const isBoolean = val => typeof val === 'boolean';
|
||||||
|
|
||||||
const isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
const isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
||||||
@ -284,26 +353,53 @@ const isEven = num => num % 2 === 0;
|
|||||||
|
|
||||||
const isFunction = val => val && typeof val === 'function';
|
const isFunction = val => val && typeof val === 'function';
|
||||||
|
|
||||||
|
const isNull = val => val === null;
|
||||||
|
|
||||||
const isNumber = val => typeof val === 'number';
|
const isNumber = val => typeof val === 'number';
|
||||||
|
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
const boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
|
for (var i = 2; i <= boundary; i++) if (num % i == 0) return false;
|
||||||
return num >= 2;
|
return num >= 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
|
||||||
|
|
||||||
|
const isPromiseLike = obj =>
|
||||||
|
obj !== null &&
|
||||||
|
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||||
|
typeof obj.then === 'function';
|
||||||
|
|
||||||
|
const isSorted = arr => {
|
||||||
|
const direction = arr[0] > arr[1] ? -1 : 1;
|
||||||
|
for (let [i, val] of arr.entries())
|
||||||
|
if (i === arr.length - 1) return direction;
|
||||||
|
else if ((val - arr[i + 1]) * direction > 0) return 0;
|
||||||
|
};
|
||||||
|
|
||||||
const isString = val => typeof val === 'string';
|
const isString = val => typeof val === 'string';
|
||||||
|
|
||||||
const isSymbol = val => typeof val === 'symbol';
|
const isSymbol = val => typeof val === 'symbol';
|
||||||
|
|
||||||
const JSONToDate = arr => {
|
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
||||||
const dt = new Date(parseInt(arr.toString().substr(6)));
|
|
||||||
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
const isValidJSON = obj => {
|
||||||
|
try {
|
||||||
|
JSON.parse(obj);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fs = typeof require !== "undefined" && require('fs');
|
const join = (arr, separator = ',', end = separator) =>
|
||||||
const JSONToFile = (obj, filename) =>
|
arr.reduce(
|
||||||
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
(acc, val, i) =>
|
||||||
|
i == arr.length - 2
|
||||||
|
? acc + val + end
|
||||||
|
: i == arr.length - 1 ? acc + val : acc + val + separator,
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
const last = arr => arr[arr.length - 1];
|
const last = arr => arr[arr.length - 1];
|
||||||
|
|
||||||
@ -323,6 +419,9 @@ const mapObject = (arr, fn) =>
|
|||||||
(a => (
|
(a => (
|
||||||
a = [arr, arr.map(fn)], a[0].reduce((acc, val, ind) => (acc[val] = a[1][ind], acc), {})))();
|
a = [arr, arr.map(fn)], a[0].reduce((acc, val, ind) => (acc[val] = a[1][ind], acc), {})))();
|
||||||
|
|
||||||
|
const mask = (cc, num = 4, mask = '*') =>
|
||||||
|
('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
|
||||||
|
|
||||||
const max = (...arr) => Math.max(...[].concat(...arr));
|
const max = (...arr) => Math.max(...[].concat(...arr));
|
||||||
|
|
||||||
const median = arr => {
|
const median = arr => {
|
||||||
@ -331,6 +430,11 @@ const median = arr => {
|
|||||||
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const memoize = fn => {
|
||||||
|
const cache = Object.create(null);
|
||||||
|
return value => cache[value] || (cache[value] = fn(value));
|
||||||
|
};
|
||||||
|
|
||||||
const min = arr => Math.min(...[].concat(...arr));
|
const min = arr => Math.min(...[].concat(...arr));
|
||||||
|
|
||||||
const negate = func => (...args) => !func(...args);
|
const negate = func => (...args) => !func(...args);
|
||||||
@ -356,6 +460,15 @@ const onUserInputChange = callback => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const once = fn => {
|
||||||
|
let called = false;
|
||||||
|
return function(...args) {
|
||||||
|
if (called) return;
|
||||||
|
called = true;
|
||||||
|
return fn.apply(this, args);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const orderBy = (arr, props, orders) =>
|
const orderBy = (arr, props, orders) =>
|
||||||
[...arr].sort((a, b) =>
|
[...arr].sort((a, b) =>
|
||||||
props.reduce((acc, prop, i) => {
|
props.reduce((acc, prop, i) => {
|
||||||
@ -388,6 +501,14 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)
|
|||||||
|
|
||||||
const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]);
|
const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]);
|
||||||
|
|
||||||
|
const prettyBytes = (num, precision = 3, addSpace = true) => {
|
||||||
|
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
if (Math.abs(num) < 1) return num + (addSpace ? ' ' : '') + UNITS[0];
|
||||||
|
const exponent = Math.min(Math.floor(Math.log10(num < 0 ? -num : num) / 3), UNITS.length - 1);
|
||||||
|
const n = Number(((num < 0 ? -num : num) / 1000 ** exponent).toPrecision(precision));
|
||||||
|
return (num < 0 ? '-' : '') + n + (addSpace ? ' ' : '') + UNITS[exponent];
|
||||||
|
};
|
||||||
|
|
||||||
const primes = num => {
|
const primes = num => {
|
||||||
let arr = Array.from({ length: num - 1 }).map((x, i) => i + 2),
|
let arr = Array.from({ length: num - 1 }).map((x, i) => i + 2),
|
||||||
sqroot = Math.floor(Math.sqrt(num)),
|
sqroot = Math.floor(Math.sqrt(num)),
|
||||||
@ -455,6 +576,14 @@ const readFileLines = filename =>
|
|||||||
const redirect = (url, asLink = true) =>
|
const redirect = (url, asLink = true) =>
|
||||||
asLink ? (window.location.href = url) : window.location.replace(url);
|
asLink ? (window.location.href = url) : window.location.replace(url);
|
||||||
|
|
||||||
|
const reducedFilter = (data, keys, fn) =>
|
||||||
|
data.filter(fn).map(el =>
|
||||||
|
keys.reduce((acc, key) => {
|
||||||
|
acc[key] = el[key];
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
|
||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
Array.isArray(arr)
|
Array.isArray(arr)
|
||||||
? arr.filter(func).reduce((acc, val) => {
|
? arr.filter(func).reduce((acc, val) => {
|
||||||
@ -473,14 +602,41 @@ const reverseString = str =>
|
|||||||
.reverse()
|
.reverse()
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
|
||||||
|
|
||||||
const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
|
const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
|
||||||
|
|
||||||
|
const runAsync = fn => {
|
||||||
|
const blob = `
|
||||||
|
var fn = ${fn.toString()};
|
||||||
|
this.postMessage(fn());
|
||||||
|
`;
|
||||||
|
const worker = new Worker(
|
||||||
|
URL.createObjectURL(new Blob([blob]), {
|
||||||
|
type: 'application/javascript; charset=utf-8'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
worker.onmessage = ({ data }) => {
|
||||||
|
res(data), worker.terminate();
|
||||||
|
};
|
||||||
|
worker.onerror = err => {
|
||||||
|
rej(err), worker.terminate();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
|
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
|
||||||
|
|
||||||
const sample = arr => arr[Math.floor(Math.random() * arr.length)];
|
const sample = arr => arr[Math.floor(Math.random() * arr.length)];
|
||||||
|
|
||||||
|
const sampleSize = ([...arr], n = 1) => {
|
||||||
|
let m = arr.length;
|
||||||
|
while (m) {
|
||||||
|
const i = Math.floor(Math.random() * m--);
|
||||||
|
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||||
|
}
|
||||||
|
return arr.slice(0, n);
|
||||||
|
};
|
||||||
|
|
||||||
const scrollToTop = () => {
|
const scrollToTop = () => {
|
||||||
const c = document.documentElement.scrollTop || document.body.scrollTop;
|
const c = document.documentElement.scrollTop || document.body.scrollTop;
|
||||||
if (c > 0) {
|
if (c > 0) {
|
||||||
@ -518,14 +674,56 @@ const shuffle = ([...arr]) => {
|
|||||||
|
|
||||||
const similarity = (arr, values) => arr.filter(v => values.includes(v));
|
const similarity = (arr, values) => arr.filter(v => values.includes(v));
|
||||||
|
|
||||||
|
const size = value =>
|
||||||
|
Array.isArray(value)
|
||||||
|
? value.length
|
||||||
|
: value && typeof value === 'object'
|
||||||
|
? value.size || value.length || Object.keys(value).length
|
||||||
|
: typeof value === 'string' ? new Blob([value]).size : 0;
|
||||||
|
|
||||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
const solveRPN = rpn => {
|
||||||
|
const OPERATORS = {
|
||||||
|
'*': (a, b) => a * b,
|
||||||
|
'+': (a, b) => a + b,
|
||||||
|
'-': (a, b) => a - b,
|
||||||
|
'/': (a, b) => a / b,
|
||||||
|
'**': (a, b) => a ** b
|
||||||
|
};
|
||||||
|
const [stack, solve] = [
|
||||||
|
[],
|
||||||
|
rpn
|
||||||
|
.replace(/\^/g, '**')
|
||||||
|
.split(/\s+/g)
|
||||||
|
.filter(el => !/\s+/.test(el) && el !== '')
|
||||||
|
];
|
||||||
|
solve.forEach(symbol => {
|
||||||
|
if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {
|
||||||
|
stack.push(symbol);
|
||||||
|
} else if (Object.keys(OPERATORS).includes(symbol)) {
|
||||||
|
const [a, b] = [stack.pop(), stack.pop()];
|
||||||
|
stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
|
||||||
|
} else {
|
||||||
|
throw `${symbol} is not a recognized symbol`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (stack.length === 1) return stack.pop();
|
||||||
|
else throw `${rpn} is not a proper RPN. Please check it and try again`;
|
||||||
|
};
|
||||||
|
|
||||||
const sortCharactersInString = str =>
|
const sortCharactersInString = str =>
|
||||||
str
|
str
|
||||||
.split('')
|
.split('')
|
||||||
.sort((a, b) => a.localeCompare(b))
|
.sort((a, b) => a.localeCompare(b))
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
|
const sortedIndex = (arr, n) => {
|
||||||
|
const isDescending = arr[0] > arr[arr.length - 1];
|
||||||
|
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||||
|
return index === -1 ? arr.length : index;
|
||||||
|
};
|
||||||
|
|
||||||
const speechSynthesis = message => {
|
const speechSynthesis = message => {
|
||||||
const msg = new SpeechSynthesisUtterance(message);
|
const msg = new SpeechSynthesisUtterance(message);
|
||||||
msg.voice = window.speechSynthesis.getVoices()[0];
|
msg.voice = window.speechSynthesis.getVoices()[0];
|
||||||
@ -539,15 +737,19 @@ const spreadOver = fn => argsArr => fn(...argsArr);
|
|||||||
const standardDeviation = (arr, usePopulation = false) => {
|
const standardDeviation = (arr, usePopulation = false) => {
|
||||||
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
||||||
return Math.sqrt(
|
return Math.sqrt(
|
||||||
arr
|
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
|
||||||
.reduce((acc, val) => acc.concat(Math.pow(val - mean, 2)), [])
|
|
||||||
.reduce((acc, val) => acc + val, 0) /
|
|
||||||
(arr.length - (usePopulation ? 0 : 1))
|
(arr.length - (usePopulation ? 0 : 1))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
|
const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
|
||||||
|
|
||||||
|
const sumPower = (end, power = 2, start = 1) =>
|
||||||
|
Array(end + 1 - start)
|
||||||
|
.fill(0)
|
||||||
|
.map((x, i) => (i + start) ** power)
|
||||||
|
.reduce((a, b) => a + b, 0);
|
||||||
|
|
||||||
const symmetricDifference = (a, b) => {
|
const symmetricDifference = (a, b) => {
|
||||||
const sA = new Set(a),
|
const sA = new Set(a),
|
||||||
sB = new Set(b);
|
sB = new Set(b);
|
||||||
@ -588,8 +790,6 @@ const toEnglishDate = time => {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleClass = (el, className) => el.classList.toggle(className);
|
|
||||||
|
|
||||||
const toKebabCase = str =>
|
const toKebabCase = str =>
|
||||||
str &&
|
str &&
|
||||||
str
|
str
|
||||||
@ -597,8 +797,6 @@ const toKebabCase = str =>
|
|||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('-');
|
.join('-');
|
||||||
|
|
||||||
const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
|
||||||
|
|
||||||
const toOrdinalSuffix = num => {
|
const toOrdinalSuffix = num => {
|
||||||
const int = parseInt(num),
|
const int = parseInt(num),
|
||||||
digits = [int % 10, int % 100],
|
digits = [int % 10, int % 100],
|
||||||
@ -610,13 +808,16 @@ const toOrdinalSuffix = num => {
|
|||||||
: int + ordinals[3];
|
: int + ordinals[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
const toSnakeCase = str => {
|
const toSnakeCase = str =>
|
||||||
str &&
|
str &&
|
||||||
str
|
str
|
||||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('_');
|
.join('_');
|
||||||
};
|
|
||||||
|
const toggleClass = (el, className) => el.classList.toggle(className);
|
||||||
|
|
||||||
|
const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
||||||
|
|
||||||
const truncateString = (str, num) =>
|
const truncateString = (str, num) =>
|
||||||
str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
|
str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
|
||||||
@ -638,16 +839,7 @@ const unescapeHTML = str =>
|
|||||||
|
|
||||||
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
||||||
|
|
||||||
const UUIDGeneratorBrowser = () =>
|
const untildify = str => str.replace(/^~($|\/|\\)/, `${typeof require !== "undefined" && require('os').homedir()}$1`);
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
||||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
|
||||||
);
|
|
||||||
|
|
||||||
const crypto$1 = typeof require !== "undefined" && require('crypto');
|
|
||||||
const UUIDGeneratorNode = () =>
|
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
||||||
(c ^ (crypto$1.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
|
||||||
);
|
|
||||||
|
|
||||||
const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
|
const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
|
||||||
|
|
||||||
@ -655,6 +847,9 @@ const without = (arr, ...args) => arr.filter(v => !args.includes(v));
|
|||||||
|
|
||||||
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
||||||
|
|
||||||
|
const yesNo = (val, def = false) =>
|
||||||
|
/^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
|
||||||
|
|
||||||
const zip = (...arrays) => {
|
const zip = (...arrays) => {
|
||||||
const maxLength = Math.max(...arrays.map(x => x.length));
|
const maxLength = Math.max(...arrays.map(x => x.length));
|
||||||
return Array.from({ length: maxLength }).map((_, i) => {
|
return Array.from({ length: maxLength }).map((_, i) => {
|
||||||
@ -665,7 +860,7 @@ const zip = (...arrays) => {
|
|||||||
const zipObject = (props, values) =>
|
const zipObject = (props, values) =>
|
||||||
props.reduce((obj, prop, index) => (obj[prop] = values[index], obj), {});
|
props.reduce((obj, prop, index) => (obj[prop] = values[index], obj), {});
|
||||||
|
|
||||||
var imports = {anagrams,arrayToHtmlList,average,bottomVisible,byteSize,call,capitalize,capitalizeEveryWord,chainAsync,chunk,clampNumber,cleanObj,coalesce,coalesceFactory,collatz,collectInto,compact,compose,countOccurrences,countVowels,currentURL,curry,deepFlatten,detectDeviceType,difference,differenceWith,digitize,distance,distinctValuesOfArray,dropElements,dropRight,elementIsVisibleInViewport,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,fibonacciCountUntilNum,fibonacciUntilNum,filterNonUnique,flatten,flattenDepth,flip,fromCamelCase,functionName,gcd,getDaysDiffBetweenDates,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,head,hexToRGB,hide,httpsRedirect,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithValues,inRange,intersection,isArmstrongNumber,isArray,isBoolean,isDivisible,isEven,isFunction,isNumber,isPrime,isString,isSymbol,JSONToDate,JSONToFile,last,lcm,lowercaseKeys,mapObject,max,median,min,negate,nthElement,objectFromPairs,objectToPairs,onUserInputChange,orderBy,palindrome,percentile,pick,pipeFunctions,powerset,primes,promisify,pull,pullAtIndex,pullAtValue,quickSort,randomHexColorCode,randomIntegerInRange,randomNumberInRange,readFileLines,redirect,remove,repeatString,reverseString,RGBToHex,round,runPromisesInSeries,sample,scrollToTop,sdbm,select,setStyle,shallowClone,show,shuffle,similarity,sleep,sortCharactersInString,speechSynthesis,splitLines,spreadOver,standardDeviation,sum,symmetricDifference,tail,take,takeRight,timeTaken,toCamelCase,toDecimalMark,toEnglishDate,toggleClass,toKebabCase,tomorrow,toOrdinalSuffix,toSnakeCase,truncateString,truthCheckCollection,unescapeHTML,union,UUIDGeneratorBrowser,UUIDGeneratorNode,validateNumber,without,words,zip,zipObject,}
|
var imports = {JSONToDate,JSONToFile,RGBToHex,UUIDGeneratorBrowser,UUIDGeneratorNode,anagrams,arrayToHtmlList,average,bottomVisible,byteSize,call,capitalize,capitalizeEveryWord,chainAsync,chunk,clampNumber,cleanObj,cloneRegExp,coalesce,coalesceFactory,collatz,collectInto,compact,compose,copyToClipboard,countOccurrences,countVowels,currentURL,curry,deepFlatten,defer,detectDeviceType,difference,differenceWith,digitize,distance,distinctValuesOfArray,dropElements,dropRight,elementIsVisibleInViewport,elo,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,fibonacciCountUntilNum,fibonacciUntilNum,filterNonUnique,flatten,flattenDepth,flip,fromCamelCase,functionName,gcd,getDaysDiffBetweenDates,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,head,hexToRGB,hide,httpsRedirect,inRange,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithValues,intersection,invertKeyValues,isAbsoluteURL,isArmstrongNumber,isArray,isArrayLike,isBoolean,isDivisible,isEven,isFunction,isNull,isNumber,isPrime,isPrimitive,isPromiseLike,isSorted,isString,isSymbol,isTravisCI,isValidJSON,join,last,lcm,lowercaseKeys,mapObject,mask,max,median,memoize,min,negate,nthElement,objectFromPairs,objectToPairs,onUserInputChange,once,orderBy,palindrome,percentile,pick,pipeFunctions,powerset,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,quickSort,randomHexColorCode,randomIntegerInRange,randomNumberInRange,readFileLines,redirect,reducedFilter,remove,repeatString,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,select,setStyle,shallowClone,show,shuffle,similarity,size,sleep,solveRPN,sortCharactersInString,sortedIndex,speechSynthesis,splitLines,spreadOver,standardDeviation,sum,sumPower,symmetricDifference,tail,take,takeRight,timeTaken,toCamelCase,toDecimalMark,toEnglishDate,toKebabCase,toOrdinalSuffix,toSnakeCase,toggleClass,tomorrow,truncateString,truthCheckCollection,unescapeHTML,union,untildify,validateNumber,without,words,yesNo,zip,zipObject,}
|
||||||
|
|
||||||
return imports;
|
return imports;
|
||||||
|
|
||||||
|
|||||||
5
dist/_30s.min.js
vendored
5
dist/_30s.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user