Для того чтобы наверняка понимать содержание данного документа потребуется:
- понимание того что такое CommonJS
- понимание того что такое ECMAScript modules
- понимание того что такое React
- понимание того что такое TypeScript
import fs from 'node:fs/promises'; | |
const before = await readJson('./stats_before.json'); | |
const after = await readJson('./stats_after.json'); | |
getDiff(before, after) | |
.sort((a, b) => b[1] - a[1]) | |
.forEach(([key, value]) => { | |
console.log(key, `+${value}`); | |
}); |
import { PluginObj } from '@babel/core'; | |
import fs from 'node:fs'; | |
import path from 'node:path'; | |
export default function nodeModuleResolution(): PluginObj { | |
return { | |
visitor: { | |
ImportOrExportDeclaration: { | |
enter(nodePath, { file }) { | |
if (!file.opts.filename) { |
import { Worker, isMainThread, parentPort } from 'worker_threads'; | |
import jsesc from 'jsesc'; | |
const generateId = (count => () => count++)(0); | |
let escape; | |
if (isMainThread) { | |
const worker = new Worker(new URL('./escape.mjs', import.meta.url)); |
export const loadImage = path => new Promise((resolve, reject) => { | |
const image = new Image(); | |
image.onload = () => resolve(image); | |
image.onerror = () => reject(image); | |
image.src = path; | |
}); |
export const createStore = (reducer, preloadedState, enhancer) => { | |
if (enhancer) return enhancer(createStore)(reducer, preloadedState); | |
const listeners = new Set(); | |
let state = reducer(preloadedState, { type: `INIT:${performance.now()}` }); | |
return { | |
dispatch: action => void (state = reducer(state, action), listeners.forEach(fn => fn())), | |
subscribe: listener => (listeners.add(listener), () => listeners.delete(listener)), | |
getState: () => state, |
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; |
// 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); | |
} |
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), |
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 |