This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const memoizedAdd = () => { | |
const cache = new Map(); | |
return (...args) => { | |
const key = args.join(); | |
const cached = cache.get(key); | |
if (cached) { | |
console.log(`Returning cached value for ${key}`); | |
return cached; | |
} else { | |
const result = args.reduce((total, val) => total + val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = new Promise(r => r({ a: 'A' })); | |
const b = new Promise(r => r({ b: 'B' })); | |
const c = new Promise(r => r({ c: 'C' })); | |
const result = (async () => { | |
const abc = await Promise.all([a, b, c]); | |
return abc.reduce((result, obj) => ({...result, ...obj}), {}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ArrayUtils = [ | |
'map', | |
'filter', | |
'find', | |
] | |
.reduce((utils, method) => ({ | |
...utils, | |
[method]: (fn, arr) => arr ? arr[method](fn) : arr => arr[method](fn) | |
}), {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default const renameProps = (map, obj) => | |
Object.entries(map).reduce((accum, [a, b]) => { | |
delete accum[a] | |
return obj[a] | |
? Object.assign(accum, {[b]: obj[a]}) | |
: accum | |
}, {...obj}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tweens a number from `startValue` to `endValue` over the `duration` time period, | |
* calling `onAnimationFrame` on each animation frame. | |
* | |
* @example | |
* // Tween to 100 from 0 over 2 seconds | |
* tweenNumber(n => console.log(`step value: ${n}`), 100, 0, 2000); | |
*/ | |
function tweenNumber ( | |
onAnimationFrame, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function leftpad (str, len, ch) { | |
const val = String(str); | |
const pad = ch === undefined ? ' ' : String(ch); | |
return pad.repeat(Math.max(0, len - val.length), pad) + val; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const zipObject = (keys, vals) => { | |
return keys.reduce( | |
(prev, val, i) => Object.assign(prev, { [val]: vals[i] }), {} | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toTitle = str => { | |
return str.split(/[\W_]+/) | |
.map(word => word.replace(/^\w/, first => first.toUpperCase())) | |
.join(' ') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function callDeep (path, obj, ...args) { | |
var fn = path.split('.').reduce((prev, curr) => prev[curr], obj) | |
return fn.apply(obj, args) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--scale-ratio: 1.4; | |
--scale-bases: 1 1.2; | |
} |
NewerOlder