Last active
January 16, 2025 00:43
-
-
Save Offirmo/a4244fe622cf63d4bdf4f1acb845d59a to your computer and use it in GitHub Desktop.
[JS -- common libs] #JavaScript #TypeScript
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 EventEmitter from 'emittery' | |
const EMITTER_EVT = 'change' | |
const emitter = new EventEmitter<{ [EMITTER_EVT]: string }>() | |
emitter.emit(EMITTER_EVT, `[in-mem]`) | |
const unbind = emitter.on(EMITTER_EVT, (src: string) => { ... }) | |
//////////////////////////////////// | |
import fetch_ponyfill from 'fetch-ponyfill' | |
const { fetch, Request, Response, Headers } = fetch_ponyfill() | |
//////////////////////////////////// | |
import debounce from 'lodash/debounce' | |
//////////////////////////////////// | |
/* | |
"memoize-one": "^5", | |
"@types/memoize-one": "^4", | |
*/ | |
import memoize_one from 'memoize-one' | |
const get_derived: GetDerived = memoize_one(get_derived_unmemoized) | |
//////////////////////////////////// | |
// "tiny-invariant": "^1", | |
import assert from 'tiny-invariant' | |
assert( | |
typeof defaultValue !== 'undefined', | |
`getFeatureFlag: a default value must be provided when querying "${featureFlagName}"!`, | |
) | |
//////////////////////////////////// | |
// "dequal": "^2", | |
import { dequal as is_deep_equal } from 'dequal' | |
assert(is_deep_equal(eventual_state_hint, store_state), 'dispatcher: state hint = store state') | |
//////////////////////////////////// | |
// https://github.com/dphilipson/typescript-string-enums | |
// npm i typescript-string-enums | |
// yarn add typescript-string-enums | |
import { Enum } from 'typescript-string-enums' | |
// tslint:disable-next-line: variable-name | |
export const MarkName = Enum( | |
'initialBundleRequested', | |
'initialBundleLoaded', | |
'appStarted', | |
'reactStarted', | |
'userLoggedIn', | |
'userAttemptedLogin' | |
) | |
export type MarkName = Enum<typeof MarkName> // eslint-disable-line no-redeclare | |
///// | |
Enum.keys(enum) | |
Enum.values(enum) | |
if (!Enum.isType(Color, colorString)) { | |
throw new Error(`${colorString} is not a valid color`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment