ran npm run tdd

This commit is contained in:
King
2018-01-17 13:40:40 -05:00
parent f232347f8a
commit 129a6fb333
244 changed files with 894 additions and 371 deletions

View File

@ -1,4 +1,5 @@
module.exports = JSONToDate = arr => {
const JSONToDate = arr => {
const dt = new Date(parseInt(arr.toString().substr(6)));
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
};
module.exports = JSONToDate

View File

@ -0,0 +1,4 @@
const fs = require('fs');
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
module.exports = JSONToFile

View File

@ -0,0 +1,13 @@
const test = require('tape');
const JSONToFile = require('./JSONToFile.js');
test('Testing JSONToFile', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof JSONToFile === 'function', 'JSONToFile is a Function');
//t.deepEqual(JSONToFile(args..), 'Expected');
//t.equal(JSONToFile(args..), 'Expected');
//t.false(JSONToFile(args..), 'Expected');
//t.throws(JSONToFile(args..), 'Expected');
t.end();
});

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1,8 +1,10 @@
module.exports = URLJoin = (...args) =>
args.join('/')
const URLJoin = (...args) =>
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
module.exports = URLJoin

View File

@ -1,4 +1,5 @@
module.exports = UUIDGeneratorBrowser = () =>
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

View File

@ -0,0 +1,6 @@
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

View File

@ -0,0 +1,13 @@
const test = require('tape');
const UUIDGeneratorNode = require('./UUIDGeneratorNode.js');
test('Testing UUIDGeneratorNode', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof UUIDGeneratorNode === 'function', 'UUIDGeneratorNode is a Function');
//t.deepEqual(UUIDGeneratorNode(args..), 'Expected');
//t.equal(UUIDGeneratorNode(args..), 'Expected');
//t.false(UUIDGeneratorNode(args..), 'Expected');
//t.throws(UUIDGeneratorNode(args..), 'Expected');
t.end();
});

View File

@ -1,4 +1,4 @@
module.exports = anagrams = str => {
const anagrams = str => {
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
return str
.split('')
@ -8,3 +8,4 @@ acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)
[]
);
};
module.exports = anagrams

View File

@ -1,2 +1,3 @@
module.exports = arrayToHtmlList = (arr, listID) =>
const arrayToHtmlList = (arr, listID) =>
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
module.exports = arrayToHtmlList

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1,3 +1,4 @@
module.exports = averageBy = (arr, fn) =>
const averageBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
arr.length;
module.exports = averageBy

View File

@ -1,7 +1,8 @@
module.exports = binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
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

View File

@ -1,3 +1,4 @@
module.exports = bottomVisible = () =>
const bottomVisible = () =>
document.documentElement.clientHeight + window.scrollY >=
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
module.exports = bottomVisible

View File

@ -1 +1,2 @@
module.exports = byteSize = str => new Blob([str]).size;
const byteSize = str => new Blob([str]).size;
module.exports = byteSize

View File

@ -1 +1,2 @@
module.exports = call = (key, ...args) => context => context[key](...args);
const call = (key, ...args) => context => context[key](...args);
module.exports = call

View File

@ -1,2 +1,3 @@
module.exports = capitalize = ([first, ...rest], lowerRest = false) =>
const capitalize = ([first, ...rest], lowerRest = false) =>
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
module.exports = capitalize

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1,5 +1,6 @@
module.exports = chainAsync = fns => {
const chainAsync = fns => {
let curr = 0;
const next = () => fns[curr++](next);
next();
};
module.exports = chainAsync

View File

@ -1,4 +1,5 @@
module.exports = chunk = (arr, size) =>
const chunk = (arr, size) =>
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
arr.slice(i * size, i * size + size)
);
module.exports = chunk

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1,4 +1,4 @@
module.exports = cleanObj = (obj, keysToKeep = [], childIndicator) => {
const cleanObj = (obj, keysToKeep = [], childIndicator) => {
Object.keys(obj).forEach(key => {
if (key === childIndicator) {
cleanObj(obj[key], keysToKeep, childIndicator);
@ -8,3 +8,4 @@ delete obj[key];
});
return obj;
};
module.exports = cleanObj

View File

@ -1 +1,2 @@
module.exports = cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
module.exports = cloneRegExp

View File

@ -1 +1,2 @@
module.exports = coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
module.exports = coalesce

View File

@ -1 +1,2 @@
module.exports = coalesceFactory = valid => (...args) => args.find(valid);
const coalesceFactory = valid => (...args) => args.find(valid);
module.exports = coalesceFactory

View File

@ -1 +1,2 @@
module.exports = collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
const collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
module.exports = collatz

View File

@ -1 +1,2 @@
module.exports = collectInto = fn => (...args) => fn(args);
const collectInto = fn => (...args) => fn(args);
module.exports = collectInto

View File

@ -1,4 +1,4 @@
module.exports = colorize = (...args) => ({
const colorize = (...args) => ({
black: `\x1b[30m${args.join(' ')}`,
red: `\x1b[31m${args.join(' ')}`,
green: `\x1b[32m${args.join(' ')}`,
@ -16,3 +16,4 @@ bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
});
module.exports = colorize

View File

@ -1 +1,2 @@
module.exports = compact = arr => arr.filter(Boolean);
const compact = arr => arr.filter(Boolean);
module.exports = compact

View File

@ -1 +1,2 @@
module.exports = compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
module.exports = compose

View File

@ -1,4 +1,4 @@
module.exports = copyToClipboard = str => {
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
@ -15,3 +15,4 @@ document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};
module.exports = copyToClipboard

View File

@ -1,5 +1,6 @@
module.exports = countBy = (arr, fn) =>
const countBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
acc[val] = (acc[val] || 0) + 1;
return acc;
}, {});
module.exports = countBy

View File

@ -1 +1,2 @@
module.exports = countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
module.exports = countOccurrences

View File

@ -1 +1,2 @@
module.exports = countVowels = str => (str.match(/[aeiou]/gi) || []).length;
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
module.exports = countVowels

View File

@ -1,5 +1,6 @@
module.exports = createElement = str => {
const createElement = str => {
const el = document.createElement('div');
el.innerHTML = str;
return el.firstElementChild;
};
module.exports = createElement

View File

@ -1,4 +1,4 @@
module.exports = createEventHub = () => ({
const createEventHub = () => ({
hub: Object.create(null),
emit(event, data) {
(this.hub[event] || []).forEach(handler => handler(data));
@ -12,3 +12,4 @@ const i = (this.hub[event] || []).findIndex(h => h === handler);
if (i > -1) this.hub[event].splice(i, 1);
}
});
module.exports = createEventHub

View File

@ -1 +1,2 @@
module.exports = currentURL = () => window.location.href;
const currentURL = () => window.location.href;
module.exports = currentURL

View File

@ -1,2 +1,3 @@
module.exports = curry = (fn, arity = fn.length, ...args) =>
const curry = (fn, arity = fn.length, ...args) =>
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
module.exports = curry

View File

@ -1,2 +1,3 @@
module.exports = decapitalize = ([first, ...rest], upperRest = false) =>
const decapitalize = ([first, ...rest], upperRest = false) =>
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
module.exports = decapitalize

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1 +1,2 @@
module.exports = defer = (fn, ...args) => setTimeout(fn, 1, ...args);
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
module.exports = defer

View File

@ -1,4 +1,5 @@
module.exports = detectDeviceType = () =>
const detectDeviceType = () =>
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
? 'Mobile'
: 'Desktop';
module.exports = detectDeviceType

View File

@ -1,4 +1,5 @@
module.exports = difference = (a, b) => {
const difference = (a, b) => {
const s = new Set(b);
return a.filter(x => !s.has(x));
};
module.exports = difference

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1 +1,2 @@
module.exports = digitize = n => [...`${n}`].map(i => parseInt(i));
const digitize = n => [...`${n}`].map(i => parseInt(i));
module.exports = digitize

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1,4 +1,5 @@
module.exports = dropElements = (arr, func) => {
const dropElements = (arr, func) => {
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
return arr;
};
module.exports = dropElements

View File

@ -1 +1,2 @@
module.exports = dropRight = (arr, n = 1) => arr.slice(0, -n);
const dropRight = (arr, n = 1) => arr.slice(0, -n);
module.exports = dropRight

View File

@ -1,4 +1,4 @@
module.exports = elementIsVisibleInViewport = (el, partiallyVisible = false) => {
const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
return partiallyVisible
@ -6,3 +6,4 @@ return partiallyVisible
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
};
module.exports = elementIsVisibleInViewport

View File

@ -1,4 +1,4 @@
module.exports = elo = ([...ratings], kFactor = 32, selfRating) => {
const elo = ([...ratings], kFactor = 32, selfRating) => {
const [a, b] = ratings;
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
const newRating = (rating, i) =>
@ -16,3 +16,4 @@ j++;
}
return ratings;
};
module.exports = elo

View File

@ -1,4 +1,4 @@
module.exports = equals = (a, b) => {
const equals = (a, b) => {
if (a === b) return true;
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
if (!a || !b || (typeof a != 'object' && typeof b !== 'object')) return a === b;
@ -8,3 +8,4 @@ let keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
return keys.every(k => equals(a[k], b[k]));
};
module.exports = equals

View File

@ -1,4 +1,4 @@
module.exports = escapeHTML = str =>
const escapeHTML = str =>
str.replace(
/[&<>'"]/g,
tag =>
@ -10,3 +10,4 @@ tag =>
'"': '&quot;'
}[tag] || tag)
);
module.exports = escapeHTML

View File

@ -1 +1,2 @@
module.exports = escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
module.exports = escapeRegExp

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1,7 +1,8 @@
module.exports = extendHex = shortHex =>
const extendHex = shortHex =>
'#' +
shortHex
.slice(shortHex.startsWith('#') ? 1 : 0)
.split('')
.map(x => x + x)
.join('');
module.exports = extendHex

View File

@ -1,6 +1,7 @@
module.exports = factorial = n =>
const factorial = n =>
n < 0
? (() => {
throw new TypeError('Negative numbers are not allowed!');
})()
: n <= 1 ? 1 : n * factorial(n - 1);
module.exports = factorial

View File

@ -1,4 +1,4 @@
module.exports = factors = (num, primes = false) => {
const factors = (num, primes = false) => {
const isPrime = num => {
const boundary = Math.floor(Math.sqrt(num));
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
@ -17,3 +17,4 @@ return acc;
}, []);
return primes ? array.filter(isPrime) : array;
};
module.exports = factors

View File

@ -1,5 +1,6 @@
module.exports = fibonacci = n =>
const fibonacci = n =>
Array.from({ length: n }).reduce(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[]
);
module.exports = fibonacci

View File

@ -1,2 +1,3 @@
module.exports = fibonacciCountUntilNum = num =>
const fibonacciCountUntilNum = num =>
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
module.exports = fibonacciCountUntilNum

View File

@ -1,7 +1,8 @@
module.exports = fibonacciUntilNum = num => {
const fibonacciUntilNum = num => {
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(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[]
);
};
module.exports = fibonacciUntilNum

View File

@ -1 +1,2 @@
module.exports = 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

View File

@ -1 +1,2 @@
module.exports = findLast = (arr, fn) => arr.filter(fn).slice(-1);
const findLast = (arr, fn) => arr.filter(fn).slice(-1);
module.exports = findLast

View File

@ -1,4 +1,5 @@
module.exports = flatten = (arr, depth = 1) =>
const flatten = (arr, depth = 1) =>
depth != 1
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
: arr.reduce((a, v) => a.concat(v), []);
module.exports = flatten

View File

@ -1 +1,2 @@
module.exports = flip = fn => (...args) => fn(args.pop(), ...args);
const flip = fn => (...args) => fn(args.pop(), ...args);
module.exports = flip

View File

@ -1,5 +1,6 @@
module.exports = forEachRight = (arr, callback) =>
const forEachRight = (arr, callback) =>
arr
.slice(0)
.reverse()
.forEach(callback);
module.exports = forEachRight

View File

@ -1,4 +1,4 @@
module.exports = formatDuration = ms => {
const formatDuration = ms => {
if (ms < 0) ms = -ms;
const time = {
day: Math.floor(ms / 86400000),
@ -12,3 +12,4 @@ return Object.entries(time)
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
.join(', ');
};
module.exports = formatDuration

View File

@ -1,5 +1,6 @@
module.exports = fromCamelCase = (str, separator = '_') =>
const fromCamelCase = (str, separator = '_') =>
str
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
.toLowerCase();
module.exports = fromCamelCase

View File

@ -1 +1,2 @@
module.exports = functionName = fn => (console.debug(fn.name), fn);
const functionName = fn => (console.debug(fn.name), fn);
module.exports = functionName

View File

@ -1,5 +1,6 @@
module.exports = functions = (obj, inherited = false) =>
const functions = (obj, inherited = false) =>
(inherited
? [...Object.keys(obj), ...Object.keys(Object.getPrototypeOf(obj))]
: Object.keys(obj)
).filter(key => typeof obj[key] === 'function');
module.exports = functions

View File

@ -1,4 +1,5 @@
module.exports = gcd = (...arr) => {
const gcd = (...arr) => {
const _gcd = (x, y) => (!y ? x : gcd(y, x % y));
return [...arr].reduce((a, b) => _gcd(a, b));
};
module.exports = gcd

View File

@ -1,4 +1,5 @@
module.exports = geometricProgression = (end, start = 1, step = 2) =>
const geometricProgression = (end, start = 1, step = 2) =>
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
(v, i) => start * step ** i
);
module.exports = geometricProgression

View File

@ -1,2 +1,3 @@
module.exports = getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
(dateFinal - dateInitial) / (1000 * 3600 * 24);
module.exports = getDaysDiffBetweenDates

View File

@ -1,4 +1,5 @@
module.exports = getScrollPosition = (el = window) => ({
const getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
});
module.exports = getScrollPosition

View File

@ -1 +1,2 @@
module.exports = getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
module.exports = getStyle

View File

@ -1,2 +1,3 @@
module.exports = getType = v =>
const getType = v =>
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
module.exports = getType

View File

@ -1,4 +1,5 @@
module.exports = getURLParameters = url =>
const getURLParameters = url =>
url
.match(/([^?=&]+)(=([^&]*))/g)
.reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
module.exports = getURLParameters

View File

@ -1,5 +1,6 @@
module.exports = groupBy = (arr, fn) =>
const groupBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
acc[val] = (acc[val] || []).concat(arr[i]);
return acc;
}, {});
module.exports = groupBy

View File

@ -1 +1,2 @@
module.exports = hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
module.exports = hammingDistance

View File

@ -1 +1,2 @@
module.exports = hasClass = (el, className) => el.classList.contains(className);
const hasClass = (el, className) => el.classList.contains(className);
module.exports = hasClass

View File

@ -1,2 +1,3 @@
module.exports = hasFlags = (...flags) =>
const hasFlags = (...flags) =>
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
module.exports = hasFlags

View File

@ -1 +1,2 @@
module.exports = head = arr => arr[0];
const head = arr => arr[0];
module.exports = head

View File

@ -1,4 +1,4 @@
module.exports = hexToRGB = hex => {
const hexToRGB = hex => {
let alpha = false,
h = hex.slice(hex.startsWith('#') ? 1 : 0);
if (h.length === 3) h = [...h].map(x => x + x).join('');
@ -17,3 +17,4 @@ return (
')'
);
};
module.exports = hexToRGB

View File

@ -1 +1,2 @@
module.exports = hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
module.exports = hide

View File

@ -1,4 +1,4 @@
module.exports = howManyTimes = (num, divisor) => {
const howManyTimes = (num, divisor) => {
if (divisor === 1 || divisor === -1) return Infinity;
if (divisor === 0) return 0;
let i = 0;
@ -8,3 +8,4 @@ num = num / divisor;
}
return i;
};
module.exports = howManyTimes

View File

@ -1,7 +1,8 @@
module.exports = httpDelete = (url, callback, err = console.error) => {
const 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();
};
module.exports = httpDelete

View File

@ -1,7 +1,8 @@
module.exports = httpGet = (url, callback, err = console.error) => {
const 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();
};
module.exports = httpGet

View File

@ -1,4 +1,4 @@
module.exports = httpPost = (url, callback, data = null, err = console.error) => {
const httpPost = (url, data, callback, err = console.error) => {
const request = new XMLHttpRequest();
request.open('POST', url, true);
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
@ -6,3 +6,4 @@ request.onload = () => callback(request.responseText);
request.onerror = () => err(request);
request.send(data);
};
module.exports = httpPost

View File

@ -1,4 +1,4 @@
module.exports = httpPut = (url, data, callback, err = console.error) => {
const 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');
@ -6,3 +6,4 @@ request.onload = () => callback(request);
request.onerror = () => err(request);
request.send(data);
};
module.exports = httpPut

View File

@ -1,3 +1,4 @@
module.exports = httpsRedirect = () => {
const httpsRedirect = () => {
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
};
module.exports = httpsRedirect

View File

@ -1,4 +1,5 @@
module.exports = inRange = (n, start, end = null) => {
const inRange = (n, start, end = null) => {
if (end && start > end) end = [start, (start = end)][0];
return end == null ? n >= 0 && n < start : n >= start && n < end;
};
module.exports = inRange

View File

@ -1,5 +1,6 @@
module.exports = indexOfAll = (arr, val) => {
const indexOfAll = (arr, val) => {
const indices = [];
arr.forEach((el, i) => el === val && indices.push(i));
return indices;
};
module.exports = indexOfAll

View File

@ -1 +1,2 @@
module.exports = initial = arr => arr.slice(0, -1);
const initial = arr => arr.slice(0, -1);
module.exports = initial

View File

@ -1,2 +1,3 @@
module.exports = initialize2DArray = (w, h, val = null) =>
const initialize2DArray = (w, h, val = null) =>
Array.from({ length: h }).map(() => Array.from({ length: w }).fill(val));
module.exports = initialize2DArray

View File

@ -1,2 +1,3 @@
module.exports = initializeArrayWithRange = (end, start = 0, step = 1) =>
const initializeArrayWithRange = (end, start = 0, step = 1) =>
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
module.exports = initializeArrayWithRange

View File

@ -0,0 +1,5 @@
const initializeArrayWithRangeRight = (end, start = 0, step = 1) =>
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map(
(v, i, arr) => (arr.length - i - 1) * step + start
);
module.exports = initializeArrayWithRangeRight

View File

@ -0,0 +1,13 @@
const test = require('tape');
const initializeArrayWithRangeRight = require('./initializeArrayWithRangeRight.js');
test('Testing initializeArrayWithRangeRight', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof initializeArrayWithRangeRight === 'function', 'initializeArrayWithRangeRight is a Function');
//t.deepEqual(initializeArrayWithRangeRight(args..), 'Expected');
//t.equal(initializeArrayWithRangeRight(args..), 'Expected');
//t.false(initializeArrayWithRangeRight(args..), 'Expected');
//t.throws(initializeArrayWithRangeRight(args..), 'Expected');
t.end();
});

View File

@ -1 +1,2 @@
module.exports = initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
module.exports = initializeArrayWithValues

View File

@ -1,4 +1,5 @@
module.exports = intersection = (a, b) => {
const intersection = (a, b) => {
const s = new Set(b);
return a.filter(x => s.has(x));
};
module.exports = intersection

View File

@ -1,5 +1,6 @@
module.exports = invertKeyValues = obj =>
const invertKeyValues = obj =>
Object.keys(obj).reduce((acc, key) => {
acc[obj[key]] = key;
return acc;
}, {});
module.exports = invertKeyValues

View File

@ -1 +1,2 @@
module.exports = isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
module.exports = isAbsoluteURL

Some files were not shown because too many files have changed in this diff Show More