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 limit = (min, max, num) => Math.min(Math.max(num, min), max) |
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 stopEvent = (e = {}) => { | |
if (typeof e.stopPropagation==='function') e.stopPropagation() | |
if (typeof e.preventDefault==='function') e.preventDefault() | |
} |
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
html = (literalSections, ...substs) => { | |
// Use raw literal sections: We don’t want | |
// backslashes (\n etc.) to be interpreted | |
let raw = literalSections.raw, | |
let result = '' | |
substs.forEach((subst, i) => { | |
// Retrieve the literal section preceding |
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 type = (data) => { | |
return Object.prototype.toString.call(data).replace(/^\[object (.+)\]$/, "$1").toLowerCase() | |
} |
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 each = (data, fn) => { | |
if (data==null) return false | |
if ((data).constructor===Object) return Array.prototype.forEach.call(Object.keys(data), (key) => fn(data[key], key, data)) | |
else return Array.prototype.forEach.call(data, (item, i) => fn(item, i, data)) | |
} |
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
%clearfix { | |
&::before, | |
&::after { | |
content: ' '; | |
display: table; | |
} | |
&::after { | |
clear: both; |
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 duplicate = (arr, duplications) => arr.reduce((acc, val, i) => { | |
const duplication = duplications[i] | |
for (let i = 0; i<duplication; i++) acc.push(val) | |
return acc | |
}, []) |
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 mousePosition = (() => { | |
let pos = {} | |
const position = (e) => ({ | |
x: e.pageX, | |
y: e.pageY | |
}) | |
document.addEventListener('mousemove', (e) => pos = position(e), false) |
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 queue = (query, delay, next) => { | |
if (query.length===0) return next() | |
query[0]() | |
const trimmed = query.slice(1) | |
setTimeout(() => exec(trimmed, delay, next), delay) |
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 loop = (fn, delay) => { | |
const next = () => setTimeout( | |
() => loop(fn, delay), | |
delay | |
) | |
fn(next) | |
} |