This file contains hidden or 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 secs2Time = (secs) => { | |
| const hours = Math.floor(secs / 60 / 60).toString().padStart(2, 0) | |
| return hours + ':' + new Date(secs * 1000).toISOString().substr(14, 5) | |
| } |
This file contains hidden or 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 download(filename, text) { | |
| Object.assign(document.createElement("a"), { | |
| download: filename, | |
| href: "data:text/plain;charset=utf-8," + encodeURIComponent(text), | |
| }).click(); | |
| } |
This file contains hidden or 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 chainable(obj) { | |
| const proxy = new Proxy(obj, { | |
| get(target, prop) { | |
| return typeof target[prop] === 'function' | |
| ? (...args) => target[prop](...args) || proxy | |
| : target[prop] | |
| }, | |
| }) | |
| return proxy | |
| } |
This file contains hidden or 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 withMemoization(func, identifierFunc) { | |
| const cache = new Map() | |
| return (...args) => { | |
| const identifier = identifierFunc(...args) | |
| if (cache.has(identifier)) { | |
| return cache.get(identifier) | |
| } | |
| const result = func(...args) | |
| cache.set(identifier, result) |
This file contains hidden or 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 SORT_STRATEGIES = { | |
| asc: (a, b) => (a - b > 0 ? 1 : -1), | |
| desc: (a, b) => (a - b < 0 ? 1 : -1), | |
| }; | |
| const pipe = (...fns) => | |
| fns.reduce( | |
| (f, g) => | |
| (...args) => | |
| g(f(...args)) |
This file contains hidden or 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 createInterval = () => { | |
| let interval = null | |
| const start = (cb, delay) => !interval && (interval = setInterval(cb, delay)) | |
| const stop = () => { | |
| clearInterval(interval) | |
| interval = null | |
| } | |
| return { start, stop } | |
| } |
This file contains hidden or 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
| <div id="app"></div> | |
| <script> | |
| const $ = (...args) => { | |
| if (args.length > 1) args.reverse() | |
| const [query, parent = document] = args | |
| return Array.from(parent.querySelectorAll(query)) | |
| } | |
| $.create = (html) => { |
This file contains hidden or 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 timeTaken = | |
| (fn) => | |
| async (...args) => { | |
| console.time(fn.name); | |
| const res = await fn(...args); | |
| console.timeEnd(fn.name); | |
| return res; | |
| }; |
This file contains hidden or 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 getGlobals = (() => { | |
| const diff = (a, b) => a.filter((v) => !b.includes(v)) | |
| const windowProps = JSON.parse( | |
| '["window","self","document","name","location","customElements","history","locationbar","menubar","personalbar","scrollbars","statusbar","toolbar","status","closed","frames","length","top","opener","parent","frameElement","navigator","origin","external","screen","innerWidth","innerHeight","scrollX","pageXOffset","scrollY","pageYOffset","visualViewport","screenX","screenY","outerWidth","outerHeight","devicePixelRatio","clientInformation","screenLeft","screenTop","defaultStatus","defaultstatus","styleMedia","onsearch","isSecureContext","performance","onappinstalled","onbeforeinstallprompt","crypto","indexedDB","webkitStorageInfo","sessionStorage","localStorage","onbeforexrselect","onabort","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","o |
This file contains hidden or 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 prop(value, path) { | |
| path = path | |
| .replace(/\[(\d)\]/g, (_, v) => '.' + v) | |
| .replace(/^\./, '') | |
| .split('.') | |
| let current = value | |
| for (let prop of path) { | |
| if (current[prop]) current = current[prop] | |
| else return current[prop] | |
| } |