Codacy style changes for test files
This commit is contained in:
@ -52,15 +52,15 @@ snippetFiles
|
|||||||
const fileFunction = fileCode
|
const fileFunction = fileCode
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(line => line)
|
.map(line => line)
|
||||||
.filter((_, i) => blockMarkers[0] < i && i < blockMarkers[1]).concat('');
|
.filter((_, i) => blockMarkers[0] < i && i < blockMarkers[1]);
|
||||||
// Grab snippet example based on code markers
|
// Grab snippet example based on code markers
|
||||||
const fileExample = fileCode
|
const fileExample = fileCode
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(line => line)
|
.map(line => line)
|
||||||
.filter((_, i) => blockMarkers[2] < i && i < blockMarkers[3]).concat('');
|
.filter((_, i) => blockMarkers[2] < i && i < blockMarkers[3]);
|
||||||
|
|
||||||
// Export template for snippetName.js
|
// Export template for snippetName.js
|
||||||
const exportFile = `${fileFunction.join('\n')}\nmodule.exports = ${fileName};`.trim();
|
const exportFile = `${fileFunction.join('\n')}\nmodule.exports = ${fileName};\n`;
|
||||||
|
|
||||||
// Export template for snippetName.test.js which generates a example test & other information
|
// Export template for snippetName.test.js which generates a example test & other information
|
||||||
const exportTest = [
|
const exportTest = [
|
||||||
@ -68,7 +68,7 @@ snippetFiles
|
|||||||
`const ${fileName} = require('./${fileName}.js');`,
|
`const ${fileName} = require('./${fileName}.js');`,
|
||||||
`\ntest('${fileName} is a Function', () => {`,
|
`\ntest('${fileName} is a Function', () => {`,
|
||||||
` expect(${fileName}).toBeInstanceOf(Function);`,
|
` expect(${fileName}).toBeInstanceOf(Function);`,
|
||||||
`});`
|
`});\n`
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
// Write/Update exportFile which is snippetName.js in respective dir
|
// Write/Update exportFile which is snippetName.js in respective dir
|
||||||
|
|||||||
@ -3,5 +3,4 @@ const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
|
|||||||
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
|
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(v => v.split(delimiter));
|
.map(v => v.split(delimiter));
|
||||||
|
|
||||||
module.exports = CSVToArray;
|
module.exports = CSVToArray;
|
||||||
@ -8,5 +8,4 @@ const CSVToJSON = (data, delimiter = ',') => {
|
|||||||
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {});
|
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = CSVToJSON;
|
module.exports = CSVToJSON;
|
||||||
@ -2,5 +2,4 @@ const JSONToDate = arr => {
|
|||||||
const dt = new Date(parseInt(arr.toString().substr(6)));
|
const dt = new Date(parseInt(arr.toString().substr(6)));
|
||||||
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = JSONToDate;
|
module.exports = JSONToDate;
|
||||||
@ -1,5 +1,4 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const JSONToFile = (obj, filename) =>
|
const JSONToFile = (obj, filename) =>
|
||||||
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
||||||
|
|
||||||
module.exports = JSONToFile;
|
module.exports = JSONToFile;
|
||||||
@ -8,5 +8,4 @@ const JSONtoCSV = (arr, columns, delimiter = ',') =>
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
module.exports = JSONtoCSV;
|
module.exports = JSONtoCSV;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
||||||
|
|
||||||
module.exports = RGBToHex;
|
module.exports = RGBToHex;
|
||||||
@ -7,5 +7,4 @@ const URLJoin = (...args) =>
|
|||||||
.replace(/\/(\?|&|#[^!])/g, '$1')
|
.replace(/\/(\?|&|#[^!])/g, '$1')
|
||||||
.replace(/\?/g, '&')
|
.replace(/\?/g, '&')
|
||||||
.replace('&', '?');
|
.replace('&', '?');
|
||||||
|
|
||||||
module.exports = URLJoin;
|
module.exports = URLJoin;
|
||||||
@ -2,5 +2,4 @@ const UUIDGeneratorBrowser = () =>
|
|||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = UUIDGeneratorBrowser;
|
module.exports = UUIDGeneratorBrowser;
|
||||||
@ -3,5 +3,4 @@ const UUIDGeneratorNode = () =>
|
|||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = UUIDGeneratorNode;
|
module.exports = UUIDGeneratorNode;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const all = (arr, fn = Boolean) => arr.every(fn);
|
const all = (arr, fn = Boolean) => arr.every(fn);
|
||||||
|
|
||||||
module.exports = all;
|
module.exports = all;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const any = (arr, fn = Boolean) => arr.some(fn);
|
const any = (arr, fn = Boolean) => arr.some(fn);
|
||||||
|
|
||||||
module.exports = any;
|
module.exports = any;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||||
|
|
||||||
module.exports = approximatelyEqual;
|
module.exports = approximatelyEqual;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const arrayToCSV = (arr, delimiter = ',') =>
|
const arrayToCSV = (arr, delimiter = ',') =>
|
||||||
arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n');
|
arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n');
|
||||||
|
|
||||||
module.exports = arrayToCSV;
|
module.exports = arrayToCSV;
|
||||||
@ -3,5 +3,4 @@ const arrayToHtmlList = (arr, listID) =>
|
|||||||
(el = document.querySelector('#' + listID)),
|
(el = document.querySelector('#' + listID)),
|
||||||
(el.innerHTML += arr.map(item => `<li>${item}</li>`).join(''))
|
(el.innerHTML += arr.map(item => `<li>${item}</li>`).join(''))
|
||||||
))();
|
))();
|
||||||
|
|
||||||
module.exports = arrayToHtmlList;
|
module.exports = arrayToHtmlList;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const ary = (fn, n) => (...args) => fn(...args.slice(0, n));
|
const ary = (fn, n) => (...args) => fn(...args.slice(0, n));
|
||||||
|
|
||||||
module.exports = ary;
|
module.exports = ary;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const atob = str => new Buffer(str, 'base64').toString('binary');
|
const atob = str => new Buffer(str, 'base64').toString('binary');
|
||||||
|
|
||||||
module.exports = atob;
|
module.exports = atob;
|
||||||
@ -5,5 +5,4 @@ const attempt = (fn, ...args) => {
|
|||||||
return e instanceof Error ? e : new Error(e);
|
return e instanceof Error ? e : new Error(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = attempt;
|
module.exports = attempt;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
|
const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
|
||||||
|
|
||||||
module.exports = average;
|
module.exports = average;
|
||||||
@ -1,5 +1,4 @@
|
|||||||
const averageBy = (arr, fn) =>
|
const averageBy = (arr, fn) =>
|
||||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
||||||
arr.length;
|
arr.length;
|
||||||
|
|
||||||
module.exports = averageBy;
|
module.exports = averageBy;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const bifurcate = (arr, filter) =>
|
const bifurcate = (arr, filter) =>
|
||||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||||
|
|
||||||
module.exports = bifurcate;
|
module.exports = bifurcate;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const bifurcateBy = (arr, fn) =>
|
const bifurcateBy = (arr, fn) =>
|
||||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||||
|
|
||||||
module.exports = bifurcateBy;
|
module.exports = bifurcateBy;
|
||||||
@ -5,5 +5,4 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
|||||||
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
|
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
|
||||||
return mid;
|
return mid;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = binarySearch;
|
module.exports = binarySearch;
|
||||||
@ -2,5 +2,4 @@ const bind = (fn, context, ...args) =>
|
|||||||
function() {
|
function() {
|
||||||
return fn.apply(context, args.concat(...arguments));
|
return fn.apply(context, args.concat(...arguments));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = bind;
|
module.exports = bind;
|
||||||
@ -7,5 +7,4 @@ const bindAll = (obj, ...fns) =>
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = bindAll;
|
module.exports = bindAll;
|
||||||
@ -2,5 +2,4 @@ const bindKey = (context, fn, ...args) =>
|
|||||||
function() {
|
function() {
|
||||||
return context[fn].apply(context, args.concat(...arguments));
|
return context[fn].apply(context, args.concat(...arguments));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = bindKey;
|
module.exports = bindKey;
|
||||||
@ -8,5 +8,4 @@ const binomialCoefficient = (n, k) => {
|
|||||||
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
||||||
return Math.round(res);
|
return Math.round(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = binomialCoefficient;
|
module.exports = binomialCoefficient;
|
||||||
@ -1,5 +1,4 @@
|
|||||||
const bottomVisible = () =>
|
const bottomVisible = () =>
|
||||||
document.documentElement.clientHeight + window.scrollY >=
|
document.documentElement.clientHeight + window.scrollY >=
|
||||||
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
||||||
|
|
||||||
module.exports = bottomVisible;
|
module.exports = bottomVisible;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const btoa = str => new Buffer(str, 'binary').toString('base64');
|
const btoa = str => new Buffer(str, 'binary').toString('base64');
|
||||||
|
|
||||||
module.exports = btoa;
|
module.exports = btoa;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const byteSize = str => new Blob([str]).size;
|
const byteSize = str => new Blob([str]).size;
|
||||||
|
|
||||||
module.exports = byteSize;
|
module.exports = byteSize;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const call = (key, ...args) => context => context[key](...args);
|
const call = (key, ...args) => context => context[key](...args);
|
||||||
|
|
||||||
module.exports = call;
|
module.exports = call;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const capitalize = ([first, ...rest], lowerRest = false) =>
|
const capitalize = ([first, ...rest], lowerRest = false) =>
|
||||||
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
||||||
|
|
||||||
module.exports = capitalize;
|
module.exports = capitalize;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
||||||
|
|
||||||
module.exports = capitalizeEveryWord;
|
module.exports = capitalizeEveryWord;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const castArray = val => (Array.isArray(val) ? val : [val]);
|
const castArray = val => (Array.isArray(val) ? val : [val]);
|
||||||
|
|
||||||
module.exports = castArray;
|
module.exports = castArray;
|
||||||
@ -3,5 +3,4 @@ const chainAsync = fns => {
|
|||||||
const next = () => fns[curr++](next);
|
const next = () => fns[curr++](next);
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = chainAsync;
|
module.exports = chainAsync;
|
||||||
@ -2,5 +2,4 @@ const chunk = (arr, size) =>
|
|||||||
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
|
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
|
||||||
arr.slice(i * size, i * size + size)
|
arr.slice(i * size, i * size + size)
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = chunk;
|
module.exports = chunk;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
||||||
|
|
||||||
module.exports = clampNumber;
|
module.exports = clampNumber;
|
||||||
@ -8,5 +8,4 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
|||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = cleanObj;
|
module.exports = cleanObj;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||||
|
|
||||||
module.exports = cloneRegExp;
|
module.exports = cloneRegExp;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
||||||
|
|
||||||
module.exports = coalesce;
|
module.exports = coalesce;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const coalesceFactory = valid => (...args) => args.find(valid);
|
const coalesceFactory = valid => (...args) => args.find(valid);
|
||||||
|
|
||||||
module.exports = coalesceFactory;
|
module.exports = coalesceFactory;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
|
const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
|
||||||
|
|
||||||
module.exports = collatz;
|
module.exports = collatz;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const collectInto = fn => (...args) => fn(args);
|
const collectInto = fn => (...args) => fn(args);
|
||||||
|
|
||||||
module.exports = collectInto;
|
module.exports = collectInto;
|
||||||
@ -16,5 +16,4 @@ const colorize = (...args) => ({
|
|||||||
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
||||||
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = colorize;
|
module.exports = colorize;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const compact = arr => arr.filter(Boolean);
|
const compact = arr => arr.filter(Boolean);
|
||||||
|
|
||||||
module.exports = compact;
|
module.exports = compact;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
||||||
|
|
||||||
module.exports = compose;
|
module.exports = compose;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
||||||
|
|
||||||
module.exports = composeRight;
|
module.exports = composeRight;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
|
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
|
||||||
|
|
||||||
module.exports = converge;
|
module.exports = converge;
|
||||||
@ -15,5 +15,4 @@ const copyToClipboard = str => {
|
|||||||
document.getSelection().addRange(selected);
|
document.getSelection().addRange(selected);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = copyToClipboard;
|
module.exports = copyToClipboard;
|
||||||
@ -3,5 +3,4 @@ const countBy = (arr, fn) =>
|
|||||||
acc[val] = (acc[val] || 0) + 1;
|
acc[val] = (acc[val] || 0) + 1;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
module.exports = countBy;
|
module.exports = countBy;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
||||||
|
|
||||||
module.exports = countOccurrences;
|
module.exports = countOccurrences;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
||||||
|
|
||||||
module.exports = countVowels;
|
module.exports = countVowels;
|
||||||
@ -9,5 +9,4 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = counter;
|
module.exports = counter;
|
||||||
@ -3,5 +3,4 @@ const createElement = str => {
|
|||||||
el.innerHTML = str;
|
el.innerHTML = str;
|
||||||
return el.firstElementChild;
|
return el.firstElementChild;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = createElement;
|
module.exports = createElement;
|
||||||
@ -12,5 +12,4 @@ const createEventHub = () => ({
|
|||||||
if (i > -1) this.hub[event].splice(i, 1);
|
if (i > -1) this.hub[event].splice(i, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = createEventHub;
|
module.exports = createEventHub;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const currentURL = () => window.location.href;
|
const currentURL = () => window.location.href;
|
||||||
|
|
||||||
module.exports = currentURL;
|
module.exports = currentURL;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
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);
|
||||||
|
|
||||||
module.exports = curry;
|
module.exports = curry;
|
||||||
@ -5,5 +5,4 @@ const debounce = (fn, ms = 0) => {
|
|||||||
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = debounce;
|
module.exports = debounce;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const decapitalize = ([first, ...rest], upperRest = false) =>
|
const decapitalize = ([first, ...rest], upperRest = false) =>
|
||||||
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
|
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
|
||||||
|
|
||||||
module.exports = decapitalize;
|
module.exports = decapitalize;
|
||||||
@ -5,5 +5,4 @@ const deepClone = obj => {
|
|||||||
);
|
);
|
||||||
return Array.isArray(obj) ? (clone.length = obj.length) && Array.from(clone) : clone;
|
return Array.isArray(obj) ? (clone.length = obj.length) && Array.from(clone) : clone;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = deepClone;
|
module.exports = deepClone;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||||
|
|
||||||
module.exports = deepFlatten;
|
module.exports = deepFlatten;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
||||||
|
|
||||||
module.exports = defaults;
|
module.exports = defaults;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
|
|
||||||
module.exports = defer;
|
module.exports = defer;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const degreesToRads = deg => (deg * Math.PI) / 180.0;
|
const degreesToRads = deg => (deg * Math.PI) / 180.0;
|
||||||
|
|
||||||
module.exports = degreesToRads;
|
module.exports = degreesToRads;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args);
|
const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args);
|
||||||
|
|
||||||
module.exports = delay;
|
module.exports = delay;
|
||||||
@ -2,5 +2,4 @@ const detectDeviceType = () =>
|
|||||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||||
? 'Mobile'
|
? 'Mobile'
|
||||||
: 'Desktop';
|
: 'Desktop';
|
||||||
|
|
||||||
module.exports = detectDeviceType;
|
module.exports = detectDeviceType;
|
||||||
@ -2,5 +2,4 @@ const difference = (a, b) => {
|
|||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => !s.has(x));
|
return a.filter(x => !s.has(x));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = difference;
|
module.exports = difference;
|
||||||
@ -2,5 +2,4 @@ const differenceBy = (a, b, fn) => {
|
|||||||
const s = new Set(b.map(v => fn(v)));
|
const s = new Set(b.map(v => fn(v)));
|
||||||
return a.filter(x => !s.has(fn(x)));
|
return a.filter(x => !s.has(fn(x)));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = differenceBy;
|
module.exports = differenceBy;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
|
const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
|
||||||
|
|
||||||
module.exports = differenceWith;
|
module.exports = differenceWith;
|
||||||
@ -5,5 +5,4 @@ const dig = (obj, target) =>
|
|||||||
if (acc !== undefined) return acc;
|
if (acc !== undefined) return acc;
|
||||||
if (typeof val === 'object') return dig(val, target);
|
if (typeof val === 'object') return dig(val, target);
|
||||||
}, undefined);
|
}, undefined);
|
||||||
|
|
||||||
module.exports = dig;
|
module.exports = dig;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const digitize = n => [...`${n}`].map(i => parseInt(i));
|
const digitize = n => [...`${n}`].map(i => parseInt(i));
|
||||||
|
|
||||||
module.exports = digitize;
|
module.exports = digitize;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
|
|
||||||
module.exports = distance;
|
module.exports = distance;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const drop = (arr, n = 1) => arr.slice(n);
|
const drop = (arr, n = 1) => arr.slice(n);
|
||||||
|
|
||||||
module.exports = drop;
|
module.exports = drop;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const dropRight = (arr, n = 1) => arr.slice(0, -n);
|
const dropRight = (arr, n = 1) => arr.slice(0, -n);
|
||||||
|
|
||||||
module.exports = dropRight;
|
module.exports = dropRight;
|
||||||
@ -2,5 +2,4 @@ const dropRightWhile = (arr, func) => {
|
|||||||
while (arr.length > 0 && !func(arr[arr.length - 1])) arr = arr.slice(0, -1);
|
while (arr.length > 0 && !func(arr[arr.length - 1])) arr = arr.slice(0, -1);
|
||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = dropRightWhile;
|
module.exports = dropRightWhile;
|
||||||
@ -2,5 +2,4 @@ const dropWhile = (arr, func) => {
|
|||||||
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
|
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
|
||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = dropWhile;
|
module.exports = dropWhile;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const elementContains = (parent, child) => parent !== child && parent.contains(child);
|
const elementContains = (parent, child) => parent !== child && parent.contains(child);
|
||||||
|
|
||||||
module.exports = elementContains;
|
module.exports = elementContains;
|
||||||
@ -6,5 +6,4 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
|||||||
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
|
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
|
||||||
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = elementIsVisibleInViewport;
|
module.exports = elementIsVisibleInViewport;
|
||||||
@ -15,5 +15,4 @@ const elo = ([...ratings], kFactor = 32, selfRating) => {
|
|||||||
}
|
}
|
||||||
return ratings;
|
return ratings;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = elo;
|
module.exports = elo;
|
||||||
@ -8,5 +8,4 @@ const equals = (a, b) => {
|
|||||||
if (keys.length !== Object.keys(b).length) return false;
|
if (keys.length !== Object.keys(b).length) return false;
|
||||||
return keys.every(k => equals(a[k], b[k]));
|
return keys.every(k => equals(a[k], b[k]));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = equals;
|
module.exports = equals;
|
||||||
@ -10,5 +10,4 @@ const escapeHTML = str =>
|
|||||||
'"': '"'
|
'"': '"'
|
||||||
}[tag] || tag)
|
}[tag] || tag)
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = escapeHTML;
|
module.exports = escapeHTML;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
|
||||||
module.exports = escapeRegExp;
|
module.exports = escapeRegExp;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
||||||
|
|
||||||
module.exports = everyNth;
|
module.exports = everyNth;
|
||||||
@ -5,5 +5,4 @@ const extendHex = shortHex =>
|
|||||||
.split('')
|
.split('')
|
||||||
.map(x => x + x)
|
.map(x => x + x)
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
module.exports = extendHex;
|
module.exports = extendHex;
|
||||||
@ -6,5 +6,4 @@ const factorial = n =>
|
|||||||
: n <= 1
|
: n <= 1
|
||||||
? 1
|
? 1
|
||||||
: n * factorial(n - 1);
|
: n * factorial(n - 1);
|
||||||
|
|
||||||
module.exports = factorial;
|
module.exports = factorial;
|
||||||
@ -17,5 +17,4 @@ const factors = (num, primes = false) => {
|
|||||||
}, []);
|
}, []);
|
||||||
return primes ? array.filter(isPrime) : array;
|
return primes ? array.filter(isPrime) : array;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = factors;
|
module.exports = factors;
|
||||||
@ -3,5 +3,4 @@ const fibonacci = n =>
|
|||||||
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = fibonacci;
|
module.exports = fibonacci;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const fibonacciCountUntilNum = num =>
|
const fibonacciCountUntilNum = num =>
|
||||||
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
||||||
|
|
||||||
module.exports = fibonacciCountUntilNum;
|
module.exports = fibonacciCountUntilNum;
|
||||||
@ -5,5 +5,4 @@ const fibonacciUntilNum = num => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = fibonacciUntilNum;
|
module.exports = fibonacciUntilNum;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
|
const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
|
||||||
|
|
||||||
module.exports = filterNonUnique;
|
module.exports = filterNonUnique;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const filterNonUniqueBy = (arr, fn) =>
|
const filterNonUniqueBy = (arr, fn) =>
|
||||||
arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j)));
|
arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j)));
|
||||||
|
|
||||||
module.exports = filterNonUniqueBy;
|
module.exports = filterNonUniqueBy;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj));
|
const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj));
|
||||||
|
|
||||||
module.exports = findKey;
|
module.exports = findKey;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const findLast = (arr, fn) => arr.filter(fn).pop();
|
const findLast = (arr, fn) => arr.filter(fn).pop();
|
||||||
|
|
||||||
module.exports = findLast;
|
module.exports = findLast;
|
||||||
@ -3,5 +3,4 @@ const findLastIndex = (arr, fn) =>
|
|||||||
.map((val, i) => [i, val])
|
.map((val, i) => [i, val])
|
||||||
.filter(([i, val]) => fn(val, i, arr))
|
.filter(([i, val]) => fn(val, i, arr))
|
||||||
.pop()[0];
|
.pop()[0];
|
||||||
|
|
||||||
module.exports = findLastIndex;
|
module.exports = findLastIndex;
|
||||||
@ -2,5 +2,4 @@ const findLastKey = (obj, fn) =>
|
|||||||
Object.keys(obj)
|
Object.keys(obj)
|
||||||
.reverse()
|
.reverse()
|
||||||
.find(key => fn(obj[key], key, obj));
|
.find(key => fn(obj[key], key, obj));
|
||||||
|
|
||||||
module.exports = findLastKey;
|
module.exports = findLastKey;
|
||||||
@ -1,4 +1,3 @@
|
|||||||
const flatten = (arr, depth = 1) =>
|
const flatten = (arr, depth = 1) =>
|
||||||
arr.reduce((a, v) => a.concat(depth > 1 && Array.isArray(v) ? flatten(v, depth - 1) : v), []);
|
arr.reduce((a, v) => a.concat(depth > 1 && Array.isArray(v) ? flatten(v, depth - 1) : v), []);
|
||||||
|
|
||||||
module.exports = flatten;
|
module.exports = flatten;
|
||||||
@ -5,5 +5,4 @@ const flattenObject = (obj, prefix = '') =>
|
|||||||
else acc[pre + k] = obj[k];
|
else acc[pre + k] = obj[k];
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
module.exports = flattenObject;
|
module.exports = flattenObject;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const flip = fn => (first, ...rest) => fn(...rest, first);
|
const flip = fn => (first, ...rest) => fn(...rest, first);
|
||||||
|
|
||||||
module.exports = flip;
|
module.exports = flip;
|
||||||
@ -3,5 +3,4 @@ const forEachRight = (arr, callback) =>
|
|||||||
.slice(0)
|
.slice(0)
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach(callback);
|
.forEach(callback);
|
||||||
|
|
||||||
module.exports = forEachRight;
|
module.exports = forEachRight;
|
||||||
@ -1,3 +1,2 @@
|
|||||||
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
|
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
|
||||||
|
|
||||||
module.exports = forOwn;
|
module.exports = forOwn;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user