generate new test that did already exist & update all module snippets with declaration
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
module.exports = arr => {
|
module.exports = 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()}`;
|
||||||
};
|
};
|
||||||
4
test/README/README.js
Normal file
4
test/README/README.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module.exports = README = e = arr => {
|
||||||
|
const dt = new Date(parseInt(arr.toString().substr(6)));
|
||||||
|
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
||||||
|
};
|
||||||
13
test/README/README.test.js
Normal file
13
test/README/README.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const README = require('./README.js');
|
||||||
|
|
||||||
|
test('Testing README', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof README === 'function', 'README is a Function');
|
||||||
|
//t.deepEqual(README(args..), 'Expected');
|
||||||
|
//t.equal(README(args..), 'Expected');
|
||||||
|
//t.false(README(args..), 'Expected');
|
||||||
|
//t.throws(README(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
module.exports = RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = () =>
|
module.exports = 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)
|
||||||
);
|
);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = str => {
|
module.exports = anagrams = str => {
|
||||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||||
return str
|
return str
|
||||||
.split('')
|
.split('')
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = (arr, listID) =>
|
module.exports = arrayToHtmlList = (arr, listID) =>
|
||||||
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
|
module.exports = average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, val, start = 0, end = arr.length - 1) => {
|
module.exports = binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
||||||
if (start > end) return -1;
|
if (start > end) return -1;
|
||||||
const mid = Math.floor((start + end) / 2);
|
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, start, mid - 1);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
module.exports = () =>
|
module.exports = bottomVisible = () =>
|
||||||
document.documentElement.clientHeight + window.scrollY >=
|
document.documentElement.clientHeight + window.scrollY >=
|
||||||
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = str => new Blob([str]).size;
|
module.exports = byteSize = str => new Blob([str]).size;
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (key, ...args) => context => context[key](...args);
|
module.exports = call = (key, ...args) => context => context[key](...args);
|
||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = ([first, ...rest], lowerRest = false) =>
|
module.exports = capitalize = ([first, ...rest], lowerRest = false) =>
|
||||||
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
module.exports = capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = fns => {
|
module.exports = chainAsync = fns => {
|
||||||
let curr = 0;
|
let curr = 0;
|
||||||
const next = () => fns[curr++](next);
|
const next = () => fns[curr++](next);
|
||||||
next();
|
next();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, size) =>
|
module.exports = 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)
|
||||||
);
|
);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
module.exports = clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (obj, keysToKeep = [], childIndicator) => {
|
module.exports = cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
||||||
Object.keys(obj).forEach(key => {
|
Object.keys(obj).forEach(key => {
|
||||||
if (key === childIndicator) {
|
if (key === childIndicator) {
|
||||||
cleanObj(obj[key], keysToKeep, childIndicator);
|
cleanObj(obj[key], keysToKeep, childIndicator);
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = regExp => new RegExp(regExp.source, regExp.flags);
|
module.exports = cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (...args) => args.find(_ => ![undefined, null].includes(_));
|
module.exports = coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = valid => (...args) => args.find(valid);
|
module.exports = coalesceFactory = valid => (...args) => args.find(valid);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
|
module.exports = collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = fn => (...args) => fn(args);
|
module.exports = collectInto = fn => (...args) => fn(args);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => arr.filter(Boolean);
|
module.exports = compact = arr => arr.filter(Boolean);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
module.exports = compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = str => {
|
module.exports = copyToClipboard = str => {
|
||||||
const el = document.createElement('textarea');
|
const el = document.createElement('textarea');
|
||||||
el.value = str;
|
el.value = str;
|
||||||
el.setAttribute('readonly', '');
|
el.setAttribute('readonly', '');
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
|
module.exports = countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = str => (str.match(/[aeiou]/gi) || []).length;
|
module.exports = countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = str => {
|
module.exports = createElement = str => {
|
||||||
const el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
el.innerHTML = str;
|
el.innerHTML = str;
|
||||||
return el.firstElementChild;
|
return el.firstElementChild;
|
||||||
|
|||||||
14
test/createEventHub/createEventHub.js
Normal file
14
test/createEventHub/createEventHub.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
module.exports = createEventHub = () => ({
|
||||||
|
hub: Object.create(null),
|
||||||
|
emit(event, data) {
|
||||||
|
(this.hub[event] || []).forEach(handler => handler(data));
|
||||||
|
},
|
||||||
|
on(event, handler) {
|
||||||
|
if (!this.hub[event]) this.hub[event] = [];
|
||||||
|
this.hub[event].push(handler);
|
||||||
|
},
|
||||||
|
off(event, handler) {
|
||||||
|
const i = (this.hub[event] || []).findIndex(h => h === handler);
|
||||||
|
if (i > -1) this.hub[event].splice(i, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
13
test/createEventHub/createEventHub.test.js
Normal file
13
test/createEventHub/createEventHub.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const createEventHub = require('./createEventHub.js');
|
||||||
|
|
||||||
|
test('Testing createEventHub', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof createEventHub === 'function', 'createEventHub is a Function');
|
||||||
|
//t.deepEqual(createEventHub(args..), 'Expected');
|
||||||
|
//t.equal(createEventHub(args..), 'Expected');
|
||||||
|
//t.false(createEventHub(args..), 'Expected');
|
||||||
|
//t.throws(createEventHub(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = () => window.location.href;
|
module.exports = currentURL = () => window.location.href;
|
||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = (fn, arity = fn.length, ...args) =>
|
module.exports = 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);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
module.exports = deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (fn, ...args) => setTimeout(fn, 1, ...args);
|
module.exports = defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = () =>
|
module.exports = 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';
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (a, b) => {
|
module.exports = 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));
|
||||||
};
|
};
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
|
module.exports = differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = n => [...`${n}`].map(i => parseInt(i));
|
module.exports = digitize = n => [...`${n}`].map(i => parseInt(i));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
module.exports = distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => [...new Set(arr)];
|
module.exports = distinctValuesOfArray = arr => [...new Set(arr)];
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, func) => {
|
module.exports = dropElements = (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;
|
||||||
};
|
};
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (arr, n = 1) => arr.slice(0, -n);
|
module.exports = dropRight = (arr, n = 1) => arr.slice(0, -n);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (el, partiallyVisible = false) => {
|
module.exports = elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
||||||
const { top, left, bottom, right } = el.getBoundingClientRect();
|
const { top, left, bottom, right } = el.getBoundingClientRect();
|
||||||
const { innerHeight, innerWidth } = window;
|
const { innerHeight, innerWidth } = window;
|
||||||
return partiallyVisible
|
return partiallyVisible
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = ([...ratings], kFactor = 32, selfRating) => {
|
module.exports = elo = ([...ratings], kFactor = 32, selfRating) => {
|
||||||
const [a, b] = ratings;
|
const [a, b] = ratings;
|
||||||
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||||
const newRating = (rating, i) =>
|
const newRating = (rating, i) =>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = str =>
|
module.exports = escapeHTML = str =>
|
||||||
str.replace(
|
str.replace(
|
||||||
/[&<>'"]/g,
|
/[&<>'"]/g,
|
||||||
tag =>
|
tag =>
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
module.exports = escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
module.exports = everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = shortHex =>
|
module.exports = extendHex = shortHex =>
|
||||||
'#' +
|
'#' +
|
||||||
shortHex
|
shortHex
|
||||||
.slice(shortHex.startsWith('#') ? 1 : 0)
|
.slice(shortHex.startsWith('#') ? 1 : 0)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = n =>
|
module.exports = factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (num, primes = false) => {
|
module.exports = factors = (num, primes = false) => {
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
const boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
|
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = n =>
|
module.exports = fibonacci = n =>
|
||||||
Array.from({ length: n }).reduce(
|
Array.from({ length: n }).reduce(
|
||||||
(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),
|
||||||
[]
|
[]
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = num =>
|
module.exports = 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));
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = num => {
|
module.exports = fibonacciUntilNum = num => {
|
||||||
let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
||||||
return Array.from({ length: n }).reduce(
|
return Array.from({ length: n }).reduce(
|
||||||
(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),
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
|
module.exports = filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => [].concat(...arr);
|
module.exports = flatten = arr => [].concat(...arr);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, depth = 1) =>
|
module.exports = flattenDepth = (arr, depth = 1) =>
|
||||||
depth != 1
|
depth != 1
|
||||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), [])
|
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), [])
|
||||||
: arr.reduce((a, v) => a.concat(v), []);
|
: arr.reduce((a, v) => a.concat(v), []);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = fn => (...args) => fn(args.pop(), ...args);
|
module.exports = flip = fn => (...args) => fn(args.pop(), ...args);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, callback) =>
|
module.exports = forEachRight = (arr, callback) =>
|
||||||
arr
|
arr
|
||||||
.slice(0)
|
.slice(0)
|
||||||
.reverse()
|
.reverse()
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = ms => {
|
module.exports = formatDuration = ms => {
|
||||||
if (ms < 0) ms = -ms;
|
if (ms < 0) ms = -ms;
|
||||||
const time = {
|
const time = {
|
||||||
day: Math.floor(ms / 86400000),
|
day: Math.floor(ms / 86400000),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (str, separator = '_') =>
|
module.exports = 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')
|
||||||
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
|
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = fn => (console.debug(fn.name), fn);
|
module.exports = functionName = fn => (console.debug(fn.name), fn);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (...arr) => {
|
module.exports = gcd = (...arr) => {
|
||||||
const _gcd = (x, y) => (!y ? x : _gcd(y, x % y));
|
const _gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||||
return [...arr].reduce((a, b) => _gcd(a, b));
|
return [...arr].reduce((a, b) => _gcd(a, b));
|
||||||
};
|
};
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (end, start = 1, step = 2) =>
|
module.exports = geometricProgression = (end, start = 1, step = 2) =>
|
||||||
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
|
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
|
||||||
(v, i) => start * step ** i
|
(v, i) => start * step ** i
|
||||||
);
|
);
|
||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = (dateInitial, dateFinal) =>
|
module.exports = getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
|
||||||
(dateFinal - dateInitial) / (1000 * 3600 * 24);
|
(dateFinal - dateInitial) / (1000 * 3600 * 24);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (el = window) => ({
|
module.exports = getScrollPosition = (el = window) => ({
|
||||||
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
|
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
|
||||||
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
|
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
|
||||||
});
|
});
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (el, ruleName) => getComputedStyle(el)[ruleName];
|
module.exports = getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
|
||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = v =>
|
module.exports = getType = v =>
|
||||||
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
|
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = url =>
|
module.exports = getURLParameters = url =>
|
||||||
url
|
url
|
||||||
.match(/([^?=&]+)(=([^&]*))/g)
|
.match(/([^?=&]+)(=([^&]*))/g)
|
||||||
.reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
|
.reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, func) =>
|
module.exports = groupBy = (arr, func) =>
|
||||||
arr.map(typeof func === 'function' ? func : val => val[func]).reduce((acc, val, i) => {
|
arr.map(typeof func === 'function' ? func : val => val[func]).reduce((acc, val, i) => {
|
||||||
acc[val] = (acc[val] || []).concat(arr[i]);
|
acc[val] = (acc[val] || []).concat(arr[i]);
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
|
module.exports = hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (el, className) => el.classList.contains(className);
|
module.exports = hasClass = (el, className) => el.classList.contains(className);
|
||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = (...flags) =>
|
module.exports = hasFlags = (...flags) =>
|
||||||
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => arr[0];
|
module.exports = head = arr => arr[0];
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = hex => {
|
module.exports = hexToRGB = hex => {
|
||||||
let alpha = false,
|
let alpha = false,
|
||||||
h = hex.slice(hex.startsWith('#') ? 1 : 0);
|
h = hex.slice(hex.startsWith('#') ? 1 : 0);
|
||||||
if (h.length === 3) h = [...h].map(x => x + x).join('');
|
if (h.length === 3) h = [...h].map(x => x + x).join('');
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
module.exports = hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (num, divisor) => {
|
module.exports = howManyTimes = (num, divisor) => {
|
||||||
if (divisor === 1 || divisor === -1) return Infinity;
|
if (divisor === 1 || divisor === -1) return Infinity;
|
||||||
if (divisor === 0) return 0;
|
if (divisor === 0) return 0;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|||||||
7
test/httpDelete/httpDelete.js
Normal file
7
test/httpDelete/httpDelete.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module.exports = httpDelete = (url, callback, err = console.error) => {
|
||||||
|
const request = new XMLHttpRequest();
|
||||||
|
request.open("DELETE", url, true);
|
||||||
|
request.onload = () => callback(request);
|
||||||
|
request.onerror = () => err(request);
|
||||||
|
request.send();
|
||||||
|
};
|
||||||
13
test/httpDelete/httpDelete.test.js
Normal file
13
test/httpDelete/httpDelete.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const httpDelete = require('./httpDelete.js');
|
||||||
|
|
||||||
|
test('Testing httpDelete', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof httpDelete === 'function', 'httpDelete is a Function');
|
||||||
|
//t.deepEqual(httpDelete(args..), 'Expected');
|
||||||
|
//t.equal(httpDelete(args..), 'Expected');
|
||||||
|
//t.false(httpDelete(args..), 'Expected');
|
||||||
|
//t.throws(httpDelete(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
7
test/httpGet/httpGet.js
Normal file
7
test/httpGet/httpGet.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module.exports = httpGet = (url, callback, err = console.error) => {
|
||||||
|
const request = new XMLHttpRequest();
|
||||||
|
request.open('GET', url, true);
|
||||||
|
request.onload = () => callback(request.responseText);
|
||||||
|
request.onerror = () => err(request);
|
||||||
|
request.send();
|
||||||
|
};
|
||||||
13
test/httpGet/httpGet.test.js
Normal file
13
test/httpGet/httpGet.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const httpGet = require('./httpGet.js');
|
||||||
|
|
||||||
|
test('Testing httpGet', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof httpGet === 'function', 'httpGet is a Function');
|
||||||
|
//t.deepEqual(httpGet(args..), 'Expected');
|
||||||
|
//t.equal(httpGet(args..), 'Expected');
|
||||||
|
//t.false(httpGet(args..), 'Expected');
|
||||||
|
//t.throws(httpGet(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
8
test/httpPost/httpPost.js
Normal file
8
test/httpPost/httpPost.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module.exports = httpPost = (url, callback, data = null, err = console.error) => {
|
||||||
|
const request = new XMLHttpRequest();
|
||||||
|
request.open('POST', url, true);
|
||||||
|
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
||||||
|
request.onload = () => callback(request.responseText);
|
||||||
|
request.onerror = () => err(request);
|
||||||
|
request.send(data);
|
||||||
|
};
|
||||||
13
test/httpPost/httpPost.test.js
Normal file
13
test/httpPost/httpPost.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const httpPost = require('./httpPost.js');
|
||||||
|
|
||||||
|
test('Testing httpPost', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof httpPost === 'function', 'httpPost is a Function');
|
||||||
|
//t.deepEqual(httpPost(args..), 'Expected');
|
||||||
|
//t.equal(httpPost(args..), 'Expected');
|
||||||
|
//t.false(httpPost(args..), 'Expected');
|
||||||
|
//t.throws(httpPost(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
8
test/httpPut/httpPut.js
Normal file
8
test/httpPut/httpPut.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module.exports = httpPut = (url, data, callback, err = console.error) => {
|
||||||
|
const request = new XMLHttpRequest();
|
||||||
|
request.open("PUT", url, true);
|
||||||
|
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||||
|
request.onload = () => callback(request);
|
||||||
|
request.onerror = () => err(request);
|
||||||
|
request.send(data);
|
||||||
|
};
|
||||||
13
test/httpPut/httpPut.test.js
Normal file
13
test/httpPut/httpPut.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const httpPut = require('./httpPut.js');
|
||||||
|
|
||||||
|
test('Testing httpPut', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof httpPut === 'function', 'httpPut is a Function');
|
||||||
|
//t.deepEqual(httpPut(args..), 'Expected');
|
||||||
|
//t.equal(httpPut(args..), 'Expected');
|
||||||
|
//t.false(httpPut(args..), 'Expected');
|
||||||
|
//t.throws(httpPut(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@ -1,3 +1,3 @@
|
|||||||
module.exports = () => {
|
module.exports = httpsRedirect = () => {
|
||||||
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
||||||
};
|
};
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (n, start, end = null) => {
|
module.exports = inRange = (n, start, end = null) => {
|
||||||
if (end && start > end) end = [start, (start = end)][0];
|
if (end && start > end) end = [start, (start = end)][0];
|
||||||
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
||||||
};
|
};
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (arr, val) => {
|
module.exports = indexOfAll = (arr, val) => {
|
||||||
const indices = [];
|
const indices = [];
|
||||||
arr.forEach((el, i) => el === val && indices.push(i));
|
arr.forEach((el, i) => el === val && indices.push(i));
|
||||||
return indices;
|
return indices;
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = arr => arr.slice(0, -1);
|
module.exports = initial = arr => arr.slice(0, -1);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (w, h, val = null) =>
|
module.exports = initialize2DArray = (w, h, val = null) =>
|
||||||
Array(h)
|
Array(h)
|
||||||
.fill()
|
.fill()
|
||||||
.map(() => Array(w).fill(val));
|
.map(() => Array(w).fill(val));
|
||||||
@ -1,2 +1,2 @@
|
|||||||
module.exports = (end, start = 0, step = 1) =>
|
module.exports = initializeArrayWithRange = (end, start = 0, step = 1) =>
|
||||||
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (n, val = 0) => Array(n).fill(val);
|
module.exports = initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = (a, b) => {
|
module.exports = intersection = (a, b) => {
|
||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => s.has(x));
|
return a.filter(x => s.has(x));
|
||||||
};
|
};
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = obj =>
|
module.exports = invertKeyValues = obj =>
|
||||||
Object.keys(obj).reduce((acc, key) => {
|
Object.keys(obj).reduce((acc, key) => {
|
||||||
acc[obj[key]] = key;
|
acc[obj[key]] = key;
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
module.exports = isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = digits =>
|
module.exports = isArmstrongNumber = digits =>
|
||||||
(arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(
|
(arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(
|
||||||
(digits + '').split('')
|
(digits + '').split('')
|
||||||
);
|
);
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = val => Array.isArray(val);
|
module.exports = isArray = val => Array.isArray(val);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = val => {
|
module.exports = isArrayLike = val => {
|
||||||
try {
|
try {
|
||||||
return [...val], true;
|
return [...val], true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
module.exports = val => typeof val === 'boolean';
|
module.exports = isBoolean = val => typeof val === 'boolean';
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = (dividend, divisor) => dividend % divisor === 0;
|
module.exports = isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user