Travis build: 1172 [cron]

This commit is contained in:
30secondsofcode
2019-05-27 15:50:49 +00:00
parent 0dca4d0374
commit fe606cc4d9
7 changed files with 480 additions and 438 deletions

478
dist/_30s.es5.js vendored
View File

@ -118,6 +118,54 @@
var crypto = typeof require !== "undefined" && require('crypto'); var crypto = typeof require !== "undefined" && require('crypto');
var CSVToArray = function CSVToArray(data) {
var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
var omitFirstRow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return data.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0).split('\n').map(function (v) {
return v.split(delimiter);
});
};
var CSVToJSON = function CSVToJSON(data) {
var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
var titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data.slice(data.indexOf('\n') + 1).split('\n').map(function (v) {
var values = v.split(delimiter);
return titles.reduce(function (obj, title, index) {
return obj[title] = values[index], obj;
}, {});
});
};
var JSONToFile = function JSONToFile(obj, filename) {
return fs.writeFile("".concat(filename, ".json"), JSON.stringify(obj, null, 2));
};
var JSONtoCSV = function JSONtoCSV(arr, columns) {
var delimiter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ',';
return [columns.join(delimiter)].concat(_toConsumableArray(arr.map(function (obj) {
return columns.reduce(function (acc, key) {
return "".concat(acc).concat(!acc.length ? '' : delimiter, "\"").concat(!obj[key] ? '' : obj[key], "\"");
}, '');
}))).join('\n');
};
var RGBToHex = function RGBToHex(r, g, b) {
return ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
};
var URLJoin = function URLJoin() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return args.join('/').replace(/[\/]+/g, '/').replace(/^(.+):\//, '$1://').replace(/^file:/, 'file:/').replace(/\/(\?|&|#[^!])/g, '$1').replace(/\?/g, '&').replace('&', '?');
};
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 UUIDGeneratorNode = function UUIDGeneratorNode() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
return (c ^ crypto.randomBytes(1)[0] & 15 >> c / 4).toString(16);
});
};
var all = function all(arr) { var all = function all(arr) {
var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Boolean; var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Boolean;
return arr.every(fn); return arr.every(fn);
@ -152,8 +200,8 @@
}; };
var ary = function ary(fn, n) { var ary = function ary(fn, n) {
return function () { return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key] = arguments[_key]; args[_key2] = arguments[_key2];
} }
return fn.apply(void 0, _toConsumableArray(args.slice(0, n))); return fn.apply(void 0, _toConsumableArray(args.slice(0, n)));
@ -164,8 +212,8 @@
}; };
var attempt = function attempt(fn) { var attempt = function attempt(fn) {
try { try {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key2 - 1] = arguments[_key2]; args[_key3 - 1] = arguments[_key3];
} }
return fn.apply(void 0, args); return fn.apply(void 0, args);
@ -174,8 +222,8 @@
} }
}; };
var average = function average() { var average = function average() {
for (var _len3 = arguments.length, nums = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { for (var _len4 = arguments.length, nums = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
nums[_key3] = arguments[_key3]; nums[_key4] = arguments[_key4];
} }
return nums.reduce(function (acc, val) { return nums.reduce(function (acc, val) {
@ -200,21 +248,21 @@
}, [[], []]); }, [[], []]);
}; };
var bind = function bind(fn, context) { var bind = function bind(fn, context) {
for (var _len4 = arguments.length, boundArgs = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) { for (var _len5 = arguments.length, boundArgs = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
boundArgs[_key4 - 2] = arguments[_key4]; boundArgs[_key5 - 2] = arguments[_key5];
} }
return function () { return function () {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key5] = arguments[_key5]; args[_key6] = arguments[_key6];
} }
return fn.apply(context, boundArgs.concat(args)); return fn.apply(context, boundArgs.concat(args));
}; };
}; };
var bindAll = function bindAll(obj) { var bindAll = function bindAll(obj) {
for (var _len6 = arguments.length, fns = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { for (var _len7 = arguments.length, fns = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
fns[_key6 - 1] = arguments[_key6]; fns[_key7 - 1] = arguments[_key7];
} }
return fns.forEach(function (fn) { return fns.forEach(function (fn) {
@ -224,13 +272,13 @@
}); });
}; };
var bindKey = function bindKey(context, fn) { var bindKey = function bindKey(context, fn) {
for (var _len7 = arguments.length, boundArgs = new Array(_len7 > 2 ? _len7 - 2 : 0), _key7 = 2; _key7 < _len7; _key7++) { for (var _len8 = arguments.length, boundArgs = new Array(_len8 > 2 ? _len8 - 2 : 0), _key8 = 2; _key8 < _len8; _key8++) {
boundArgs[_key7 - 2] = arguments[_key7]; boundArgs[_key8 - 2] = arguments[_key8];
} }
return function () { return function () {
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) { for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
args[_key8] = arguments[_key8]; args[_key9] = arguments[_key9];
} }
return context[fn].apply(context, boundArgs.concat(args)); return context[fn].apply(context, boundArgs.concat(args));
@ -260,8 +308,8 @@
return new Blob([str]).size; return new Blob([str]).size;
}; };
var call = function call(key) { var call = function call(key) {
for (var _len9 = arguments.length, args = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) { for (var _len10 = arguments.length, args = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
args[_key9 - 1] = arguments[_key9]; args[_key10 - 1] = arguments[_key10];
} }
return function (context) { return function (context) {
@ -314,8 +362,8 @@
return new RegExp(regExp.source, regExp.flags); return new RegExp(regExp.source, regExp.flags);
}; };
var coalesce = function coalesce() { var coalesce = function coalesce() {
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) { for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
args[_key10] = arguments[_key10]; args[_key11] = arguments[_key11];
} }
return args.find(function (_) { return args.find(function (_) {
@ -324,8 +372,8 @@
}; };
var coalesceFactory = function coalesceFactory(valid) { var coalesceFactory = function coalesceFactory(valid) {
return function () { return function () {
for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) { for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
args[_key11] = arguments[_key11]; args[_key12] = arguments[_key12];
} }
return args.find(valid); return args.find(valid);
@ -333,16 +381,16 @@
}; };
var collectInto = function collectInto(fn) { var collectInto = function collectInto(fn) {
return function () { return function () {
for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) { for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
args[_key12] = arguments[_key12]; args[_key13] = arguments[_key13];
} }
return fn(args); return fn(args);
}; };
}; };
var colorize = function colorize() { var colorize = function colorize() {
for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) { for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
args[_key13] = arguments[_key13]; args[_key14] = arguments[_key14];
} }
return { return {
@ -371,8 +419,8 @@
return str.replace(/\s{2,}/g, ' '); return str.replace(/\s{2,}/g, ' ');
}; };
var compose = function compose() { var compose = function compose() {
for (var _len14 = arguments.length, fns = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) { for (var _len15 = arguments.length, fns = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
fns[_key14] = arguments[_key14]; fns[_key15] = arguments[_key15];
} }
return fns.reduce(function (f, g) { return fns.reduce(function (f, g) {
@ -382,8 +430,8 @@
}); });
}; };
var composeRight = function composeRight() { var composeRight = function composeRight() {
for (var _len15 = arguments.length, fns = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) { for (var _len16 = arguments.length, fns = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
fns[_key15] = arguments[_key15]; fns[_key16] = arguments[_key16];
} }
return fns.reduce(function (f, g) { return fns.reduce(function (f, g) {
@ -394,8 +442,8 @@
}; };
var converge = function converge(converger, fns) { var converge = function converge(converger, fns) {
return function () { return function () {
for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) { for (var _len17 = arguments.length, args = new Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
args[_key16] = arguments[_key16]; args[_key17] = arguments[_key17];
} }
return converger.apply(void 0, _toConsumableArray(fns.map(function (fn) { return converger.apply(void 0, _toConsumableArray(fns.map(function (fn) {
@ -428,6 +476,11 @@
return acc; return acc;
}, {}); }, {});
}; };
var countOccurrences = function countOccurrences(arr, val) {
return arr.reduce(function (a, v) {
return v === val ? a + 1 : a;
}, 0);
};
var counter = function counter(selector, start, end) { var counter = function counter(selector, start, end) {
var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var duration = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 2000; var duration = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 2000;
@ -443,11 +496,6 @@
return timer; return timer;
}; };
var countOccurrences = function countOccurrences(arr, val) {
return arr.reduce(function (a, v) {
return v === val ? a + 1 : a;
}, 0);
};
var createDirIfNotExists = function createDirIfNotExists(dir) { var createDirIfNotExists = function createDirIfNotExists(dir) {
return !fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined; return !fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined;
}; };
@ -476,31 +524,14 @@
} }
}; };
}; };
var CSVToArray = function CSVToArray(data) {
var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
var omitFirstRow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return data.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0).split('\n').map(function (v) {
return v.split(delimiter);
});
};
var CSVToJSON = function CSVToJSON(data) {
var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
var titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data.slice(data.indexOf('\n') + 1).split('\n').map(function (v) {
var values = v.split(delimiter);
return titles.reduce(function (obj, title, index) {
return obj[title] = values[index], obj;
}, {});
});
};
var currentURL = function currentURL() { var currentURL = function currentURL() {
return window.location.href; return window.location.href;
}; };
var curry = function curry(fn) { var curry = function curry(fn) {
var arity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fn.length; var arity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fn.length;
for (var _len17 = arguments.length, args = new Array(_len17 > 2 ? _len17 - 2 : 0), _key17 = 2; _key17 < _len17; _key17++) { for (var _len18 = arguments.length, args = new Array(_len18 > 2 ? _len18 - 2 : 0), _key18 = 2; _key18 < _len18; _key18++) {
args[_key17 - 2] = arguments[_key17]; args[_key18 - 2] = arguments[_key18];
} }
return arity <= args.length ? fn.apply(void 0, args) : curry.bind.apply(curry, [null, fn, arity].concat(args)); return arity <= args.length ? fn.apply(void 0, args) : curry.bind.apply(curry, [null, fn, arity].concat(args));
@ -514,8 +545,8 @@
return function () { return function () {
var _this = this; var _this = this;
for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) { for (var _len19 = arguments.length, args = new Array(_len19), _key19 = 0; _key19 < _len19; _key19++) {
args[_key18] = arguments[_key18]; args[_key19] = arguments[_key19];
} }
clearTimeout(timeoutId); clearTimeout(timeoutId);
@ -566,15 +597,15 @@
}, {}) : obj; }, {}) : obj;
}; };
var defaults = function defaults(obj) { var defaults = function defaults(obj) {
for (var _len19 = arguments.length, defs = new Array(_len19 > 1 ? _len19 - 1 : 0), _key19 = 1; _key19 < _len19; _key19++) { for (var _len20 = arguments.length, defs = new Array(_len20 > 1 ? _len20 - 1 : 0), _key20 = 1; _key20 < _len20; _key20++) {
defs[_key19 - 1] = arguments[_key19]; defs[_key20 - 1] = arguments[_key20];
} }
return Object.assign.apply(Object, [{}, obj].concat(_toConsumableArray(defs.reverse()), [obj])); return Object.assign.apply(Object, [{}, obj].concat(_toConsumableArray(defs.reverse()), [obj]));
}; };
var defer = function defer(fn) { var defer = function defer(fn) {
for (var _len20 = arguments.length, args = new Array(_len20 > 1 ? _len20 - 1 : 0), _key20 = 1; _key20 < _len20; _key20++) { for (var _len21 = arguments.length, args = new Array(_len21 > 1 ? _len21 - 1 : 0), _key21 = 1; _key21 < _len21; _key21++) {
args[_key20 - 1] = arguments[_key20]; args[_key21 - 1] = arguments[_key21];
} }
return setTimeout.apply(void 0, [fn, 1].concat(args)); return setTimeout.apply(void 0, [fn, 1].concat(args));
@ -583,8 +614,8 @@
return deg * Math.PI / 180.0; return deg * Math.PI / 180.0;
}; };
var delay = function delay(fn, wait) { var delay = function delay(fn, wait) {
for (var _len21 = arguments.length, args = new Array(_len21 > 2 ? _len21 - 2 : 0), _key21 = 2; _key21 < _len21; _key21++) { for (var _len22 = arguments.length, args = new Array(_len22 > 2 ? _len22 - 2 : 0), _key22 = 2; _key22 < _len22; _key22++) {
args[_key21 - 2] = arguments[_key21]; args[_key22 - 2] = arguments[_key22];
} }
return setTimeout.apply(void 0, [fn, wait].concat(args)); return setTimeout.apply(void 0, [fn, wait].concat(args));
@ -805,8 +836,8 @@
}; };
var flip = function flip(fn) { var flip = function flip(fn) {
return function (first) { return function (first) {
for (var _len22 = arguments.length, rest = new Array(_len22 > 1 ? _len22 - 1 : 0), _key22 = 1; _key22 < _len22; _key22++) { for (var _len23 = arguments.length, rest = new Array(_len23 > 1 ? _len23 - 1 : 0), _key23 = 1; _key23 < _len23; _key23++) {
rest[_key22 - 1] = arguments[_key22]; rest[_key23 - 1] = arguments[_key23];
} }
return fn.apply(void 0, rest.concat([first])); return fn.apply(void 0, rest.concat([first]));
@ -815,6 +846,25 @@
var forEachRight = function forEachRight(arr, callback) { var forEachRight = function forEachRight(arr, callback) {
return arr.slice(0).reverse().forEach(callback); return arr.slice(0).reverse().forEach(callback);
}; };
var forOwn = function forOwn(obj, fn) {
return Object.keys(obj).forEach(function (key) {
return fn(obj[key], key, obj);
});
};
var forOwnRight = function forOwnRight(obj, fn) {
return Object.keys(obj).reverse().forEach(function (key) {
return fn(obj[key], key, obj);
});
};
var formToObject = function formToObject(form) {
return Array.from(new FormData(form)).reduce(function (acc, _ref10) {
var _ref11 = _slicedToArray(_ref10, 2),
key = _ref11[0],
value = _ref11[1];
return _objectSpread({}, acc, _defineProperty({}, key, value));
}, {});
};
var formatDuration = function formatDuration(ms) { var formatDuration = function formatDuration(ms) {
if (ms < 0) ms = -ms; if (ms < 0) ms = -ms;
var time = { var time = {
@ -826,33 +876,14 @@
}; };
return Object.entries(time).filter(function (val) { return Object.entries(time).filter(function (val) {
return val[1] !== 0; return val[1] !== 0;
}).map(function (_ref10) { }).map(function (_ref12) {
var _ref11 = _slicedToArray(_ref10, 2), var _ref13 = _slicedToArray(_ref12, 2),
key = _ref11[0], key = _ref13[0],
val = _ref11[1]; val = _ref13[1];
return "".concat(val, " ").concat(key).concat(val !== 1 ? 's' : ''); return "".concat(val, " ").concat(key).concat(val !== 1 ? 's' : '');
}).join(', '); }).join(', ');
}; };
var formToObject = function formToObject(form) {
return Array.from(new FormData(form)).reduce(function (acc, _ref12) {
var _ref13 = _slicedToArray(_ref12, 2),
key = _ref13[0],
value = _ref13[1];
return _objectSpread({}, acc, _defineProperty({}, key, value));
}, {});
};
var forOwn = function forOwn(obj, fn) {
return Object.keys(obj).forEach(function (key) {
return fn(obj[key], key, obj);
});
};
var forOwnRight = function forOwnRight(obj, fn) {
return Object.keys(obj).reverse().forEach(function (key) {
return fn(obj[key], key, obj);
});
};
var fromCamelCase = function fromCamelCase(str) { var fromCamelCase = function fromCamelCase(str) {
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '_'; var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '_';
return str.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2').replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2').toLowerCase(); return str.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2').replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2').toLowerCase();
@ -871,8 +902,8 @@
return !y ? x : gcd(y, x % y); return !y ? x : gcd(y, x % y);
}; };
for (var _len23 = arguments.length, arr = new Array(_len23), _key23 = 0; _key23 < _len23; _key23++) { for (var _len24 = arguments.length, arr = new Array(_len24), _key24 = 0; _key24 < _len24; _key24++) {
arr[_key23] = arguments[_key23]; arr[_key24] = arguments[_key24];
} }
return arr.concat().reduce(function (a, b) { return arr.concat().reduce(function (a, b) {
@ -889,8 +920,8 @@
}); });
}; };
var get = function get(from) { var get = function get(from) {
for (var _len24 = arguments.length, selectors = new Array(_len24 > 1 ? _len24 - 1 : 0), _key24 = 1; _key24 < _len24; _key24++) { for (var _len25 = arguments.length, selectors = new Array(_len25 > 1 ? _len25 - 1 : 0), _key25 = 1; _key25 < _len25; _key25++) {
selectors[_key24 - 1] = arguments[_key24]; selectors[_key25 - 1] = arguments[_key25];
} }
return selectors.concat().map(function (s) { return selectors.concat().map(function (s) {
@ -952,8 +983,8 @@
return el.classList.contains(className); return el.classList.contains(className);
}; };
var hasFlags = function hasFlags() { var hasFlags = function hasFlags() {
for (var _len25 = arguments.length, flags = new Array(_len25), _key25 = 0; _key25 < _len25; _key25++) { for (var _len26 = arguments.length, flags = new Array(_len26), _key26 = 0; _key26 < _len26; _key26++) {
flags[_key25] = arguments[_key25]; flags[_key26] = arguments[_key26];
} }
return flags.every(function (flag) { return flags.every(function (flag) {
@ -992,8 +1023,8 @@
return 'rgb' + (alpha ? 'a' : '') + '(' + (h >>> (alpha ? 24 : 16)) + ', ' + ((h & (alpha ? 0x00ff0000 : 0x00ff00)) >>> (alpha ? 16 : 8)) + ', ' + ((h & (alpha ? 0x0000ff00 : 0x0000ff)) >>> (alpha ? 8 : 0)) + (alpha ? ", ".concat(h & 0x000000ff) : '') + ')'; return 'rgb' + (alpha ? 'a' : '') + '(' + (h >>> (alpha ? 24 : 16)) + ', ' + ((h & (alpha ? 0x00ff0000 : 0x00ff00)) >>> (alpha ? 16 : 8)) + ', ' + ((h & (alpha ? 0x0000ff00 : 0x0000ff)) >>> (alpha ? 8 : 0)) + (alpha ? ", ".concat(h & 0x000000ff) : '') + ')';
}; };
var hide = function hide() { var hide = function hide() {
for (var _len26 = arguments.length, el = new Array(_len26), _key26 = 0; _key26 < _len26; _key26++) { for (var _len27 = arguments.length, el = new Array(_len27), _key27 = 0; _key27 < _len27; _key27++) {
el[_key26] = arguments[_key26]; el[_key27] = arguments[_key27];
} }
return el.concat().forEach(function (e) { return el.concat().forEach(function (e) {
@ -1044,6 +1075,17 @@
return 1000 * iterations / (performance.now() - before); return 1000 * iterations / (performance.now() - before);
}; };
var inRange = function inRange(n, start) {
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
if (end && start > end) {
var _ref14 = [start, end];
end = _ref14[0];
start = _ref14[1];
}
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
var indentString = function indentString(str, count) { var indentString = function indentString(str, count) {
var indent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' '; var indent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' ';
return str.replace(/^/gm, indent.repeat(count)); return str.replace(/^/gm, indent.repeat(count));
@ -1089,8 +1131,8 @@
return Array(n).fill(val); return Array(n).fill(val);
}; };
var initializeNDArray = function initializeNDArray(val) { var initializeNDArray = function initializeNDArray(val) {
for (var _len27 = arguments.length, args = new Array(_len27 > 1 ? _len27 - 1 : 0), _key27 = 1; _key27 < _len27; _key27++) { for (var _len28 = arguments.length, args = new Array(_len28 > 1 ? _len28 - 1 : 0), _key28 = 1; _key28 < _len28; _key28++) {
args[_key27 - 1] = arguments[_key27]; args[_key28 - 1] = arguments[_key28];
} }
return args.length === 0 ? val : Array.from({ return args.length === 0 ? val : Array.from({
@ -1099,17 +1141,6 @@
return initializeNDArray.apply(void 0, [val].concat(_toConsumableArray(args.slice(1)))); return initializeNDArray.apply(void 0, [val].concat(_toConsumableArray(args.slice(1))));
}); });
}; };
var inRange = function inRange(n, start) {
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
if (end && start > end) {
var _ref14 = [start, end];
end = _ref14[0];
start = _ref14[1];
}
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
var insertAfter = function insertAfter(el, htmlString) { var insertAfter = function insertAfter(el, htmlString) {
return el.insertAdjacentHTML('afterend', htmlString); return el.insertAdjacentHTML('afterend', htmlString);
}; };
@ -1300,17 +1331,6 @@
return i === arr.length - 2 ? acc + val + end : i === arr.length - 1 ? acc + val : acc + val + separator; return i === arr.length - 2 ? acc + val + end : i === arr.length - 1 ? acc + val : acc + val + separator;
}, ''); }, '');
}; };
var JSONtoCSV = function JSONtoCSV(arr, columns) {
var delimiter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ',';
return [columns.join(delimiter)].concat(_toConsumableArray(arr.map(function (obj) {
return columns.reduce(function (acc, key) {
return "".concat(acc).concat(!acc.length ? '' : delimiter, "\"").concat(!obj[key] ? '' : obj[key], "\"");
}, '');
}))).join('\n');
};
var JSONToFile = function JSONToFile(obj, filename) {
return fs.writeFile("".concat(filename, ".json"), JSON.stringify(obj, null, 2));
};
var last = function last(arr) { var last = function last(arr) {
return arr[arr.length - 1]; return arr[arr.length - 1];
}; };
@ -1323,8 +1343,8 @@
return x * y / gcd(x, y); return x * y / gcd(x, y);
}; };
for (var _len28 = arguments.length, arr = new Array(_len28), _key28 = 0; _key28 < _len28; _key28++) { for (var _len29 = arguments.length, arr = new Array(_len29), _key29 = 0; _key29 < _len29; _key29++) {
arr[_key28] = arguments[_key28]; arr[_key29] = arguments[_key29];
} }
return arr.concat().reduce(function (a, b) { return arr.concat().reduce(function (a, b) {
@ -1332,8 +1352,8 @@
}); });
}; };
var longestItem = function longestItem() { var longestItem = function longestItem() {
for (var _len29 = arguments.length, vals = new Array(_len29), _key29 = 0; _key29 < _len29; _key29++) { for (var _len30 = arguments.length, vals = new Array(_len30), _key30 = 0; _key30 < _len30; _key30++) {
vals[_key29] = arguments[_key29]; vals[_key30] = arguments[_key30];
} }
return vals.reduce(function (a, x) { return vals.reduce(function (a, x) {
@ -1407,8 +1427,8 @@
var maxDate = function maxDate() { var maxDate = function maxDate() {
var _Math$max; var _Math$max;
for (var _len30 = arguments.length, dates = new Array(_len30), _key30 = 0; _key30 < _len30; _key30++) { for (var _len31 = arguments.length, dates = new Array(_len31), _key31 = 0; _key31 < _len31; _key31++) {
dates[_key30] = arguments[_key30]; dates[_key31] = arguments[_key31];
} }
return new Date((_Math$max = Math.max).apply.apply(_Math$max, [null].concat(dates))); return new Date((_Math$max = Math.max).apply.apply(_Math$max, [null].concat(dates)));
@ -1438,8 +1458,8 @@
return cached; return cached;
}; };
var merge = function merge() { var merge = function merge() {
for (var _len31 = arguments.length, objs = new Array(_len31), _key31 = 0; _key31 < _len31; _key31++) { for (var _len32 = arguments.length, objs = new Array(_len32), _key32 = 0; _key32 < _len32; _key32++) {
objs[_key31] = arguments[_key31]; objs[_key32] = arguments[_key32];
} }
return objs.concat().reduce(function (acc, obj) { return objs.concat().reduce(function (acc, obj) {
@ -1468,8 +1488,8 @@
var minDate = function minDate() { var minDate = function minDate() {
var _Math$min; var _Math$min;
for (var _len32 = arguments.length, dates = new Array(_len32), _key32 = 0; _key32 < _len32; _key32++) { for (var _len33 = arguments.length, dates = new Array(_len33), _key33 = 0; _key33 < _len33; _key33++) {
dates[_key32] = arguments[_key32]; dates[_key33] = arguments[_key33];
} }
return new Date((_Math$min = Math.min).apply.apply(_Math$min, [null].concat(dates))); return new Date((_Math$min = Math.min).apply.apply(_Math$min, [null].concat(dates)));
@ -1518,8 +1538,8 @@
}; };
var nthArg = function nthArg(n) { var nthArg = function nthArg(n) {
return function () { return function () {
for (var _len33 = arguments.length, args = new Array(_len33), _key33 = 0; _key33 < _len33; _key33++) { for (var _len34 = arguments.length, args = new Array(_len34), _key34 = 0; _key34 < _len34; _key34++) {
args[_key33] = arguments[_key33]; args[_key34] = arguments[_key34];
} }
return args.slice(n)[0]; return args.slice(n)[0];
@ -1590,19 +1610,6 @@
el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false); el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false);
if (opts.target) return delegatorFn; if (opts.target) return delegatorFn;
}; };
var once = function once(fn) {
var called = false;
return function () {
if (called) return;
called = true;
for (var _len34 = arguments.length, args = new Array(_len34), _key34 = 0; _key34 < _len34; _key34++) {
args[_key34] = arguments[_key34];
}
return fn.apply(this, args);
};
};
var onUserInputChange = function onUserInputChange(callback) { var onUserInputChange = function onUserInputChange(callback) {
var type = 'mouse', var type = 'mouse',
lastTime = 0; lastTime = 0;
@ -1618,6 +1625,19 @@
type = 'touch', callback(type), document.addEventListener('mousemove', mousemoveHandler); type = 'touch', callback(type), document.addEventListener('mousemove', mousemoveHandler);
}); });
}; };
var once = function once(fn) {
var called = false;
return function () {
if (called) return;
called = true;
for (var _len35 = arguments.length, args = new Array(_len35), _key35 = 0; _key35 < _len35; _key35++) {
args[_key35] = arguments[_key35];
}
return fn.apply(this, args);
};
};
var orderBy = function orderBy(arr, props, orders) { var orderBy = function orderBy(arr, props, orders) {
return _toConsumableArray(arr).sort(function (a, b) { return _toConsumableArray(arr).sort(function (a, b) {
return props.reduce(function (acc, prop, i) { return props.reduce(function (acc, prop, i) {
@ -1635,13 +1655,13 @@
}); });
}; };
var over = function over() { var over = function over() {
for (var _len35 = arguments.length, fns = new Array(_len35), _key35 = 0; _key35 < _len35; _key35++) { for (var _len36 = arguments.length, fns = new Array(_len36), _key36 = 0; _key36 < _len36; _key36++) {
fns[_key35] = arguments[_key35]; fns[_key36] = arguments[_key36];
} }
return function () { return function () {
for (var _len36 = arguments.length, args = new Array(_len36), _key36 = 0; _key36 < _len36; _key36++) { for (var _len37 = arguments.length, args = new Array(_len37), _key37 = 0; _key37 < _len37; _key37++) {
args[_key36] = arguments[_key36]; args[_key37] = arguments[_key37];
} }
return fns.map(function (fn) { return fns.map(function (fn) {
@ -1651,8 +1671,8 @@
}; };
var overArgs = function overArgs(fn, transforms) { var overArgs = function overArgs(fn, transforms) {
return function () { return function () {
for (var _len37 = arguments.length, args = new Array(_len37), _key37 = 0; _key37 < _len37; _key37++) { for (var _len38 = arguments.length, args = new Array(_len38), _key38 = 0; _key38 < _len38; _key38++) {
args[_key37] = arguments[_key37]; args[_key38] = arguments[_key38];
} }
return fn.apply(void 0, _toConsumableArray(args.map(function (val, i) { return fn.apply(void 0, _toConsumableArray(args.map(function (val, i) {
@ -1677,26 +1697,26 @@
}, {}); }, {});
}; };
var partial = function partial(fn) { var partial = function partial(fn) {
for (var _len38 = arguments.length, partials = new Array(_len38 > 1 ? _len38 - 1 : 0), _key38 = 1; _key38 < _len38; _key38++) { for (var _len39 = arguments.length, partials = new Array(_len39 > 1 ? _len39 - 1 : 0), _key39 = 1; _key39 < _len39; _key39++) {
partials[_key38 - 1] = arguments[_key38]; partials[_key39 - 1] = arguments[_key39];
} }
return function () { return function () {
for (var _len39 = arguments.length, args = new Array(_len39), _key39 = 0; _key39 < _len39; _key39++) { for (var _len40 = arguments.length, args = new Array(_len40), _key40 = 0; _key40 < _len40; _key40++) {
args[_key39] = arguments[_key39]; args[_key40] = arguments[_key40];
} }
return fn.apply(void 0, partials.concat(args)); return fn.apply(void 0, partials.concat(args));
}; };
}; };
var partialRight = function partialRight(fn) { var partialRight = function partialRight(fn) {
for (var _len40 = arguments.length, partials = new Array(_len40 > 1 ? _len40 - 1 : 0), _key40 = 1; _key40 < _len40; _key40++) { for (var _len41 = arguments.length, partials = new Array(_len41 > 1 ? _len41 - 1 : 0), _key41 = 1; _key41 < _len41; _key41++) {
partials[_key40 - 1] = arguments[_key40]; partials[_key41 - 1] = arguments[_key41];
} }
return function () { return function () {
for (var _len41 = arguments.length, args = new Array(_len41), _key41 = 0; _key41 < _len41; _key41++) { for (var _len42 = arguments.length, args = new Array(_len42), _key42 = 0; _key42 < _len42; _key42++) {
args[_key41] = arguments[_key41]; args[_key42] = arguments[_key42];
} }
return fn.apply(void 0, args.concat(partials)); return fn.apply(void 0, args.concat(partials));
@ -1734,8 +1754,8 @@
}, {}); }, {});
}; };
var pipeAsyncFunctions = function pipeAsyncFunctions() { var pipeAsyncFunctions = function pipeAsyncFunctions() {
for (var _len42 = arguments.length, fns = new Array(_len42), _key42 = 0; _key42 < _len42; _key42++) { for (var _len43 = arguments.length, fns = new Array(_len43), _key43 = 0; _key43 < _len43; _key43++) {
fns[_key42] = arguments[_key42]; fns[_key43] = arguments[_key43];
} }
return function (arg) { return function (arg) {
@ -1745,8 +1765,8 @@
}; };
}; };
var pipeFunctions = function pipeFunctions() { var pipeFunctions = function pipeFunctions() {
for (var _len43 = arguments.length, fns = new Array(_len43), _key43 = 0; _key43 < _len43; _key43++) { for (var _len44 = arguments.length, fns = new Array(_len44), _key44 = 0; _key44 < _len44; _key44++) {
fns[_key43] = arguments[_key43]; fns[_key44] = arguments[_key44];
} }
return fns.reduce(function (f, g) { return fns.reduce(function (f, g) {
@ -1813,8 +1833,8 @@
}; };
var promisify = function promisify(func) { var promisify = function promisify(func) {
return function () { return function () {
for (var _len44 = arguments.length, args = new Array(_len44), _key44 = 0; _key44 < _len44; _key44++) { for (var _len45 = arguments.length, args = new Array(_len45), _key45 = 0; _key45 < _len45; _key45++) {
args[_key44] = arguments[_key44]; args[_key45] = arguments[_key45];
} }
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
@ -1825,8 +1845,8 @@
}; };
}; };
var pull = function pull(arr) { var pull = function pull(arr) {
for (var _len45 = arguments.length, args = new Array(_len45 > 1 ? _len45 - 1 : 0), _key45 = 1; _key45 < _len45; _key45++) { for (var _len46 = arguments.length, args = new Array(_len46 > 1 ? _len46 - 1 : 0), _key46 = 1; _key46 < _len46; _key46++) {
args[_key45 - 1] = arguments[_key45]; args[_key46 - 1] = arguments[_key46];
} }
var argState = Array.isArray(args[0]) ? args[0] : args; var argState = Array.isArray(args[0]) ? args[0] : args;
@ -1866,8 +1886,8 @@
return removed; return removed;
}; };
var pullBy = function pullBy(arr) { var pullBy = function pullBy(arr) {
for (var _len46 = arguments.length, args = new Array(_len46 > 1 ? _len46 - 1 : 0), _key46 = 1; _key46 < _len46; _key46++) { for (var _len47 = arguments.length, args = new Array(_len47 > 1 ? _len47 - 1 : 0), _key47 = 1; _key47 < _len47; _key47++) {
args[_key46 - 1] = arguments[_key46]; args[_key47 - 1] = arguments[_key47];
} }
var length = args.length; var length = args.length;
@ -1910,8 +1930,8 @@
}; };
var rearg = function rearg(fn, indexes) { var rearg = function rearg(fn, indexes) {
return function () { return function () {
for (var _len47 = arguments.length, args = new Array(_len47), _key47 = 0; _key47 < _len47; _key47++) { for (var _len48 = arguments.length, args = new Array(_len48), _key48 = 0; _key48 < _len48; _key48++) {
args[_key47] = arguments[_key47]; args[_key48] = arguments[_key48];
} }
return fn.apply(void 0, _toConsumableArray(indexes.map(function (i) { return fn.apply(void 0, _toConsumableArray(indexes.map(function (i) {
@ -1951,14 +1971,6 @@
var asLink = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; var asLink = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
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 reduceSuccessive = function reduceSuccessive(arr, fn, acc) { var reduceSuccessive = function reduceSuccessive(arr, fn, acc) {
return arr.reduce(function (res, val, i, arr) { return arr.reduce(function (res, val, i, arr) {
return res.push(fn(res.slice(-1)[0], val, i, arr)), res; return res.push(fn(res.slice(-1)[0], val, i, arr)), res;
@ -1972,6 +1984,14 @@
return comparator(a, b) >= 0 ? b : a; return comparator(a, b) >= 0 ? b : a;
}); });
}; };
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 reject = function reject(pred, array) { var reject = function reject(pred, array) {
return array.filter(function () { return array.filter(function () {
return !pred.apply(void 0, arguments); return !pred.apply(void 0, arguments);
@ -1994,9 +2014,6 @@
var reverseString = function reverseString(str) { var reverseString = function reverseString(str) {
return _toConsumableArray(str).reverse().join(''); return _toConsumableArray(str).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("".concat(Math.round("".concat(n, "e").concat(decimals)), "e-").concat(decimals)); return Number("".concat(Math.round("".concat(n, "e").concat(decimals)), "e-").concat(decimals));
@ -2072,15 +2089,15 @@
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var delCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; var delCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
for (var _len48 = arguments.length, elements = new Array(_len48 > 3 ? _len48 - 3 : 0), _key48 = 3; _key48 < _len48; _key48++) { for (var _len49 = arguments.length, elements = new Array(_len49 > 3 ? _len49 - 3 : 0), _key49 = 3; _key49 < _len49; _key49++) {
elements[_key48 - 3] = arguments[_key48]; elements[_key49 - 3] = arguments[_key49];
} }
return arr.slice(0, index).concat(elements).concat(arr.slice(index + delCount)); return arr.slice(0, index).concat(elements).concat(arr.slice(index + delCount));
}; };
var show = function show() { var show = function show() {
for (var _len49 = arguments.length, el = new Array(_len49), _key49 = 0; _key49 < _len49; _key49++) { for (var _len50 = arguments.length, el = new Array(_len50), _key50 = 0; _key50 < _len50; _key50++) {
el[_key49] = arguments[_key49]; el[_key50] = arguments[_key50];
} }
return el.concat().forEach(function (e) { return el.concat().forEach(function (e) {
@ -2199,8 +2216,8 @@
return str.replace(/<[^>]*>/g, ''); return str.replace(/<[^>]*>/g, '');
}; };
var sum = function sum() { var sum = function sum() {
for (var _len50 = arguments.length, arr = new Array(_len50), _key50 = 0; _key50 < _len50; _key50++) { for (var _len51 = arguments.length, arr = new Array(_len51), _key51 = 0; _key51 < _len51; _key51++) {
arr[_key50] = arguments[_key50]; arr[_key51] = arguments[_key51];
} }
return arr.concat().reduce(function (acc, val) { return arr.concat().reduce(function (acc, val) {
@ -2323,18 +2340,18 @@
} }
}; };
}; };
var times = function times(n, fn) {
var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
var i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
var timeTaken = function timeTaken(callback) { var timeTaken = function timeTaken(callback) {
console.time('timeTaken'); console.time('timeTaken');
var r = callback(); var r = callback();
console.timeEnd('timeTaken'); console.timeEnd('timeTaken');
return r; return r;
}; };
var times = function times(n, fn) {
var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
var i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
var toCamelCase = function toCamelCase(str) { var toCamelCase = function toCamelCase(str) {
var s = 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) { var s = 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.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase(); return x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase();
@ -2351,9 +2368,6 @@
var toDecimalMark = function toDecimalMark(num) { var toDecimalMark = function toDecimalMark(num) {
return num.toLocaleString('en-US'); return num.toLocaleString('en-US');
}; };
var toggleClass = function toggleClass(el, className) {
return el.classList.toggle(className);
};
var toHash = function toHash(object, key) { var toHash = function toHash(object, key) {
return Array.prototype.reduce.call(object, function (acc, data, index) { return Array.prototype.reduce.call(object, function (acc, data, index) {
return acc[!key ? index : data[key]] = data, acc; return acc[!key ? index : data[key]] = data, acc;
@ -2364,11 +2378,6 @@
return x.toLowerCase(); return x.toLowerCase();
}).join('-'); }).join('-');
}; };
var tomorrow = function tomorrow() {
var t = new Date();
t.setDate(t.getDate() + 1);
return t.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],
@ -2390,6 +2399,14 @@
return x.charAt(0).toUpperCase() + x.slice(1); return x.charAt(0).toUpperCase() + x.slice(1);
}).join(' '); }).join(' ');
}; };
var toggleClass = function toggleClass(el, className) {
return el.classList.toggle(className);
};
var tomorrow = function tomorrow() {
var t = new Date();
t.setDate(t.getDate() + 1);
return t.toISOString().split('T')[0];
};
var transform = function transform(obj, fn, acc) { var transform = function transform(obj, fn, acc) {
return Object.keys(obj).reduce(function (a, k) { return Object.keys(obj).reduce(function (a, k) {
return fn(a, obj[k], k, obj); return fn(a, obj[k], k, obj);
@ -2424,8 +2441,8 @@
}; };
}; };
for (var _len51 = arguments.length, args = new Array(_len51), _key51 = 0; _key51 < _len51; _key51++) { for (var _len52 = arguments.length, args = new Array(_len52), _key52 = 0; _key52 < _len52; _key52++) {
args[_key51] = arguments[_key51]; args[_key52] = arguments[_key52];
} }
if (n > args.length) throw new RangeError('Arguments too few!'); if (n > args.length) throw new RangeError('Arguments too few!');
@ -2538,23 +2555,6 @@
return fn.apply(void 0, _toConsumableArray(val)); return fn.apply(void 0, _toConsumableArray(val));
}); });
}; };
var URLJoin = function URLJoin() {
for (var _len52 = arguments.length, args = new Array(_len52), _key52 = 0; _key52 < _len52; _key52++) {
args[_key52] = arguments[_key52];
}
return args.join('/').replace(/[\/]+/g, '/').replace(/^(.+):\//, '$1://').replace(/^file:/, 'file:/').replace(/\/(\?|&|#[^!])/g, '$1').replace(/\?/g, '&').replace('&', '?');
};
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 UUIDGeneratorNode = function UUIDGeneratorNode() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
return (c ^ crypto.randomBytes(1)[0] & 15 >> c / 4).toString(16);
});
};
var validateNumber = function validateNumber(n) { var validateNumber = function validateNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n; return !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
}; };
@ -2640,6 +2640,14 @@
}); });
}; };
exports.CSVToArray = CSVToArray;
exports.CSVToJSON = CSVToJSON;
exports.JSONToFile = JSONToFile;
exports.JSONtoCSV = JSONtoCSV;
exports.RGBToHex = RGBToHex;
exports.URLJoin = URLJoin;
exports.UUIDGeneratorBrowser = UUIDGeneratorBrowser;
exports.UUIDGeneratorNode = UUIDGeneratorNode;
exports.all = all; exports.all = all;
exports.allEqual = allEqual; exports.allEqual = allEqual;
exports.any = any; exports.any = any;
@ -2680,13 +2688,11 @@
exports.converge = converge; exports.converge = converge;
exports.copyToClipboard = copyToClipboard; exports.copyToClipboard = copyToClipboard;
exports.countBy = countBy; exports.countBy = countBy;
exports.counter = counter;
exports.countOccurrences = countOccurrences; exports.countOccurrences = countOccurrences;
exports.counter = counter;
exports.createDirIfNotExists = createDirIfNotExists; exports.createDirIfNotExists = createDirIfNotExists;
exports.createElement = createElement; exports.createElement = createElement;
exports.createEventHub = createEventHub; exports.createEventHub = createEventHub;
exports.CSVToArray = CSVToArray;
exports.CSVToJSON = CSVToJSON;
exports.currentURL = currentURL; exports.currentURL = currentURL;
exports.curry = curry; exports.curry = curry;
exports.dayOfYear = dayOfYear; exports.dayOfYear = dayOfYear;
@ -2733,10 +2739,10 @@
exports.flattenObject = flattenObject; exports.flattenObject = flattenObject;
exports.flip = flip; exports.flip = flip;
exports.forEachRight = forEachRight; exports.forEachRight = forEachRight;
exports.formatDuration = formatDuration;
exports.formToObject = formToObject;
exports.forOwn = forOwn; exports.forOwn = forOwn;
exports.forOwnRight = forOwnRight; exports.forOwnRight = forOwnRight;
exports.formToObject = formToObject;
exports.formatDuration = formatDuration;
exports.fromCamelCase = fromCamelCase; exports.fromCamelCase = fromCamelCase;
exports.functionName = functionName; exports.functionName = functionName;
exports.functions = functions; exports.functions = functions;
@ -2764,6 +2770,7 @@
exports.httpPost = httpPost; exports.httpPost = httpPost;
exports.httpsRedirect = httpsRedirect; exports.httpsRedirect = httpsRedirect;
exports.hz = hz; exports.hz = hz;
exports.inRange = inRange;
exports.indentString = indentString; exports.indentString = indentString;
exports.indexOfAll = indexOfAll; exports.indexOfAll = indexOfAll;
exports.initial = initial; exports.initial = initial;
@ -2772,7 +2779,6 @@
exports.initializeArrayWithRangeRight = initializeArrayWithRangeRight; exports.initializeArrayWithRangeRight = initializeArrayWithRangeRight;
exports.initializeArrayWithValues = initializeArrayWithValues; exports.initializeArrayWithValues = initializeArrayWithValues;
exports.initializeNDArray = initializeNDArray; exports.initializeNDArray = initializeNDArray;
exports.inRange = inRange;
exports.insertAfter = insertAfter; exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore; exports.insertBefore = insertBefore;
exports.intersection = intersection; exports.intersection = intersection;
@ -2816,8 +2822,6 @@
exports.isValidJSON = isValidJSON; exports.isValidJSON = isValidJSON;
exports.isWritableStream = isWritableStream; exports.isWritableStream = isWritableStream;
exports.join = join; exports.join = join;
exports.JSONtoCSV = JSONtoCSV;
exports.JSONToFile = JSONToFile;
exports.last = last; exports.last = last;
exports.lcm = lcm; exports.lcm = lcm;
exports.longestItem = longestItem; exports.longestItem = longestItem;
@ -2856,8 +2860,8 @@
exports.omit = omit; exports.omit = omit;
exports.omitBy = omitBy; exports.omitBy = omitBy;
exports.on = on; exports.on = on;
exports.once = once;
exports.onUserInputChange = onUserInputChange; exports.onUserInputChange = onUserInputChange;
exports.once = once;
exports.orderBy = orderBy; exports.orderBy = orderBy;
exports.over = over; exports.over = over;
exports.overArgs = overArgs; exports.overArgs = overArgs;
@ -2892,15 +2896,14 @@
exports.rearg = rearg; exports.rearg = rearg;
exports.recordAnimationFrames = recordAnimationFrames; exports.recordAnimationFrames = recordAnimationFrames;
exports.redirect = redirect; exports.redirect = redirect;
exports.reducedFilter = reducedFilter;
exports.reduceSuccessive = reduceSuccessive; exports.reduceSuccessive = reduceSuccessive;
exports.reduceWhich = reduceWhich; exports.reduceWhich = reduceWhich;
exports.reducedFilter = reducedFilter;
exports.reject = reject; exports.reject = reject;
exports.remove = remove; exports.remove = remove;
exports.removeNonASCII = removeNonASCII; exports.removeNonASCII = removeNonASCII;
exports.renameKeys = renameKeys; exports.renameKeys = renameKeys;
exports.reverseString = reverseString; exports.reverseString = reverseString;
exports.RGBToHex = RGBToHex;
exports.round = round; exports.round = round;
exports.runAsync = runAsync; exports.runAsync = runAsync;
exports.runPromisesInSeries = runPromisesInSeries; exports.runPromisesInSeries = runPromisesInSeries;
@ -2942,19 +2945,19 @@
exports.takeRightWhile = takeRightWhile; exports.takeRightWhile = takeRightWhile;
exports.takeWhile = takeWhile; exports.takeWhile = takeWhile;
exports.throttle = throttle; exports.throttle = throttle;
exports.times = times;
exports.timeTaken = timeTaken; exports.timeTaken = timeTaken;
exports.times = times;
exports.toCamelCase = toCamelCase; exports.toCamelCase = toCamelCase;
exports.toCurrency = toCurrency; exports.toCurrency = toCurrency;
exports.toDecimalMark = toDecimalMark; exports.toDecimalMark = toDecimalMark;
exports.toggleClass = toggleClass;
exports.toHash = toHash; exports.toHash = toHash;
exports.toKebabCase = toKebabCase; exports.toKebabCase = toKebabCase;
exports.tomorrow = tomorrow;
exports.toOrdinalSuffix = toOrdinalSuffix; exports.toOrdinalSuffix = toOrdinalSuffix;
exports.toSafeInteger = toSafeInteger; exports.toSafeInteger = toSafeInteger;
exports.toSnakeCase = toSnakeCase; exports.toSnakeCase = toSnakeCase;
exports.toTitleCase = toTitleCase; exports.toTitleCase = toTitleCase;
exports.toggleClass = toggleClass;
exports.tomorrow = tomorrow;
exports.transform = transform; exports.transform = transform;
exports.triggerEvent = triggerEvent; exports.triggerEvent = triggerEvent;
exports.truncateString = truncateString; exports.truncateString = truncateString;
@ -2974,9 +2977,6 @@
exports.untildify = untildify; exports.untildify = untildify;
exports.unzip = unzip; exports.unzip = unzip;
exports.unzipWith = unzipWith; exports.unzipWith = unzipWith;
exports.URLJoin = URLJoin;
exports.UUIDGeneratorBrowser = UUIDGeneratorBrowser;
exports.UUIDGeneratorNode = UUIDGeneratorNode;
exports.validateNumber = validateNumber; exports.validateNumber = validateNumber;
exports.vectorDistance = vectorDistance; exports.vectorDistance = vectorDistance;
exports.when = when; exports.when = when;

File diff suppressed because one or more lines are too long

172
dist/_30s.esm.js vendored
View File

@ -1,6 +1,51 @@
const fs = typeof require !== "undefined" && require('fs'); const fs = typeof require !== "undefined" && require('fs');
const crypto = typeof require !== "undefined" && require('crypto'); const crypto = typeof require !== "undefined" && require('crypto');
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
data
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
.split('\n')
.map(v => v.split(delimiter));
const CSVToJSON = (data, delimiter = ',') => {
const titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data
.slice(data.indexOf('\n') + 1)
.split('\n')
.map(v => {
const values = v.split(delimiter);
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {});
});
};
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
const JSONtoCSV = (arr, columns, delimiter = ',') =>
[
columns.join(delimiter),
...arr.map(obj =>
columns.reduce(
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
''
)
)
].join('\n');
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
const URLJoin = (...args) =>
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
const UUIDGeneratorBrowser = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
const UUIDGeneratorNode = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
);
const all = (arr, fn = Boolean) => arr.every(fn); const all = (arr, fn = Boolean) => arr.every(fn);
const allEqual = arr => arr.every(val => val === arr[0]); const allEqual = arr => arr.every(val => val === arr[0]);
const any = (arr, fn = Boolean) => arr.some(fn); const any = (arr, fn = Boolean) => arr.some(fn);
@ -127,6 +172,7 @@ const countBy = (arr, fn) =>
acc[val] = (acc[val] || 0) + 1; acc[val] = (acc[val] || 0) + 1;
return acc; return acc;
}, {}); }, {});
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
const counter = (selector, start, end, step = 1, duration = 2000) => { const counter = (selector, start, end, step = 1, duration = 2000) => {
let current = start, let current = start,
_step = (end - start) * step < 0 ? -step : step, _step = (end - start) * step < 0 ? -step : step,
@ -138,7 +184,6 @@ const counter = (selector, start, end, step = 1, duration = 2000) => {
}, Math.abs(Math.floor(duration / (end - start)))); }, Math.abs(Math.floor(duration / (end - start))));
return timer; return timer;
}; };
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined); const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);
const createElement = str => { const createElement = str => {
const el = document.createElement('div'); const el = document.createElement('div');
@ -159,21 +204,6 @@ const createEventHub = () => ({
if (i > -1) this.hub[event].splice(i, 1); if (i > -1) this.hub[event].splice(i, 1);
} }
}); });
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
data
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
.split('\n')
.map(v => v.split(delimiter));
const CSVToJSON = (data, delimiter = ',') => {
const titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data
.slice(data.indexOf('\n') + 1)
.split('\n')
.map(v => {
const values = v.split(delimiter);
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {});
});
};
const currentURL = () => window.location.href; const currentURL = () => window.location.href;
const curry = (fn, arity = fn.length, ...args) => const curry = (fn, arity = fn.length, ...args) =>
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args); arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
@ -352,6 +382,19 @@ const forEachRight = (arr, callback) =>
.slice(0) .slice(0)
.reverse() .reverse()
.forEach(callback); .forEach(callback);
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
const forOwnRight = (obj, fn) =>
Object.keys(obj)
.reverse()
.forEach(key => fn(obj[key], key, obj));
const formToObject = form =>
Array.from(new FormData(form)).reduce(
(acc, [key, value]) => ({
...acc,
[key]: value
}),
{}
);
const formatDuration = ms => { const formatDuration = ms => {
if (ms < 0) ms = -ms; if (ms < 0) ms = -ms;
const time = { const time = {
@ -366,19 +409,6 @@ const formatDuration = ms => {
.map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`) .map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
.join(', '); .join(', ');
}; };
const formToObject = form =>
Array.from(new FormData(form)).reduce(
(acc, [key, value]) => ({
...acc,
[key]: value
}),
{}
);
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
const forOwnRight = (obj, fn) =>
Object.keys(obj)
.reverse()
.forEach(key => fn(obj[key], key, obj));
const fromCamelCase = (str, separator = '_') => const fromCamelCase = (str, separator = '_') =>
str str
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2') .replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
@ -507,6 +537,10 @@ const hz = (fn, iterations = 100) => {
for (let i = 0; i < iterations; i++) fn(); for (let i = 0; i < iterations; i++) fn();
return (1000 * iterations) / (performance.now() - before); return (1000 * iterations) / (performance.now() - before);
}; };
const inRange = (n, start, end = null) => {
if (end && start > end) [end, start] = [start, end];
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.repeat(count)); const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.repeat(count));
const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...acc, i] : acc), []); const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...acc, i] : acc), []);
const initial = arr => arr.slice(0, -1); const initial = arr => arr.slice(0, -1);
@ -523,10 +557,6 @@ const initializeNDArray = (val, ...args) =>
args.length === 0 args.length === 0
? val ? val
: Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1))); : Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1)));
const inRange = (n, start, end = null) => {
if (end && start > end) [end, start] = [start, end];
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlString); const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlString);
const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString); const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString);
const intersection = (a, b) => { const intersection = (a, b) => {
@ -638,18 +668,6 @@ const join = (arr, separator = ',', end = separator) =>
: acc + val + separator, : acc + val + separator,
'' ''
); );
const JSONtoCSV = (arr, columns, delimiter = ',') =>
[
columns.join(delimiter),
...arr.map(obj =>
columns.reduce(
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
''
)
)
].join('\n');
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
const last = arr => arr[arr.length - 1]; const last = arr => arr[arr.length - 1];
const lcm = (...arr) => { const lcm = (...arr) => {
const gcd = (x, y) => (!y ? x : gcd(y, x % y)); const gcd = (x, y) => (!y ? x : gcd(y, x % y));
@ -784,14 +802,6 @@ const on = (el, evt, fn, opts = {}) => {
el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false); el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false);
if (opts.target) return delegatorFn; if (opts.target) return delegatorFn;
}; };
const once = fn => {
let called = false;
return function(...args) {
if (called) return;
called = true;
return fn.apply(this, args);
};
};
const onUserInputChange = callback => { const onUserInputChange = callback => {
let type = 'mouse', let type = 'mouse',
lastTime = 0; lastTime = 0;
@ -806,6 +816,14 @@ const onUserInputChange = callback => {
(type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler); (type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler);
}); });
}; };
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) => {
@ -964,6 +982,10 @@ const recordAnimationFrames = (callback, autoStart = true) => {
}; };
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 reduceSuccessive = (arr, fn, acc) =>
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]);
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
const reducedFilter = (data, keys, fn) => const reducedFilter = (data, keys, fn) =>
data.filter(fn).map(el => data.filter(fn).map(el =>
keys.reduce((acc, key) => { keys.reduce((acc, key) => {
@ -971,10 +993,6 @@ const reducedFilter = (data, keys, fn) =>
return acc; return acc;
}, {}) }, {})
); );
const reduceSuccessive = (arr, fn, acc) =>
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]);
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
const reject = (pred, array) => array.filter((...args) => !pred(...args)); const reject = (pred, array) => array.filter((...args) => !pred(...args));
const remove = (arr, func) => const remove = (arr, func) =>
Array.isArray(arr) Array.isArray(arr)
@ -993,7 +1011,6 @@ const renameKeys = (keysMap, obj) =>
{} {}
); );
const reverseString = str => [...str].reverse().join(''); const reverseString = str => [...str].reverse().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 runAsync = fn => {
const worker = new Worker( const worker = new Worker(
@ -1170,16 +1187,16 @@ const throttle = (fn, wait) => {
} }
}; };
}; };
const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
const timeTaken = callback => { const timeTaken = callback => {
console.time('timeTaken'); console.time('timeTaken');
const r = callback(); const r = callback();
console.timeEnd('timeTaken'); console.timeEnd('timeTaken');
return r; return r;
}; };
const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
const toCamelCase = str => { const toCamelCase = str => {
let s = let s =
str && str &&
@ -1192,7 +1209,6 @@ const toCamelCase = str => {
const toCurrency = (n, curr, LanguageFormat = undefined) => const toCurrency = (n, curr, LanguageFormat = undefined) =>
Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n); Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
const toDecimalMark = num => num.toLocaleString('en-US'); const toDecimalMark = num => num.toLocaleString('en-US');
const toggleClass = (el, className) => el.classList.toggle(className);
const toHash = (object, key) => const toHash = (object, key) =>
Array.prototype.reduce.call( Array.prototype.reduce.call(
object, object,
@ -1205,11 +1221,6 @@ const toKebabCase = 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 tomorrow = () => {
let t = new Date();
t.setDate(t.getDate() + 1);
return t.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],
@ -1233,6 +1244,12 @@ const toTitleCase = 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.charAt(0).toUpperCase() + x.slice(1)) .map(x => x.charAt(0).toUpperCase() + x.slice(1))
.join(' '); .join(' ');
const toggleClass = (el, className) => el.classList.toggle(className);
const tomorrow = () => {
let t = new Date();
t.setDate(t.getDate() + 1);
return t.toISOString().split('T')[0];
};
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc); const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
const triggerEvent = (el, eventType, detail) => const triggerEvent = (el, eventType, detail) =>
el.dispatchEvent(new CustomEvent(eventType, { detail })); el.dispatchEvent(new CustomEvent(eventType, { detail }));
@ -1317,23 +1334,6 @@ const unzipWith = (arr, fn) =>
}).map(x => []) }).map(x => [])
) )
.map(val => fn(...val)); .map(val => fn(...val));
const URLJoin = (...args) =>
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
const UUIDGeneratorBrowser = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
const UUIDGeneratorNode = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.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;
const vectorDistance = (...coords) => { const vectorDistance = (...coords) => {
let pointLength = Math.trunc(coords.length / 2); let pointLength = Math.trunc(coords.length / 2);
@ -1364,4 +1364,4 @@ const zipWith = (...array) => {
); );
}; };
export { all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, checkProp, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compactWhitespace, compose, composeRight, converge, copyToClipboard, countBy, counter, countOccurrences, createDirIfNotExists, createElement, createEventHub, CSVToArray, CSVToJSON, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, deepGet, deepMapKeys, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, formatDuration, formToObject, forOwn, forOwnRight, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, inRange, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, JSONtoCSV, JSONToFile, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapNumRange, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, once, onUserInputChange, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reducedFilter, reduceSuccessive, reduceWhich, reject, remove, removeNonASCII, renameKeys, reverseString, RGBToHex, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, serializeForm, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, times, timeTaken, toCamelCase, toCurrency, toDecimalMark, toggleClass, toHash, toKebabCase, tomorrow, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, validateNumber, vectorDistance, when, without, words, xProd, yesNo, zip, zipObject, zipWith }; export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, checkProp, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compactWhitespace, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createDirIfNotExists, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, deepGet, deepMapKeys, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formToObject, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapNumRange, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, serializeForm, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, vectorDistance, when, without, words, xProd, yesNo, zip, zipObject, zipWith };

204
dist/_30s.js vendored
View File

@ -7,6 +7,51 @@
const fs = typeof require !== "undefined" && require('fs'); const fs = typeof require !== "undefined" && require('fs');
const crypto = typeof require !== "undefined" && require('crypto'); const crypto = typeof require !== "undefined" && require('crypto');
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
data
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
.split('\n')
.map(v => v.split(delimiter));
const CSVToJSON = (data, delimiter = ',') => {
const titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data
.slice(data.indexOf('\n') + 1)
.split('\n')
.map(v => {
const values = v.split(delimiter);
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {});
});
};
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
const JSONtoCSV = (arr, columns, delimiter = ',') =>
[
columns.join(delimiter),
...arr.map(obj =>
columns.reduce(
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
''
)
)
].join('\n');
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
const URLJoin = (...args) =>
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
const UUIDGeneratorBrowser = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
const UUIDGeneratorNode = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
);
const all = (arr, fn = Boolean) => arr.every(fn); const all = (arr, fn = Boolean) => arr.every(fn);
const allEqual = arr => arr.every(val => val === arr[0]); const allEqual = arr => arr.every(val => val === arr[0]);
const any = (arr, fn = Boolean) => arr.some(fn); const any = (arr, fn = Boolean) => arr.some(fn);
@ -133,6 +178,7 @@
acc[val] = (acc[val] || 0) + 1; acc[val] = (acc[val] || 0) + 1;
return acc; return acc;
}, {}); }, {});
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
const counter = (selector, start, end, step = 1, duration = 2000) => { const counter = (selector, start, end, step = 1, duration = 2000) => {
let current = start, let current = start,
_step = (end - start) * step < 0 ? -step : step, _step = (end - start) * step < 0 ? -step : step,
@ -144,7 +190,6 @@
}, Math.abs(Math.floor(duration / (end - start)))); }, Math.abs(Math.floor(duration / (end - start))));
return timer; return timer;
}; };
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined); const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);
const createElement = str => { const createElement = str => {
const el = document.createElement('div'); const el = document.createElement('div');
@ -165,21 +210,6 @@
if (i > -1) this.hub[event].splice(i, 1); if (i > -1) this.hub[event].splice(i, 1);
} }
}); });
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
data
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
.split('\n')
.map(v => v.split(delimiter));
const CSVToJSON = (data, delimiter = ',') => {
const titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data
.slice(data.indexOf('\n') + 1)
.split('\n')
.map(v => {
const values = v.split(delimiter);
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {});
});
};
const currentURL = () => window.location.href; const currentURL = () => window.location.href;
const curry = (fn, arity = fn.length, ...args) => const curry = (fn, arity = fn.length, ...args) =>
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args); arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
@ -358,6 +388,19 @@
.slice(0) .slice(0)
.reverse() .reverse()
.forEach(callback); .forEach(callback);
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
const forOwnRight = (obj, fn) =>
Object.keys(obj)
.reverse()
.forEach(key => fn(obj[key], key, obj));
const formToObject = form =>
Array.from(new FormData(form)).reduce(
(acc, [key, value]) => ({
...acc,
[key]: value
}),
{}
);
const formatDuration = ms => { const formatDuration = ms => {
if (ms < 0) ms = -ms; if (ms < 0) ms = -ms;
const time = { const time = {
@ -372,19 +415,6 @@
.map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`) .map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
.join(', '); .join(', ');
}; };
const formToObject = form =>
Array.from(new FormData(form)).reduce(
(acc, [key, value]) => ({
...acc,
[key]: value
}),
{}
);
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
const forOwnRight = (obj, fn) =>
Object.keys(obj)
.reverse()
.forEach(key => fn(obj[key], key, obj));
const fromCamelCase = (str, separator = '_') => const fromCamelCase = (str, separator = '_') =>
str str
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2') .replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
@ -513,6 +543,10 @@
for (let i = 0; i < iterations; i++) fn(); for (let i = 0; i < iterations; i++) fn();
return (1000 * iterations) / (performance.now() - before); return (1000 * iterations) / (performance.now() - before);
}; };
const inRange = (n, start, end = null) => {
if (end && start > end) [end, start] = [start, end];
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.repeat(count)); const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.repeat(count));
const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...acc, i] : acc), []); const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...acc, i] : acc), []);
const initial = arr => arr.slice(0, -1); const initial = arr => arr.slice(0, -1);
@ -529,10 +563,6 @@
args.length === 0 args.length === 0
? val ? val
: Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1))); : Array.from({ length: args[0] }).map(() => initializeNDArray(val, ...args.slice(1)));
const inRange = (n, start, end = null) => {
if (end && start > end) [end, start] = [start, end];
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlString); const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlString);
const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString); const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString);
const intersection = (a, b) => { const intersection = (a, b) => {
@ -644,18 +674,6 @@
: acc + val + separator, : acc + val + separator,
'' ''
); );
const JSONtoCSV = (arr, columns, delimiter = ',') =>
[
columns.join(delimiter),
...arr.map(obj =>
columns.reduce(
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
''
)
)
].join('\n');
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
const last = arr => arr[arr.length - 1]; const last = arr => arr[arr.length - 1];
const lcm = (...arr) => { const lcm = (...arr) => {
const gcd = (x, y) => (!y ? x : gcd(y, x % y)); const gcd = (x, y) => (!y ? x : gcd(y, x % y));
@ -790,14 +808,6 @@
el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false); el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false);
if (opts.target) return delegatorFn; if (opts.target) return delegatorFn;
}; };
const once = fn => {
let called = false;
return function(...args) {
if (called) return;
called = true;
return fn.apply(this, args);
};
};
const onUserInputChange = callback => { const onUserInputChange = callback => {
let type = 'mouse', let type = 'mouse',
lastTime = 0; lastTime = 0;
@ -812,6 +822,14 @@
(type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler); (type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler);
}); });
}; };
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) => {
@ -970,6 +988,10 @@
}; };
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 reduceSuccessive = (arr, fn, acc) =>
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]);
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
const reducedFilter = (data, keys, fn) => const reducedFilter = (data, keys, fn) =>
data.filter(fn).map(el => data.filter(fn).map(el =>
keys.reduce((acc, key) => { keys.reduce((acc, key) => {
@ -977,10 +999,6 @@
return acc; return acc;
}, {}) }, {})
); );
const reduceSuccessive = (arr, fn, acc) =>
arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]);
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
const reject = (pred, array) => array.filter((...args) => !pred(...args)); const reject = (pred, array) => array.filter((...args) => !pred(...args));
const remove = (arr, func) => const remove = (arr, func) =>
Array.isArray(arr) Array.isArray(arr)
@ -999,7 +1017,6 @@
{} {}
); );
const reverseString = str => [...str].reverse().join(''); const reverseString = str => [...str].reverse().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 runAsync = fn => {
const worker = new Worker( const worker = new Worker(
@ -1176,16 +1193,16 @@
} }
}; };
}; };
const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
const timeTaken = callback => { const timeTaken = callback => {
console.time('timeTaken'); console.time('timeTaken');
const r = callback(); const r = callback();
console.timeEnd('timeTaken'); console.timeEnd('timeTaken');
return r; return r;
}; };
const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
const toCamelCase = str => { const toCamelCase = str => {
let s = let s =
str && str &&
@ -1198,7 +1215,6 @@
const toCurrency = (n, curr, LanguageFormat = undefined) => const toCurrency = (n, curr, LanguageFormat = undefined) =>
Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n); Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
const toDecimalMark = num => num.toLocaleString('en-US'); const toDecimalMark = num => num.toLocaleString('en-US');
const toggleClass = (el, className) => el.classList.toggle(className);
const toHash = (object, key) => const toHash = (object, key) =>
Array.prototype.reduce.call( Array.prototype.reduce.call(
object, object,
@ -1211,11 +1227,6 @@
.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 tomorrow = () => {
let t = new Date();
t.setDate(t.getDate() + 1);
return t.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],
@ -1239,6 +1250,12 @@
.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.charAt(0).toUpperCase() + x.slice(1)) .map(x => x.charAt(0).toUpperCase() + x.slice(1))
.join(' '); .join(' ');
const toggleClass = (el, className) => el.classList.toggle(className);
const tomorrow = () => {
let t = new Date();
t.setDate(t.getDate() + 1);
return t.toISOString().split('T')[0];
};
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc); const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
const triggerEvent = (el, eventType, detail) => const triggerEvent = (el, eventType, detail) =>
el.dispatchEvent(new CustomEvent(eventType, { detail })); el.dispatchEvent(new CustomEvent(eventType, { detail }));
@ -1323,23 +1340,6 @@
}).map(x => []) }).map(x => [])
) )
.map(val => fn(...val)); .map(val => fn(...val));
const URLJoin = (...args) =>
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
const UUIDGeneratorBrowser = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
const UUIDGeneratorNode = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.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;
const vectorDistance = (...coords) => { const vectorDistance = (...coords) => {
let pointLength = Math.trunc(coords.length / 2); let pointLength = Math.trunc(coords.length / 2);
@ -1370,6 +1370,14 @@
); );
}; };
exports.CSVToArray = CSVToArray;
exports.CSVToJSON = CSVToJSON;
exports.JSONToFile = JSONToFile;
exports.JSONtoCSV = JSONtoCSV;
exports.RGBToHex = RGBToHex;
exports.URLJoin = URLJoin;
exports.UUIDGeneratorBrowser = UUIDGeneratorBrowser;
exports.UUIDGeneratorNode = UUIDGeneratorNode;
exports.all = all; exports.all = all;
exports.allEqual = allEqual; exports.allEqual = allEqual;
exports.any = any; exports.any = any;
@ -1410,13 +1418,11 @@
exports.converge = converge; exports.converge = converge;
exports.copyToClipboard = copyToClipboard; exports.copyToClipboard = copyToClipboard;
exports.countBy = countBy; exports.countBy = countBy;
exports.counter = counter;
exports.countOccurrences = countOccurrences; exports.countOccurrences = countOccurrences;
exports.counter = counter;
exports.createDirIfNotExists = createDirIfNotExists; exports.createDirIfNotExists = createDirIfNotExists;
exports.createElement = createElement; exports.createElement = createElement;
exports.createEventHub = createEventHub; exports.createEventHub = createEventHub;
exports.CSVToArray = CSVToArray;
exports.CSVToJSON = CSVToJSON;
exports.currentURL = currentURL; exports.currentURL = currentURL;
exports.curry = curry; exports.curry = curry;
exports.dayOfYear = dayOfYear; exports.dayOfYear = dayOfYear;
@ -1463,10 +1469,10 @@
exports.flattenObject = flattenObject; exports.flattenObject = flattenObject;
exports.flip = flip; exports.flip = flip;
exports.forEachRight = forEachRight; exports.forEachRight = forEachRight;
exports.formatDuration = formatDuration;
exports.formToObject = formToObject;
exports.forOwn = forOwn; exports.forOwn = forOwn;
exports.forOwnRight = forOwnRight; exports.forOwnRight = forOwnRight;
exports.formToObject = formToObject;
exports.formatDuration = formatDuration;
exports.fromCamelCase = fromCamelCase; exports.fromCamelCase = fromCamelCase;
exports.functionName = functionName; exports.functionName = functionName;
exports.functions = functions; exports.functions = functions;
@ -1494,6 +1500,7 @@
exports.httpPost = httpPost; exports.httpPost = httpPost;
exports.httpsRedirect = httpsRedirect; exports.httpsRedirect = httpsRedirect;
exports.hz = hz; exports.hz = hz;
exports.inRange = inRange;
exports.indentString = indentString; exports.indentString = indentString;
exports.indexOfAll = indexOfAll; exports.indexOfAll = indexOfAll;
exports.initial = initial; exports.initial = initial;
@ -1502,7 +1509,6 @@
exports.initializeArrayWithRangeRight = initializeArrayWithRangeRight; exports.initializeArrayWithRangeRight = initializeArrayWithRangeRight;
exports.initializeArrayWithValues = initializeArrayWithValues; exports.initializeArrayWithValues = initializeArrayWithValues;
exports.initializeNDArray = initializeNDArray; exports.initializeNDArray = initializeNDArray;
exports.inRange = inRange;
exports.insertAfter = insertAfter; exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore; exports.insertBefore = insertBefore;
exports.intersection = intersection; exports.intersection = intersection;
@ -1546,8 +1552,6 @@
exports.isValidJSON = isValidJSON; exports.isValidJSON = isValidJSON;
exports.isWritableStream = isWritableStream; exports.isWritableStream = isWritableStream;
exports.join = join; exports.join = join;
exports.JSONtoCSV = JSONtoCSV;
exports.JSONToFile = JSONToFile;
exports.last = last; exports.last = last;
exports.lcm = lcm; exports.lcm = lcm;
exports.longestItem = longestItem; exports.longestItem = longestItem;
@ -1586,8 +1590,8 @@
exports.omit = omit; exports.omit = omit;
exports.omitBy = omitBy; exports.omitBy = omitBy;
exports.on = on; exports.on = on;
exports.once = once;
exports.onUserInputChange = onUserInputChange; exports.onUserInputChange = onUserInputChange;
exports.once = once;
exports.orderBy = orderBy; exports.orderBy = orderBy;
exports.over = over; exports.over = over;
exports.overArgs = overArgs; exports.overArgs = overArgs;
@ -1622,15 +1626,14 @@
exports.rearg = rearg; exports.rearg = rearg;
exports.recordAnimationFrames = recordAnimationFrames; exports.recordAnimationFrames = recordAnimationFrames;
exports.redirect = redirect; exports.redirect = redirect;
exports.reducedFilter = reducedFilter;
exports.reduceSuccessive = reduceSuccessive; exports.reduceSuccessive = reduceSuccessive;
exports.reduceWhich = reduceWhich; exports.reduceWhich = reduceWhich;
exports.reducedFilter = reducedFilter;
exports.reject = reject; exports.reject = reject;
exports.remove = remove; exports.remove = remove;
exports.removeNonASCII = removeNonASCII; exports.removeNonASCII = removeNonASCII;
exports.renameKeys = renameKeys; exports.renameKeys = renameKeys;
exports.reverseString = reverseString; exports.reverseString = reverseString;
exports.RGBToHex = RGBToHex;
exports.round = round; exports.round = round;
exports.runAsync = runAsync; exports.runAsync = runAsync;
exports.runPromisesInSeries = runPromisesInSeries; exports.runPromisesInSeries = runPromisesInSeries;
@ -1672,19 +1675,19 @@
exports.takeRightWhile = takeRightWhile; exports.takeRightWhile = takeRightWhile;
exports.takeWhile = takeWhile; exports.takeWhile = takeWhile;
exports.throttle = throttle; exports.throttle = throttle;
exports.times = times;
exports.timeTaken = timeTaken; exports.timeTaken = timeTaken;
exports.times = times;
exports.toCamelCase = toCamelCase; exports.toCamelCase = toCamelCase;
exports.toCurrency = toCurrency; exports.toCurrency = toCurrency;
exports.toDecimalMark = toDecimalMark; exports.toDecimalMark = toDecimalMark;
exports.toggleClass = toggleClass;
exports.toHash = toHash; exports.toHash = toHash;
exports.toKebabCase = toKebabCase; exports.toKebabCase = toKebabCase;
exports.tomorrow = tomorrow;
exports.toOrdinalSuffix = toOrdinalSuffix; exports.toOrdinalSuffix = toOrdinalSuffix;
exports.toSafeInteger = toSafeInteger; exports.toSafeInteger = toSafeInteger;
exports.toSnakeCase = toSnakeCase; exports.toSnakeCase = toSnakeCase;
exports.toTitleCase = toTitleCase; exports.toTitleCase = toTitleCase;
exports.toggleClass = toggleClass;
exports.tomorrow = tomorrow;
exports.transform = transform; exports.transform = transform;
exports.triggerEvent = triggerEvent; exports.triggerEvent = triggerEvent;
exports.truncateString = truncateString; exports.truncateString = truncateString;
@ -1704,9 +1707,6 @@
exports.untildify = untildify; exports.untildify = untildify;
exports.unzip = unzip; exports.unzip = unzip;
exports.unzipWith = unzipWith; exports.unzipWith = unzipWith;
exports.URLJoin = URLJoin;
exports.UUIDGeneratorBrowser = UUIDGeneratorBrowser;
exports.UUIDGeneratorNode = UUIDGeneratorNode;
exports.validateNumber = validateNumber; exports.validateNumber = validateNumber;
exports.vectorDistance = vectorDistance; exports.vectorDistance = vectorDistance;
exports.when = when; exports.when = when;

View File

@ -27,7 +27,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "690147b9d4d90d37d9f42ec6596decc3e99eb8104f51d27a392ee3b50041878e" "hash": "0a82f35a23ffb933cfcd29db918081cee7212c80ace6238838a193295f42f60c"
} }
}, },
{ {
@ -386,7 +386,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "b9a0897aca121af7d0705cace7673c27b22ffab5e67890a3e1859b7f28df2500" "hash": "ab66ab76096083ad5861e228065926db7b8aee7f240d12ad00467a78b35f089c"
} }
}, },
{ {
@ -815,6 +815,20 @@
"hash": "9cf10fcda51ff8e1d130b0efa7971549a0d0bb4c24090c5766b82c12e9958604" "hash": "9cf10fcda51ff8e1d130b0efa7971549a0d0bb4c24090c5766b82c12e9958604"
} }
}, },
{
"id": "deepGet",
"type": "snippetListing",
"attributes": {
"tags": [
"object",
"intermediate"
],
"archived": false
},
"meta": {
"hash": "1f7e933fa6c3e1dee4a9523c6d269a352d6ca2532a2f4a43468dc00da92164d9"
}
},
{ {
"id": "deepMapKeys", "id": "deepMapKeys",
"type": "snippetListing", "type": "snippetListing",
@ -897,7 +911,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "2262275b7adcd7d9b2dd8f31da2a3a2dbcc663584928f46131a0d273b587403b" "hash": "ab4d8502aa63a33bfc3e7919125a76d55f85158f6b15e22bfe2653b05ea328d1"
} }
}, },
{ {

View File

@ -27,7 +27,7 @@
"type": "snippet", "type": "snippet",
"attributes": { "attributes": {
"fileName": "allEqual.md", "fileName": "allEqual.md",
"text": "Check if all elements in an array are equal.\n\nUse `Array.prototype.every()` to check if all the elements of the array are the same as the first one.", "text": "Check if all elements in an array are equal.\n\nUse `Array.prototype.every()` to check if all the elements of the array are the same as the first one.\nElements in the array are compared using the strict comparison operator, which does not account for `NaN` self-inequality.",
"codeBlocks": { "codeBlocks": {
"es6": "const allEqual = arr => arr.every(val => val === arr[0]);", "es6": "const allEqual = arr => arr.every(val => val === arr[0]);",
"es5": "var allEqual = function allEqual(arr) {\n return arr.every(function (val) {\n return val === arr[0];\n });\n};", "es5": "var allEqual = function allEqual(arr) {\n return arr.every(function (val) {\n return val === arr[0];\n });\n};",
@ -41,7 +41,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "690147b9d4d90d37d9f42ec6596decc3e99eb8104f51d27a392ee3b50041878e" "hash": "0a82f35a23ffb933cfcd29db918081cee7212c80ace6238838a193295f42f60c"
} }
}, },
{ {
@ -568,7 +568,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "b9a0897aca121af7d0705cace7673c27b22ffab5e67890a3e1859b7f28df2500" "hash": "ab66ab76096083ad5861e228065926db7b8aee7f240d12ad00467a78b35f089c"
} }
}, },
{ {
@ -1200,6 +1200,27 @@
"hash": "9cf10fcda51ff8e1d130b0efa7971549a0d0bb4c24090c5766b82c12e9958604" "hash": "9cf10fcda51ff8e1d130b0efa7971549a0d0bb4c24090c5766b82c12e9958604"
} }
}, },
{
"id": "deepGet",
"type": "snippet",
"attributes": {
"fileName": "deepGet.md",
"text": "Returns the target value in a nested JSON object, based on the `keys` array.\n\nCompare the keys you want in the nested JSON object as an `Array`.\nUse `Array.prototype.reduce()` to get value from nested JSON object one by one. \nIf the key exists in object, return target value, otherwise, return `null`.",
"codeBlocks": {
"es6": "const deepGet = (obj, keys) => keys.reduce((xs, x) => (xs && xs[x] ? xs[x] : null), obj);",
"es5": "var deepGet = function deepGet(obj, keys) {\n return keys.reduce(function (xs, x) {\n return xs && xs[x] ? xs[x] : null;\n }, obj);\n};",
"example": "let index = 2;\nconst data = {\n foo: {\n foz: [1, 2, 3],\n bar: {\n baz: ['a', 'b', 'c']\n }\n }\n};\ndeepGet(data, ['foo', 'foz', index]); // get 3\ndeepGet(data, ['foo', 'bar', 'baz', 8, 'foz']); // null"
},
"tags": [
"object",
"intermediate"
]
},
"meta": {
"archived": false,
"hash": "1f7e933fa6c3e1dee4a9523c6d269a352d6ca2532a2f4a43468dc00da92164d9"
}
},
{ {
"id": "deepMapKeys", "id": "deepMapKeys",
"type": "snippet", "type": "snippet",
@ -1311,7 +1332,7 @@
"type": "snippet", "type": "snippet",
"attributes": { "attributes": {
"fileName": "detectDeviceType.md", "fileName": "detectDeviceType.md",
"text": "Detects wether the website is being opened in a mobile device or a desktop/laptop.\n\nUse a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop.", "text": "Detects whether the website is being opened in a mobile device or a desktop/laptop.\n\nUse a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop.",
"codeBlocks": { "codeBlocks": {
"es6": "const detectDeviceType = () =>\n /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)\n ? 'Mobile'\n : 'Desktop';", "es6": "const detectDeviceType = () =>\n /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)\n ? 'Mobile'\n : 'Desktop';",
"es5": "var detectDeviceType = function detectDeviceType() {\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 'Mobile' : 'Desktop';\n};", "es5": "var detectDeviceType = function detectDeviceType() {\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 'Mobile' : 'Desktop';\n};",
@ -1324,7 +1345,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "2262275b7adcd7d9b2dd8f31da2a3a2dbcc663584928f46131a0d273b587403b" "hash": "ab4d8502aa63a33bfc3e7919125a76d55f85158f6b15e22bfe2653b05ea328d1"
} }
}, },
{ {

View File

@ -11,7 +11,7 @@
"body": [ "body": [
"const allEqual = arr => arr.every(val => val === arr[0]);" "const allEqual = arr => arr.every(val => val === arr[0]);"
], ],
"description": "Check if all elements in an array are equal.\n\nUse `Array.prototype.every()` to check if all the elements of the array are the same as the first one" "description": "Check if all elements in an array are equal.\n\nUse `Array.prototype.every()` to check if all the elements of the array are the same as the first one.\nElements in the array are compared using the strict comparison operator, which does not account for `NaN` self-inequality"
}, },
"any": { "any": {
"prefix": "30s_any", "prefix": "30s_any",
@ -534,6 +534,13 @@
], ],
"description": "Deep freezes an object.\n\nCalls `Object.freeze(obj)` recursively on all unfrozen properties of passed object that are `instanceof` object" "description": "Deep freezes an object.\n\nCalls `Object.freeze(obj)` recursively on all unfrozen properties of passed object that are `instanceof` object"
}, },
"deepGet": {
"prefix": "30s_deepGet",
"body": [
"const deepGet = (obj, keys) => keys.reduce((xs, x) => (xs && xs[x] ? xs[x] : null), obj);"
],
"description": "Returns the target value in a nested JSON object, based on the `keys` array.\n\nCompare the keys you want in the nested JSON object as an `Array`.\nUse `Array.prototype.reduce()` to get value from nested JSON object one by one. \nIf the key exists in object, return target value, otherwise, return `null`"
},
"deepMapKeys": { "deepMapKeys": {
"prefix": "30s_deepMapKeys", "prefix": "30s_deepMapKeys",
"body": [ "body": [
@ -587,7 +594,7 @@
" ? 'Mobile'", " ? 'Mobile'",
" : 'Desktop';" " : 'Desktop';"
], ],
"description": "Detects wether the website is being opened in a mobile device or a desktop/laptop.\n\nUse a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop" "description": "Detects whether the website is being opened in a mobile device or a desktop/laptop.\n\nUse a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop"
}, },
"difference": { "difference": {
"prefix": "30s_difference", "prefix": "30s_difference",