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
type ReadableConfig = { | |
separator?: string; | |
unit?: string; | |
formatFn?: (value: number) => string; | |
fractional?: boolean; | |
}; | |
// Sorted from big to small | |
// See: https://www.bipm.org/en/measurement-units | |
const si = [ |
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
export const cached = (fn) => { | |
const cache = new Map(); | |
return function cachedFn(...args) { | |
const input = JSON.stringify(args); | |
if (cache.has(input)) { | |
return cache.get(input); | |
} |
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
export const round = (number: number, fractionDigits = 0): number => { | |
const digits = 10 ** fractionDigits; | |
const value = number * digits * (1 + Number.EPSILON); | |
return Math.round(value) / digits; | |
}; |
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
'use strict'; | |
const queryString = (params) => { | |
const qs = String(new URLSearchParams(params)); | |
return qs ? `?${qs}` : ""; | |
}; | |
const joinBase = (url, baseUrl) => | |
`${baseUrl.replace(/\/$/, "")}/${url.replace(/^\/|\/$/, "")}/`; |
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
import { | |
notEmpty, | |
booleanType, | |
numberType, | |
numberMin, | |
numberMax, | |
numberGt, | |
numberLt, | |
numberBetween, | |
integerType, |
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 onSubmit = () => { | |
closeModal(); | |
saveNameAction(); | |
}; | |
// Component |
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 queryString = (params) => { | |
const qs = String(new URLSearchParams(params)); | |
return qs ? `?${qs}` : ""; | |
}; | |
const joinBase = (url, baseUrl) => | |
`${baseUrl.replace(/\/$/, "")}/${url.replace(/^\/|\/$/, "")}/`; | |
const contentTypeJson = { "Content-Type": "application/json" }; |
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
// Run each test in the new tab | |
const { performance, PerformanceObserver } = typeof window !== 'undefined' ? window : require('perf_hooks'); | |
function test() { | |
let objectSize = 30; | |
let iterations = 7000; | |
const values = { | |
'ENTRIES': 0, | |
'FOR-OF-KEYS': 0, |
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
// @flow | |
const myEvent = new CustomEvent<{ body: string }>('eventType', { | |
detail: { body: 'Specific Text' }, | |
}); | |
const myEventHandler = (event: typeof myEvent) => { | |
if (event.detail.body === 'Specific Text') { | |
// perform a certain action | |
} |
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 groupEvents = events => { | |
for (const fromEvent of events) { | |
const eventCreate = fromEvent.create; | |
fromEvent.create = (data, fullName, args) => { | |
const [meta = {}] = args; | |
if (meta !== null && !meta.single) { | |
for (const toEvent of events) { | |
if (toEvent !== fromEvent) { | |
toEvent(data, { single: true }); |
NewerOlder