Updated the test system
This commit is contained in:
@ -14,79 +14,38 @@ if (util.isTravisCI() && util.isNotTravisCronOrAPI()) {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
// Declare paths
|
// Declare paths
|
||||||
const SNIPPETS_ACTIVE = './snippets';
|
const SNIPPETS_PATH = './snippets';
|
||||||
const SNIPPETS_ARCHIVE = './snippets_archive';
|
const SNIPPETS_ARCHIVE_PATH = './snippets_archive';
|
||||||
const TEST_PATH = './test';
|
const TEST_PATH = './test';
|
||||||
|
|
||||||
// Array of snippet names
|
|
||||||
const snippetFiles = [];
|
|
||||||
|
|
||||||
const snippetFilesActive = fs
|
|
||||||
.readdirSync(SNIPPETS_ACTIVE, 'utf8')
|
|
||||||
.map(fileName => fileName.slice(0, -3));
|
|
||||||
const snippetFilesArchive = fs
|
|
||||||
.readdirSync(SNIPPETS_ARCHIVE, 'utf8')
|
|
||||||
.filter(fileName => !fileName.includes('README')) // -> Filters out main README.md file in Archieve which isn't a snippet
|
|
||||||
.map(fileName => fileName.slice(0, -3));
|
|
||||||
|
|
||||||
snippetFiles.push(...snippetFilesActive);
|
|
||||||
snippetFiles.push(...snippetFilesArchive);
|
|
||||||
|
|
||||||
console.time('Tester');
|
console.time('Tester');
|
||||||
snippetFiles
|
try {
|
||||||
.map(fileName => {
|
// Read snippets, archive and tests, find which tests are not defined
|
||||||
// Check if fileName for snippet exist in test/ dir, if doesnt create
|
const snippets = fs.readdirSync(SNIPPETS_PATH).map(v => v.replace('.md', ''));
|
||||||
fs.ensureDirSync(path.join(TEST_PATH, fileName));
|
const archivedSnippets = fs.readdirSync(SNIPPETS_ARCHIVE_PATH).filter(v => v !== 'README.md').map(v => v.replace('.md', ''));
|
||||||
|
const definedTests = fs.readdirSync(TEST_PATH).map(v => v.replace('.test.js', '')).filter(v => v !== '_30s.js' && v !== 'testlog');
|
||||||
// return fileName for later use
|
const undefinedTests = [...snippets, ...archivedSnippets].filter(v => !definedTests.includes(v));
|
||||||
return fileName;
|
const orphanedTests = [...definedTests.filter(v => ![...snippets, ...archivedSnippets].includes(v))];
|
||||||
|
orphanedTests.forEach(snippet => {
|
||||||
|
console.log(`${chalk.yellow('WARNING!')} Orphaned test: ${snippet}`);
|
||||||
})
|
})
|
||||||
.map(fileName => {
|
// Create files for undefined tests
|
||||||
const activeOrArchive = snippetFilesActive.includes(fileName)
|
undefinedTests.forEach(snippet => {
|
||||||
? SNIPPETS_ACTIVE
|
|
||||||
: SNIPPETS_ARCHIVE;
|
|
||||||
// Grab snippetData
|
|
||||||
const fileData = fs.readFileSync(path.join(activeOrArchive, `${fileName}.md`), 'utf8');
|
|
||||||
// Grab snippet Code blocks
|
|
||||||
const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3);
|
|
||||||
// Split code based on code markers
|
|
||||||
const blockMarkers = fileCode
|
|
||||||
.split('\n')
|
|
||||||
.map((line, lineIndex) => (line.slice(0, 3) === '```' ? lineIndex : '//CLEAR//'))
|
|
||||||
.filter(x => !(x === '//CLEAR//'));
|
|
||||||
// Grab snippet function based on code markers
|
|
||||||
const fileFunction = fileCode
|
|
||||||
.split('\n')
|
|
||||||
.map(line => line)
|
|
||||||
.filter((_, i) => blockMarkers[0] < i && i < blockMarkers[1]);
|
|
||||||
|
|
||||||
// Export template for snippetName.js
|
|
||||||
const exportFile = `${fileFunction.join('\n')}\nmodule.exports = ${fileName};\n`;
|
|
||||||
|
|
||||||
// Export template for snippetName.test.js which generates a example test & other information
|
|
||||||
const exportTest = [
|
const exportTest = [
|
||||||
`const expect = require('expect');`,
|
`const expect = require('expect');`,
|
||||||
`const ${fileName} = require('./${fileName}.js');`,
|
`const {${snippet}} = require('._30s.js');`,
|
||||||
`\ntest('${fileName} is a Function', () => {`,
|
`\ntest('${snippet} is a Function', () => {`,
|
||||||
` expect(${fileName}).toBeInstanceOf(Function);`,
|
` expect(${snippet}).toBeInstanceOf(Function);`,
|
||||||
`});\n`
|
`});\n`
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
fs.writeFileSync(path.join(TEST_PATH, `${snippet}.test.js`), exportTest);
|
||||||
// Write/Update exportFile which is snippetName.js in respective dir
|
|
||||||
fs.writeFileSync(path.join(TEST_PATH, fileName, `${fileName}.js`), exportFile);
|
|
||||||
|
|
||||||
if (!fs.existsSync(path.join(TEST_PATH, fileName, `${fileName}.test.js`))) {
|
|
||||||
// if snippetName.test.js doesn't exist inrespective dir exportTest
|
|
||||||
fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.test.js`, exportTest);
|
|
||||||
}
|
|
||||||
|
|
||||||
// return fileName for later use
|
|
||||||
return fileName;
|
|
||||||
});
|
});
|
||||||
try {
|
// Run tests
|
||||||
fs.writeFileSync(path.join(TEST_PATH, 'testlog'), `Test log for: ${new Date().toString()}\n`);
|
fs.writeFileSync(path.join(TEST_PATH, 'testlog'), `Test log for: ${new Date().toString()}\n`);
|
||||||
childProcess.execSync('npm test');
|
childProcess.execSync('npm test');
|
||||||
} catch (e) {
|
console.log(`${chalk.green('SUCCESS!')} All tests ran successfully!`);
|
||||||
fs.appendFileSync(path.join(TEST_PATH, 'testlog'));
|
} catch (err) {
|
||||||
|
console.log(`${chalk.red('ERROR!')} During test runs: ${err}`);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.timeEnd('Tester');
|
console.timeEnd('Tester');
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const CSVToArray = require('./CSVToArray.js');
|
const {CSVToArray} = require('./_30s.js');
|
||||||
|
|
||||||
test('CSVToArray is a Function', () => {
|
test('CSVToArray is a Function', () => {
|
||||||
expect(CSVToArray).toBeInstanceOf(Function);
|
expect(CSVToArray).toBeInstanceOf(Function);
|
||||||
@ -1,6 +0,0 @@
|
|||||||
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
|
|
||||||
data
|
|
||||||
.slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
|
|
||||||
.split('\n')
|
|
||||||
.map(v => v.split(delimiter));
|
|
||||||
module.exports = CSVToArray;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const CSVToJSON = require('./CSVToJSON.js');
|
const {CSVToJSON} = require('./_30s.js');
|
||||||
|
|
||||||
test('CSVToJSON is a Function', () => {
|
test('CSVToJSON is a Function', () => {
|
||||||
expect(CSVToJSON).toBeInstanceOf(Function);
|
expect(CSVToJSON).toBeInstanceOf(Function);
|
||||||
@ -1,11 +0,0 @@
|
|||||||
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), {});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
module.exports = CSVToJSON;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const JSONToDate = require('./JSONToDate.js');
|
const {JSONToDate} = require('./_30s.js');
|
||||||
|
|
||||||
test('JSONToDate is a Function', () => {
|
test('JSONToDate is a Function', () => {
|
||||||
expect(JSONToDate).toBeInstanceOf(Function);
|
expect(JSONToDate).toBeInstanceOf(Function);
|
||||||
@ -1,5 +0,0 @@
|
|||||||
const JSONToDate = arr => {
|
|
||||||
const dt = new Date(parseInt(arr.toString().substr(6)));
|
|
||||||
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
|
||||||
};
|
|
||||||
module.exports = JSONToDate;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const JSONToFile = require('./JSONToFile.js');
|
const {JSONToFile} = require('./_30s.js');
|
||||||
|
|
||||||
test('JSONToFile is a Function', () => {
|
test('JSONToFile is a Function', () => {
|
||||||
expect(JSONToFile).toBeInstanceOf(Function);
|
expect(JSONToFile).toBeInstanceOf(Function);
|
||||||
@ -1,4 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const JSONToFile = (obj, filename) =>
|
|
||||||
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
|
||||||
module.exports = JSONToFile;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const JSONtoCSV = require('./JSONtoCSV.js');
|
const {JSONtoCSV} = require('./_30s.js');
|
||||||
|
|
||||||
test('JSONtoCSV is a Function', () => {
|
test('JSONtoCSV is a Function', () => {
|
||||||
expect(JSONtoCSV).toBeInstanceOf(Function);
|
expect(JSONtoCSV).toBeInstanceOf(Function);
|
||||||
@ -1,11 +0,0 @@
|
|||||||
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');
|
|
||||||
module.exports = JSONtoCSV;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const RGBToHex = require('./RGBToHex.js');
|
const {RGBToHex} = require('./_30s.js');
|
||||||
|
|
||||||
test('RGBToHex is a Function', () => {
|
test('RGBToHex is a Function', () => {
|
||||||
expect(RGBToHex).toBeInstanceOf(Function);
|
expect(RGBToHex).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
|
||||||
module.exports = RGBToHex;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const URLJoin = require('./URLJoin.js');
|
const {URLJoin} = require('./_30s.js');
|
||||||
|
|
||||||
test('URLJoin is a Function', () => {
|
test('URLJoin is a Function', () => {
|
||||||
expect(URLJoin).toBeInstanceOf(Function);
|
expect(URLJoin).toBeInstanceOf(Function);
|
||||||
@ -1,10 +0,0 @@
|
|||||||
const URLJoin = (...args) =>
|
|
||||||
args
|
|
||||||
.join('/')
|
|
||||||
.replace(/[\/]+/g, '/')
|
|
||||||
.replace(/^(.+):\//, '$1://')
|
|
||||||
.replace(/^file:/, 'file:/')
|
|
||||||
.replace(/\/(\?|&|#[^!])/g, '$1')
|
|
||||||
.replace(/\?/g, '&')
|
|
||||||
.replace('&', '?');
|
|
||||||
module.exports = URLJoin;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js');
|
const {UUIDGeneratorBrowser} = require('./_30s.js');
|
||||||
|
|
||||||
test('UUIDGeneratorBrowser is a Function', () => {
|
test('UUIDGeneratorBrowser is a Function', () => {
|
||||||
expect(UUIDGeneratorBrowser).toBeInstanceOf(Function);
|
expect(UUIDGeneratorBrowser).toBeInstanceOf(Function);
|
||||||
@ -1,5 +0,0 @@
|
|||||||
const UUIDGeneratorBrowser = () =>
|
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
||||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
|
||||||
);
|
|
||||||
module.exports = UUIDGeneratorBrowser;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const UUIDGeneratorNode = require('./UUIDGeneratorNode.js');
|
const {UUIDGeneratorNode} = require('./_30s.js');
|
||||||
|
|
||||||
test('UUIDGeneratorNode is a Function', () => {
|
test('UUIDGeneratorNode is a Function', () => {
|
||||||
expect(UUIDGeneratorNode).toBeInstanceOf(Function);
|
expect(UUIDGeneratorNode).toBeInstanceOf(Function);
|
||||||
@ -1,6 +0,0 @@
|
|||||||
const crypto = require('crypto');
|
|
||||||
const UUIDGeneratorNode = () =>
|
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
||||||
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
|
||||||
);
|
|
||||||
module.exports = UUIDGeneratorNode;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const all = require('./all.js');
|
const {all} = require('./_30s.js');
|
||||||
|
|
||||||
test('all is a Function', () => {
|
test('all is a Function', () => {
|
||||||
expect(all).toBeInstanceOf(Function);
|
expect(all).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const all = (arr, fn = Boolean) => arr.every(fn);
|
|
||||||
module.exports = all;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const allEqual = require('./allEqual.js');
|
const {allEqual} = require('./_30s.js');
|
||||||
|
|
||||||
test('allEqual is a Function', () => {
|
test('allEqual is a Function', () => {
|
||||||
expect(allEqual).toBeInstanceOf(Function);
|
expect(allEqual).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const allEqual = arr => arr.every(val => val === arr[0]);
|
|
||||||
module.exports = allEqual;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const any = require('./any.js');
|
const {any} = require('./_30s.js');
|
||||||
|
|
||||||
test('any is a Function', () => {
|
test('any is a Function', () => {
|
||||||
expect(any).toBeInstanceOf(Function);
|
expect(any).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const any = (arr, fn = Boolean) => arr.some(fn);
|
|
||||||
module.exports = any;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const approximatelyEqual = require('./approximatelyEqual.js');
|
const {approximatelyEqual} = require('./_30s.js');
|
||||||
|
|
||||||
test('approximatelyEqual is a Function', () => {
|
test('approximatelyEqual is a Function', () => {
|
||||||
expect(approximatelyEqual).toBeInstanceOf(Function);
|
expect(approximatelyEqual).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
|
||||||
module.exports = approximatelyEqual;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const arrayToCSV = require('./arrayToCSV.js');
|
const {arrayToCSV} = require('./_30s.js');
|
||||||
|
|
||||||
test('arrayToCSV is a Function', () => {
|
test('arrayToCSV is a Function', () => {
|
||||||
expect(arrayToCSV).toBeInstanceOf(Function);
|
expect(arrayToCSV).toBeInstanceOf(Function);
|
||||||
@ -1,3 +0,0 @@
|
|||||||
const arrayToCSV = (arr, delimiter = ',') =>
|
|
||||||
arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n');
|
|
||||||
module.exports = arrayToCSV;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const arrayToHtmlList = require('./arrayToHtmlList.js');
|
const {arrayToHtmlList} = require('./_30s.js');
|
||||||
|
|
||||||
test('arrayToHtmlList is a Function', () => {
|
test('arrayToHtmlList is a Function', () => {
|
||||||
expect(arrayToHtmlList).toBeInstanceOf(Function);
|
expect(arrayToHtmlList).toBeInstanceOf(Function);
|
||||||
@ -1,6 +0,0 @@
|
|||||||
const arrayToHtmlList = (arr, listID) =>
|
|
||||||
(el => (
|
|
||||||
(el = document.querySelector('#' + listID)),
|
|
||||||
(el.innerHTML += arr.map(item => `<li>${item}</li>`).join(''))
|
|
||||||
))();
|
|
||||||
module.exports = arrayToHtmlList;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const ary = require('./ary.js');
|
const {ary} = require('./_30s.js');
|
||||||
|
|
||||||
test('ary is a Function', () => {
|
test('ary is a Function', () => {
|
||||||
expect(ary).toBeInstanceOf(Function);
|
expect(ary).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const ary = (fn, n) => (...args) => fn(...args.slice(0, n));
|
|
||||||
module.exports = ary;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const atob = require('./atob.js');
|
const {atob} = require('./_30s.js');
|
||||||
|
|
||||||
test('atob is a Function', () => {
|
test('atob is a Function', () => {
|
||||||
expect(atob).toBeInstanceOf(Function);
|
expect(atob).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const atob = str => Buffer.from(str, 'base64').toString('binary');
|
|
||||||
module.exports = atob;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const attempt = require('./attempt.js');
|
const {attempt} = require('./_30s.js');
|
||||||
|
|
||||||
test('attempt is a Function', () => {
|
test('attempt is a Function', () => {
|
||||||
expect(attempt).toBeInstanceOf(Function);
|
expect(attempt).toBeInstanceOf(Function);
|
||||||
@ -1,8 +0,0 @@
|
|||||||
const attempt = (fn, ...args) => {
|
|
||||||
try {
|
|
||||||
return fn(...args);
|
|
||||||
} catch (e) {
|
|
||||||
return e instanceof Error ? e : new Error(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = attempt;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const average = require('./average.js');
|
const {average} = require('./_30s.js');
|
||||||
|
|
||||||
test('average is a Function', () => {
|
test('average is a Function', () => {
|
||||||
expect(average).toBeInstanceOf(Function);
|
expect(average).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length;
|
|
||||||
module.exports = average;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const averageBy = require('./averageBy.js');
|
const {averageBy} = require('./_30s.js');
|
||||||
|
|
||||||
test('averageBy is a Function', () => {
|
test('averageBy is a Function', () => {
|
||||||
expect(averageBy).toBeInstanceOf(Function);
|
expect(averageBy).toBeInstanceOf(Function);
|
||||||
@ -1,4 +0,0 @@
|
|||||||
const averageBy = (arr, fn) =>
|
|
||||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
|
||||||
arr.length;
|
|
||||||
module.exports = averageBy;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const bifurcate = require('./bifurcate.js');
|
const {bifurcate} = require('./_30s.js');
|
||||||
|
|
||||||
test('bifurcate is a Function', () => {
|
test('bifurcate is a Function', () => {
|
||||||
expect(bifurcate).toBeInstanceOf(Function);
|
expect(bifurcate).toBeInstanceOf(Function);
|
||||||
@ -1,3 +0,0 @@
|
|||||||
const bifurcate = (arr, filter) =>
|
|
||||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
|
||||||
module.exports = bifurcate;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const bifurcateBy = require('./bifurcateBy.js');
|
const {bifurcateBy} = require('./_30s.js');
|
||||||
|
|
||||||
test('bifurcateBy is a Function', () => {
|
test('bifurcateBy is a Function', () => {
|
||||||
expect(bifurcateBy).toBeInstanceOf(Function);
|
expect(bifurcateBy).toBeInstanceOf(Function);
|
||||||
@ -1,3 +0,0 @@
|
|||||||
const bifurcateBy = (arr, fn) =>
|
|
||||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
|
||||||
module.exports = bifurcateBy;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const binarySearch = require('./binarySearch.js');
|
const {binarySearch} = require('./_30s.js');
|
||||||
|
|
||||||
test('binarySearch is a Function', () => {
|
test('binarySearch is a Function', () => {
|
||||||
expect(binarySearch).toBeInstanceOf(Function);
|
expect(binarySearch).toBeInstanceOf(Function);
|
||||||
@ -1,8 +0,0 @@
|
|||||||
const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
|
||||||
if (start > end) return -1;
|
|
||||||
const mid = Math.floor((start + end) / 2);
|
|
||||||
if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1);
|
|
||||||
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
|
|
||||||
return mid;
|
|
||||||
};
|
|
||||||
module.exports = binarySearch;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const bind = require('./bind.js');
|
const {bind} = require('./_30s.js');
|
||||||
|
|
||||||
test('bind is a Function', () => {
|
test('bind is a Function', () => {
|
||||||
expect(bind).toBeInstanceOf(Function);
|
expect(bind).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const bind = (fn, context, ...boundArgs) => (...args) => fn.apply(context, [...boundArgs, ...args]);
|
|
||||||
module.exports = bind;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const bindAll = require('./bindAll.js');
|
const {bindAll} = require('./_30s.js');
|
||||||
|
|
||||||
test('bindAll is a Function', () => {
|
test('bindAll is a Function', () => {
|
||||||
expect(bindAll).toBeInstanceOf(Function);
|
expect(bindAll).toBeInstanceOf(Function);
|
||||||
@ -1,10 +0,0 @@
|
|||||||
const bindAll = (obj, ...fns) =>
|
|
||||||
fns.forEach(
|
|
||||||
fn => (
|
|
||||||
(f = obj[fn]),
|
|
||||||
(obj[fn] = function() {
|
|
||||||
return f.apply(obj);
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
module.exports = bindAll;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const bindKey = require('./bindKey.js');
|
const {bindKey} = require('./_30s.js');
|
||||||
|
|
||||||
test('bindKey is a Function', () => {
|
test('bindKey is a Function', () => {
|
||||||
expect(bindKey).toBeInstanceOf(Function);
|
expect(bindKey).toBeInstanceOf(Function);
|
||||||
@ -1,3 +0,0 @@
|
|||||||
const bindKey = (context, fn, ...boundArgs) => (...args) =>
|
|
||||||
context[fn].apply(context, [...boundArgs, ...args]);
|
|
||||||
module.exports = bindKey;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const binomialCoefficient = require('./binomialCoefficient.js');
|
const {binomialCoefficient} = require('./_30s.js');
|
||||||
|
|
||||||
test('binomialCoefficient is a Function', () => {
|
test('binomialCoefficient is a Function', () => {
|
||||||
expect(binomialCoefficient).toBeInstanceOf(Function);
|
expect(binomialCoefficient).toBeInstanceOf(Function);
|
||||||
@ -1,11 +0,0 @@
|
|||||||
const binomialCoefficient = (n, k) => {
|
|
||||||
if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
|
|
||||||
if (k < 0 || k > n) return 0;
|
|
||||||
if (k === 0 || k === n) return 1;
|
|
||||||
if (k === 1 || k === n - 1) return n;
|
|
||||||
if (n - k < k) k = n - k;
|
|
||||||
let res = n;
|
|
||||||
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
|
||||||
return Math.round(res);
|
|
||||||
};
|
|
||||||
module.exports = binomialCoefficient;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const bottomVisible = require('./bottomVisible.js');
|
const {bottomVisible} = require('./_30s.js');
|
||||||
|
|
||||||
test('bottomVisible is a Function', () => {
|
test('bottomVisible is a Function', () => {
|
||||||
expect(bottomVisible).toBeInstanceOf(Function);
|
expect(bottomVisible).toBeInstanceOf(Function);
|
||||||
@ -1,4 +0,0 @@
|
|||||||
const bottomVisible = () =>
|
|
||||||
document.documentElement.clientHeight + window.scrollY >=
|
|
||||||
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
|
||||||
module.exports = bottomVisible;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const btoa = require('./btoa.js');
|
const {btoa} = require('./_30s.js');
|
||||||
|
|
||||||
test('btoa is a Function', () => {
|
test('btoa is a Function', () => {
|
||||||
expect(btoa).toBeInstanceOf(Function);
|
expect(btoa).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const btoa = str => Buffer.from(str, 'binary').toString('base64');
|
|
||||||
module.exports = btoa;
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const byteSize = str => new Blob([str]).size;
|
|
||||||
module.exports = byteSize;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const call = require('./call.js');
|
const {call} = require('./_30s.js');
|
||||||
|
|
||||||
test('call is a Function', () => {
|
test('call is a Function', () => {
|
||||||
expect(call).toBeInstanceOf(Function);
|
expect(call).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const call = (key, ...args) => context => context[key](...args);
|
|
||||||
module.exports = call;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const capitalize = require('./capitalize.js');
|
const {capitalize} = require('./_30s.js');
|
||||||
|
|
||||||
test('capitalize is a Function', () => {
|
test('capitalize is a Function', () => {
|
||||||
expect(capitalize).toBeInstanceOf(Function);
|
expect(capitalize).toBeInstanceOf(Function);
|
||||||
@ -1,3 +0,0 @@
|
|||||||
const capitalize = ([first, ...rest], lowerRest = false) =>
|
|
||||||
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
|
||||||
module.exports = capitalize;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const capitalizeEveryWord = require('./capitalizeEveryWord.js');
|
const {capitalizeEveryWord} = require('./_30s.js');
|
||||||
|
|
||||||
test('capitalizeEveryWord is a Function', () => {
|
test('capitalizeEveryWord is a Function', () => {
|
||||||
expect(capitalizeEveryWord).toBeInstanceOf(Function);
|
expect(capitalizeEveryWord).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
|
||||||
module.exports = capitalizeEveryWord;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const castArray = require('./castArray.js');
|
const {castArray} = require('./_30s.js');
|
||||||
|
|
||||||
test('castArray is a Function', () => {
|
test('castArray is a Function', () => {
|
||||||
expect(castArray).toBeInstanceOf(Function);
|
expect(castArray).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const castArray = val => (Array.isArray(val) ? val : [val]);
|
|
||||||
module.exports = castArray;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const chainAsync = require('./chainAsync.js');
|
const {chainAsync} = require('./_30s.js');
|
||||||
|
|
||||||
test('chainAsync is a Function', () => {
|
test('chainAsync is a Function', () => {
|
||||||
expect(chainAsync).toBeInstanceOf(Function);
|
expect(chainAsync).toBeInstanceOf(Function);
|
||||||
@ -1,6 +0,0 @@
|
|||||||
const chainAsync = fns => {
|
|
||||||
let curr = 0;
|
|
||||||
const next = () => fns[curr++](next);
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
module.exports = chainAsync;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const chunk = require('./chunk.js');
|
const {chunk} = require('./_30s.js');
|
||||||
|
|
||||||
test('chunk is a Function', () => {
|
test('chunk is a Function', () => {
|
||||||
expect(chunk).toBeInstanceOf(Function);
|
expect(chunk).toBeInstanceOf(Function);
|
||||||
@ -1,5 +0,0 @@
|
|||||||
const chunk = (arr, size) =>
|
|
||||||
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
|
|
||||||
arr.slice(i * size, i * size + size)
|
|
||||||
);
|
|
||||||
module.exports = chunk;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const clampNumber = require('./clampNumber.js');
|
const {clampNumber} = require('./_30s.js');
|
||||||
|
|
||||||
test('clampNumber is a Function', () => {
|
test('clampNumber is a Function', () => {
|
||||||
expect(clampNumber).toBeInstanceOf(Function);
|
expect(clampNumber).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
|
||||||
module.exports = clampNumber;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const cleanObj = require('./cleanObj.js');
|
const {cleanObj} = require('./_30s.js');
|
||||||
|
|
||||||
test('cleanObj is a Function', () => {
|
test('cleanObj is a Function', () => {
|
||||||
expect(cleanObj).toBeInstanceOf(Function);
|
expect(cleanObj).toBeInstanceOf(Function);
|
||||||
@ -1,11 +0,0 @@
|
|||||||
const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
if (key === childIndicator) {
|
|
||||||
cleanObj(obj[key], keysToKeep, childIndicator);
|
|
||||||
} else if (!keysToKeep.includes(key)) {
|
|
||||||
delete obj[key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
module.exports = cleanObj;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const cloneRegExp = require('./cloneRegExp.js');
|
const {cloneRegExp} = require('./_30s.js');
|
||||||
|
|
||||||
test('cloneRegExp is a Function', () => {
|
test('cloneRegExp is a Function', () => {
|
||||||
expect(cloneRegExp).toBeInstanceOf(Function);
|
expect(cloneRegExp).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
|
||||||
module.exports = cloneRegExp;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const coalesce = require('./coalesce.js');
|
const {coalesce} = require('./_30s.js');
|
||||||
|
|
||||||
test('coalesce is a Function', () => {
|
test('coalesce is a Function', () => {
|
||||||
expect(coalesce).toBeInstanceOf(Function);
|
expect(coalesce).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
|
||||||
module.exports = coalesce;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const coalesceFactory = require('./coalesceFactory.js');
|
const {coalesceFactory} = require('./_30s.js');
|
||||||
|
|
||||||
test('coalesceFactory is a Function', () => {
|
test('coalesceFactory is a Function', () => {
|
||||||
expect(coalesceFactory).toBeInstanceOf(Function);
|
expect(coalesceFactory).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const coalesceFactory = valid => (...args) => args.find(valid);
|
|
||||||
module.exports = coalesceFactory;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const collatz = require('./collatz.js');
|
const {collatz} = require('./_30s.js');
|
||||||
|
|
||||||
test('collatz is a Function', () => {
|
test('collatz is a Function', () => {
|
||||||
expect(collatz).toBeInstanceOf(Function);
|
expect(collatz).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
|
|
||||||
module.exports = collatz;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const collectInto = require('./collectInto.js');
|
const {collectInto} = require('./_30s.js');
|
||||||
|
|
||||||
test('collectInto is a Function', () => {
|
test('collectInto is a Function', () => {
|
||||||
expect(collectInto).toBeInstanceOf(Function);
|
expect(collectInto).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const collectInto = fn => (...args) => fn(args);
|
|
||||||
module.exports = collectInto;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const colorize = require('./colorize.js');
|
const {colorize} = require('./_30s.js');
|
||||||
|
|
||||||
test('colorize is a Function', () => {
|
test('colorize is a Function', () => {
|
||||||
expect(colorize).toBeInstanceOf(Function);
|
expect(colorize).toBeInstanceOf(Function);
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const colorize = (...args) => ({
|
|
||||||
black: `\x1b[30m${args.join(' ')}`,
|
|
||||||
red: `\x1b[31m${args.join(' ')}`,
|
|
||||||
green: `\x1b[32m${args.join(' ')}`,
|
|
||||||
yellow: `\x1b[33m${args.join(' ')}`,
|
|
||||||
blue: `\x1b[34m${args.join(' ')}`,
|
|
||||||
magenta: `\x1b[35m${args.join(' ')}`,
|
|
||||||
cyan: `\x1b[36m${args.join(' ')}`,
|
|
||||||
white: `\x1b[37m${args.join(' ')}`,
|
|
||||||
bgBlack: `\x1b[40m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgRed: `\x1b[41m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgGreen: `\x1b[42m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgYellow: `\x1b[43m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgBlue: `\x1b[44m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
|
||||||
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
|
||||||
});
|
|
||||||
module.exports = colorize;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const compact = require('./compact.js');
|
const {compact} = require('./_30s.js');
|
||||||
|
|
||||||
test('compact is a Function', () => {
|
test('compact is a Function', () => {
|
||||||
expect(compact).toBeInstanceOf(Function);
|
expect(compact).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const compact = arr => arr.filter(Boolean);
|
|
||||||
module.exports = compact;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const compose = require('./compose.js');
|
const {compose} = require('./_30s.js');
|
||||||
|
|
||||||
test('compose is a Function', () => {
|
test('compose is a Function', () => {
|
||||||
expect(compose).toBeInstanceOf(Function);
|
expect(compose).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
|
||||||
module.exports = compose;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const composeRight = require('./composeRight.js');
|
const {composeRight} = require('./_30s.js');
|
||||||
|
|
||||||
test('composeRight is a Function', () => {
|
test('composeRight is a Function', () => {
|
||||||
expect(composeRight).toBeInstanceOf(Function);
|
expect(composeRight).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
|
||||||
module.exports = composeRight;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const converge = require('./converge.js');
|
const {converge} = require('./_30s.js');
|
||||||
|
|
||||||
test('converge is a Function', () => {
|
test('converge is a Function', () => {
|
||||||
expect(converge).toBeInstanceOf(Function);
|
expect(converge).toBeInstanceOf(Function);
|
||||||
@ -1,2 +0,0 @@
|
|||||||
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
|
|
||||||
module.exports = converge;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const copyToClipboard = require('./copyToClipboard.js');
|
const {copyToClipboard} = require('./_30s.js');
|
||||||
|
|
||||||
test('copyToClipboard is a Function', () => {
|
test('copyToClipboard is a Function', () => {
|
||||||
expect(copyToClipboard).toBeInstanceOf(Function);
|
expect(copyToClipboard).toBeInstanceOf(Function);
|
||||||
@ -1,18 +0,0 @@
|
|||||||
const copyToClipboard = str => {
|
|
||||||
const el = document.createElement('textarea');
|
|
||||||
el.value = str;
|
|
||||||
el.setAttribute('readonly', '');
|
|
||||||
el.style.position = 'absolute';
|
|
||||||
el.style.left = '-9999px';
|
|
||||||
document.body.appendChild(el);
|
|
||||||
const selected =
|
|
||||||
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
|
||||||
el.select();
|
|
||||||
document.execCommand('copy');
|
|
||||||
document.body.removeChild(el);
|
|
||||||
if (selected) {
|
|
||||||
document.getSelection().removeAllRanges();
|
|
||||||
document.getSelection().addRange(selected);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = copyToClipboard;
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const countBy = require('./countBy.js');
|
const {countBy} = require('./_30s.js');
|
||||||
|
|
||||||
test('countBy is a Function', () => {
|
test('countBy is a Function', () => {
|
||||||
expect(countBy).toBeInstanceOf(Function);
|
expect(countBy).toBeInstanceOf(Function);
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user