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
function stripBOM (content) { | |
return content.charCodeAt(0) === 0xFEFF ? content.slice(1) : content | |
} |
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
function classnames (...classes) { | |
const arr = [] | |
for (const name of classes) { | |
if (typeof name === 'string') { | |
arr.push(name) | |
} | |
else if (typeof name === 'object' && name !== null) { | |
for (let [key, value] of Object.entries(name)) { | |
if (value) arr.push(key) |
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 { useEffect, useRef } from 'preact/hooks' | |
/** | |
* @param {function} callback | |
* @param {number} delay | |
*/ | |
function useAwaitInterval (callback, delay) { | |
const cb = useRef() | |
useEffect(() => { |
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
/** | |
* Deep clones an object or array | |
* @param {object|array} obj Object or array to clone | |
* @returns {object|array} Cloned object or array | |
*/ | |
function deepClone (obj) { | |
if (typeof obj !== 'object' || obj === null) return {}; | |
const res = Array.isArray(obj) ? [] : {}; | |
const queue = [{ base: res, current: 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
function resolveDeps (pkgs, name) { | |
const resolved = []; | |
const missingRequired = []; | |
const missingOptional = []; | |
const queue = [name]; | |
while (queue.length) { | |
const curr = queue.shift(); | |
const pkg = pkgs[curr]; |
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
function throttle (fn, ms) { | |
let throttled = false; | |
return function () { | |
const call = () => fn.apply(this, arguments); | |
if (throttled) return; | |
throttled = true; | |
setTimeout(() => throttled = 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
function debounce (fn, ms, immediate = false) { | |
let timeout; | |
return function () { | |
const call = () => { | |
timeout = null; | |
if (!immediate) fn.apply(this, arguments); | |
}; | |
const now = immediate && !timeout; |
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
class LockError extends Error {} | |
function createLock () { | |
/** @type {boolean} */ | |
let locked = false; | |
/** @type {PromiseObject[]} */ | |
let pending = []; | |
function acquire () { |
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'; | |
const fsp = fs.promises; | |
/** | |
* Creates a directory tree | |
* @param {string} dirname Path to directory to read | |
* @returns {object} A directory tree |
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 debounce<F extends ((...args: any) => any)> ( | |
fn: F, | |
ms: number | |
) { | |
/** | |
* Not the correct type, because of these conflicts: | |
* - Node's setTimeout returns a `Timeout` object | |
* - Browser's setTimeout returns a `number` | |
* | |
* TypeScript doesn't provide an option to specifically exclude certain type |
OlderNewer