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
import fs from 'fs'; | |
import path from 'path'; | |
export function readdirRecuriveSync(dir, filelist) { | |
filelist = filelist || []; | |
var files = fs.readdirSync(dir); | |
files.forEach(function (file) { | |
file = path.join(dir, file); |
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 ajax = (url, { | |
method = 'GET', | |
contentType = 'application/x-www-form-urlencoded; charset=UTF-8'; | |
data, | |
onDone, | |
} = {}) => { | |
const xhr = new XMLHttpRequest(); | |
if (typeof onDone === 'function') { | |
const handler = () => onDone(xhr); |
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
import isEqual from 'lodash/isEqual'; | |
import { useState, useEffect, useRef, useMemo as defaultUseMemo } from 'react'; | |
export const useOnMount = callback => { | |
useEffect(callback, []); | |
}; | |
export const useForceUpdate = () => { | |
const [, setState] = useState(null); | |
return () => setState(Math.random()); |
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
import { toRadians, toDegrees } from './math.js'; | |
export const Vec2 = { | |
of (x, y) { | |
return { x, y }; | |
}, | |
length (v) { | |
return Math.sqrt(v.x ** 2 + v.y ** 2); | |
}, |
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 $ = selectors => document.querySelector(selectors); | |
export const $$ = selectors => document.querySelectorAll(selectors); | |
// on(div, 'click touch', () => {}); | |
export const on = (target, eventNames, handler, options) => { | |
const eventNamesList = eventNames.split(' '); | |
eventNamesList.forEach(eventName => { | |
target.addEventListener(eventName, handler, options); |
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
import { default as parse } from 'date-fns/parse'; | |
import { default as isValid } from 'date-fns/isValid'; | |
// like parse but second argument must array of strings | |
// returns date | |
export const parseMultiple = ( | |
dateString, | |
formatString, | |
referenceDate, | |
options |
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 takeChain (timeout, types, task, ...args) => fork(function * () { | |
while (true) { | |
const BREAK_TYPE = `BREAK_${performance.now()}`; | |
const collectedActions = [yield take(types)]; | |
yield fork(putDelayed, timeout, BREAK_TYPE); | |
while (true) { | |
const { action, canceled } = yield race({ | |
action: take(types), |
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
// more minimal version of https://github.com/olahol/scrollparent.js/blob/master/scrollparent.js | |
const regex = /(auto|scroll)/; | |
const isScrollable = element => { | |
let result = false; | |
if (element) { | |
const styles = getComputedStyle(element); | |
result = regex.test(styles.overflow + styles.overflowX + styles.overflowY); | |
} |
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 add = (a, b) => a + b; | |
const sumList = numbers => numbers.reduce(add, 0); | |
const sum = (...startValues) => { | |
let total = sumList(startValues); | |
const fn = (...values) => (total += sumList(values), fn); | |
fn.valueOf = () => total; |
OlderNewer