Recursively clone an object.
const obj = {
foo: 'bar'
}
cloneObj(obj);
module.exports = (data, limit = 10) => { | |
let chunk = -1; | |
let chunks = []; | |
for (let index = 0; index < data.length; index++) { | |
if (index % limit === 0) { | |
chunk += 1; | |
chunks.push([]); | |
} |
module.exports = (value) => { | |
return value && typeof value.then === 'function' && typeof value.catch === 'function'; | |
}; |
const PERMISSION_WRITE = 'clipboard-write'; | |
const canUseAsyncAPI = () => { | |
return ( | |
navigator.clipboard && | |
navigator.clipboard.writeText && | |
navigator.permissions && | |
navigator.permissions.request | |
); | |
}; |
module.exports = (foreground, background) => { | |
const l1 = Math.max(foreground, background); | |
const l2 = Math.min(foreground, background); | |
return (l1 + 0.05) / (l2 + 0.05); | |
}; |
module.exports = (red, green, blue) => { | |
const rs = red / 255; | |
const gs = green / 255; | |
const bs = blue / 255; | |
const rn = rs <= 0.03928 ? rs / 12.92 : Math.pow((rs + 0.055) / 1.055, 2.4); | |
const gn = gs <= 0.03928 ? gs / 12.92 : Math.pow((gs + 0.055) / 1.055, 2.4); | |
const bn = bs <= 0.03928 ? bs / 12.92 : Math.pow((bs + 0.055) / 1.055, 2.4); | |
return (0.2126 * rn) + (0.7152 * gn) + (0.0722 * bn); |
module.exports = hex => { | |
if (hex.charAt(0) === '#') { | |
hex = hex.substring(1); | |
} | |
if (hex.length !== 3 && hex.length !== 6) { | |
return false; | |
} | |
if (hex.length === 3) { |
module.exports = (red, green, blue, preferShorthand = false) => { | |
let colours = [red, green, blue].map(value => value.toString(16)); | |
let canBeCondensed = colours.every(value => value.charAt(0) === value.charAt(1)); | |
if (canBeCondensed && preferShorthand) { | |
colours = colours.map(v => v.charAt(0)); | |
} | |
return '#' + colours.join(''); | |
}; |