Fixed issues with deepClone, built everything
This commit is contained in:
188
dist/_30s.js
vendored
188
dist/_30s.js
vendored
@ -7,51 +7,6 @@
|
||||
const fs = typeof require !== "undefined" && require('fs');
|
||||
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 allEqual = arr => arr.every(val => val === arr[0]);
|
||||
const any = (arr, fn = Boolean) => arr.some(fn);
|
||||
@ -175,7 +130,6 @@
|
||||
acc[val] = (acc[val] || 0) + 1;
|
||||
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) => {
|
||||
let current = start,
|
||||
_step = (end - start) * step < 0 ? -step : step,
|
||||
@ -187,6 +141,7 @@
|
||||
}, Math.abs(Math.floor(duration / (end - start))));
|
||||
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 createElement = str => {
|
||||
const el = document.createElement('div');
|
||||
@ -207,6 +162,21 @@
|
||||
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 curry = (fn, arity = fn.length, ...args) =>
|
||||
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
|
||||
@ -226,7 +196,7 @@
|
||||
Object.keys(clone).forEach(
|
||||
key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key])
|
||||
);
|
||||
return Array.isArray(obj) ? (clone.length = obj.length) && Array.from(clone) : clone;
|
||||
return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone;
|
||||
};
|
||||
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||
const deepFreeze = obj =>
|
||||
@ -380,11 +350,6 @@
|
||||
.slice(0)
|
||||
.reverse()
|
||||
.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 formatDuration = ms => {
|
||||
if (ms < 0) ms = -ms;
|
||||
const time = {
|
||||
@ -399,6 +364,11 @@
|
||||
.map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
|
||||
.join(', ');
|
||||
};
|
||||
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 = '_') =>
|
||||
str
|
||||
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
|
||||
@ -527,10 +497,6 @@
|
||||
for (let i = 0; i < iterations; i++) fn();
|
||||
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 indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...acc, i] : acc), []);
|
||||
const initial = arr => arr.slice(0, -1);
|
||||
@ -547,6 +513,10 @@
|
||||
args.length === 0
|
||||
? val
|
||||
: 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 insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString);
|
||||
const intersection = (a, b) => {
|
||||
@ -658,6 +628,18 @@
|
||||
: 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 lcm = (...arr) => {
|
||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||
@ -790,6 +772,14 @@
|
||||
el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false);
|
||||
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 => {
|
||||
let type = 'mouse',
|
||||
lastTime = 0;
|
||||
@ -804,14 +794,6 @@
|
||||
(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) =>
|
||||
[...arr].sort((a, b) =>
|
||||
props.reduce((acc, prop, i) => {
|
||||
@ -970,10 +952,6 @@
|
||||
};
|
||||
const redirect = (url, asLink = true) =>
|
||||
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) =>
|
||||
data.filter(fn).map(el =>
|
||||
keys.reduce((acc, key) => {
|
||||
@ -981,6 +959,10 @@
|
||||
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 remove = (arr, func) =>
|
||||
Array.isArray(arr)
|
||||
@ -999,6 +981,7 @@
|
||||
{}
|
||||
);
|
||||
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 runAsync = fn => {
|
||||
const worker = new Worker(
|
||||
@ -1173,16 +1156,16 @@
|
||||
}
|
||||
};
|
||||
};
|
||||
const times = (n, fn, context = undefined) => {
|
||||
let i = 0;
|
||||
while (fn.call(context, i) !== false && ++i < n) {}
|
||||
};
|
||||
const timeTaken = callback => {
|
||||
console.time('timeTaken');
|
||||
const r = callback();
|
||||
console.timeEnd('timeTaken');
|
||||
return r;
|
||||
};
|
||||
const times = (n, fn, context = undefined) => {
|
||||
let i = 0;
|
||||
while (fn.call(context, i) !== false && ++i < n) {}
|
||||
};
|
||||
const toCamelCase = str => {
|
||||
let s =
|
||||
str &&
|
||||
@ -1195,6 +1178,7 @@
|
||||
const toCurrency = (n, curr, LanguageFormat = undefined) =>
|
||||
Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
|
||||
const toDecimalMark = num => num.toLocaleString('en-US');
|
||||
const toggleClass = (el, className) => el.classList.toggle(className);
|
||||
const toHash = (object, key) =>
|
||||
Array.prototype.reduce.call(
|
||||
object,
|
||||
@ -1207,6 +1191,11 @@
|
||||
.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())
|
||||
.join('-');
|
||||
const tomorrow = () => {
|
||||
let t = new Date();
|
||||
t.setDate(t.getDate() + 1);
|
||||
return t.toISOString().split('T')[0];
|
||||
};
|
||||
const toOrdinalSuffix = num => {
|
||||
const int = parseInt(num),
|
||||
digits = [int % 10, int % 100],
|
||||
@ -1230,12 +1219,6 @@
|
||||
.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))
|
||||
.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 triggerEvent = (el, eventType, detail) =>
|
||||
el.dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
@ -1320,6 +1303,23 @@
|
||||
}).map(x => [])
|
||||
)
|
||||
.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 when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x);
|
||||
const without = (arr, ...args) => arr.filter(v => !args.includes(v));
|
||||
@ -1343,14 +1343,6 @@
|
||||
);
|
||||
};
|
||||
|
||||
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.allEqual = allEqual;
|
||||
exports.any = any;
|
||||
@ -1390,11 +1382,13 @@
|
||||
exports.converge = converge;
|
||||
exports.copyToClipboard = copyToClipboard;
|
||||
exports.countBy = countBy;
|
||||
exports.countOccurrences = countOccurrences;
|
||||
exports.counter = counter;
|
||||
exports.countOccurrences = countOccurrences;
|
||||
exports.createDirIfNotExists = createDirIfNotExists;
|
||||
exports.createElement = createElement;
|
||||
exports.createEventHub = createEventHub;
|
||||
exports.CSVToArray = CSVToArray;
|
||||
exports.CSVToJSON = CSVToJSON;
|
||||
exports.currentURL = currentURL;
|
||||
exports.curry = curry;
|
||||
exports.dayOfYear = dayOfYear;
|
||||
@ -1440,9 +1434,9 @@
|
||||
exports.flattenObject = flattenObject;
|
||||
exports.flip = flip;
|
||||
exports.forEachRight = forEachRight;
|
||||
exports.formatDuration = formatDuration;
|
||||
exports.forOwn = forOwn;
|
||||
exports.forOwnRight = forOwnRight;
|
||||
exports.formatDuration = formatDuration;
|
||||
exports.fromCamelCase = fromCamelCase;
|
||||
exports.functionName = functionName;
|
||||
exports.functions = functions;
|
||||
@ -1470,7 +1464,6 @@
|
||||
exports.httpPost = httpPost;
|
||||
exports.httpsRedirect = httpsRedirect;
|
||||
exports.hz = hz;
|
||||
exports.inRange = inRange;
|
||||
exports.indentString = indentString;
|
||||
exports.indexOfAll = indexOfAll;
|
||||
exports.initial = initial;
|
||||
@ -1479,6 +1472,7 @@
|
||||
exports.initializeArrayWithRangeRight = initializeArrayWithRangeRight;
|
||||
exports.initializeArrayWithValues = initializeArrayWithValues;
|
||||
exports.initializeNDArray = initializeNDArray;
|
||||
exports.inRange = inRange;
|
||||
exports.insertAfter = insertAfter;
|
||||
exports.insertBefore = insertBefore;
|
||||
exports.intersection = intersection;
|
||||
@ -1522,6 +1516,8 @@
|
||||
exports.isValidJSON = isValidJSON;
|
||||
exports.isWritableStream = isWritableStream;
|
||||
exports.join = join;
|
||||
exports.JSONtoCSV = JSONtoCSV;
|
||||
exports.JSONToFile = JSONToFile;
|
||||
exports.last = last;
|
||||
exports.lcm = lcm;
|
||||
exports.longestItem = longestItem;
|
||||
@ -1559,8 +1555,8 @@
|
||||
exports.omit = omit;
|
||||
exports.omitBy = omitBy;
|
||||
exports.on = on;
|
||||
exports.onUserInputChange = onUserInputChange;
|
||||
exports.once = once;
|
||||
exports.onUserInputChange = onUserInputChange;
|
||||
exports.orderBy = orderBy;
|
||||
exports.over = over;
|
||||
exports.overArgs = overArgs;
|
||||
@ -1595,14 +1591,15 @@
|
||||
exports.rearg = rearg;
|
||||
exports.recordAnimationFrames = recordAnimationFrames;
|
||||
exports.redirect = redirect;
|
||||
exports.reducedFilter = reducedFilter;
|
||||
exports.reduceSuccessive = reduceSuccessive;
|
||||
exports.reduceWhich = reduceWhich;
|
||||
exports.reducedFilter = reducedFilter;
|
||||
exports.reject = reject;
|
||||
exports.remove = remove;
|
||||
exports.removeNonASCII = removeNonASCII;
|
||||
exports.renameKeys = renameKeys;
|
||||
exports.reverseString = reverseString;
|
||||
exports.RGBToHex = RGBToHex;
|
||||
exports.round = round;
|
||||
exports.runAsync = runAsync;
|
||||
exports.runPromisesInSeries = runPromisesInSeries;
|
||||
@ -1643,19 +1640,19 @@
|
||||
exports.takeRightWhile = takeRightWhile;
|
||||
exports.takeWhile = takeWhile;
|
||||
exports.throttle = throttle;
|
||||
exports.timeTaken = timeTaken;
|
||||
exports.times = times;
|
||||
exports.timeTaken = timeTaken;
|
||||
exports.toCamelCase = toCamelCase;
|
||||
exports.toCurrency = toCurrency;
|
||||
exports.toDecimalMark = toDecimalMark;
|
||||
exports.toggleClass = toggleClass;
|
||||
exports.toHash = toHash;
|
||||
exports.toKebabCase = toKebabCase;
|
||||
exports.tomorrow = tomorrow;
|
||||
exports.toOrdinalSuffix = toOrdinalSuffix;
|
||||
exports.toSafeInteger = toSafeInteger;
|
||||
exports.toSnakeCase = toSnakeCase;
|
||||
exports.toTitleCase = toTitleCase;
|
||||
exports.toggleClass = toggleClass;
|
||||
exports.tomorrow = tomorrow;
|
||||
exports.transform = transform;
|
||||
exports.triggerEvent = triggerEvent;
|
||||
exports.truncateString = truncateString;
|
||||
@ -1675,6 +1672,9 @@
|
||||
exports.untildify = untildify;
|
||||
exports.unzip = unzip;
|
||||
exports.unzipWith = unzipWith;
|
||||
exports.URLJoin = URLJoin;
|
||||
exports.UUIDGeneratorBrowser = UUIDGeneratorBrowser;
|
||||
exports.UUIDGeneratorNode = UUIDGeneratorNode;
|
||||
exports.validateNumber = validateNumber;
|
||||
exports.when = when;
|
||||
exports.without = without;
|
||||
|
||||
Reference in New Issue
Block a user