@take-out/helpers 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types/array/getRandomItem.d.ts +0 -3
- package/types/array/getRandomItem.d.ts.map +0 -11
- package/types/array/takeLast.d.ts +0 -3
- package/types/array/takeLast.d.ts.map +0 -11
- package/types/array/uniqBy.d.ts +0 -12
- package/types/array/uniqBy.d.ts.map +0 -11
- package/types/assert.d.ts +0 -6
- package/types/assert.d.ts.map +0 -11
- package/types/async/abortable.d.ts +0 -10
- package/types/async/abortable.d.ts.map +0 -11
- package/types/async/asyncContext.d.ts +0 -8
- package/types/async/asyncContext.d.ts.map +0 -11
- package/types/async/asyncContext.native.d.ts +0 -8
- package/types/async/asyncContext.native.d.ts.map +0 -11
- package/types/async/idle.d.ts +0 -8
- package/types/async/idle.d.ts.map +0 -11
- package/types/async/interval.d.ts +0 -3
- package/types/async/interval.d.ts.map +0 -11
- package/types/async/isAborted.d.ts +0 -3
- package/types/async/isAborted.d.ts.map +0 -11
- package/types/async/sleep.d.ts +0 -3
- package/types/async/sleep.d.ts.map +0 -11
- package/types/async/useAsync.d.ts +0 -3
- package/types/async/useAsync.d.ts.map +0 -11
- package/types/async/useAsyncEffect.d.ts +0 -12
- package/types/async/useAsyncEffect.d.ts.map +0 -11
- package/types/async/useLazyMount.d.ts +0 -9
- package/types/async/useLazyMount.d.ts.map +0 -11
- package/types/async/useLazyValue.d.ts +0 -6
- package/types/async/useLazyValue.d.ts.map +0 -11
- package/types/browser/clearIndexedDB.d.ts +0 -3
- package/types/browser/clearIndexedDB.d.ts.map +0 -11
- package/types/browser/isActiveElementFormField.d.ts +0 -3
- package/types/browser/isActiveElementFormField.d.ts.map +0 -11
- package/types/browser/openPopup.d.ts +0 -3
- package/types/browser/openPopup.d.ts.map +0 -11
- package/types/client-only.d.ts +0 -2
- package/types/client-only.d.ts.map +0 -11
- package/types/clipboard/clipboard.d.ts +0 -3
- package/types/clipboard/clipboard.d.ts.map +0 -11
- package/types/clipboard/clipboard.native.d.ts +0 -3
- package/types/clipboard/clipboard.native.d.ts.map +0 -11
- package/types/color/extractOpacityFromColor.d.ts +0 -3
- package/types/color/extractOpacityFromColor.d.ts.map +0 -11
- package/types/color/generateColors.d.ts +0 -11
- package/types/color/generateColors.d.ts.map +0 -11
- package/types/color/lum.d.ts +0 -3
- package/types/color/lum.d.ts.map +0 -11
- package/types/color/toHex.d.ts +0 -4
- package/types/color/toHex.d.ts.map +0 -11
- package/types/constants.d.ts +0 -10
- package/types/constants.d.ts.map +0 -17
- package/types/debug/debugLog.d.ts +0 -11
- package/types/debug/debugLog.d.ts.map +0 -11
- package/types/debug/debugUseState.d.ts +0 -3
- package/types/debug/debugUseState.d.ts.map +0 -11
- package/types/emitter.d.ts +0 -77
- package/types/emitter.d.ts.map +0 -11
- package/types/ensure/ensure.d.ts +0 -6
- package/types/ensure/ensure.d.ts.map +0 -11
- package/types/ensure/ensureOne.d.ts +0 -3
- package/types/ensure/ensureOne.d.ts.map +0 -11
- package/types/error/errors.d.ts +0 -8
- package/types/error/errors.d.ts.map +0 -11
- package/types/function/emptyFn.d.ts +0 -3
- package/types/function/emptyFn.d.ts.map +0 -11
- package/types/function/identityFn.d.ts +0 -3
- package/types/function/identityFn.d.ts.map +0 -11
- package/types/function/throttle.d.ts +0 -23
- package/types/function/throttle.d.ts.map +0 -11
- package/types/global/globalEffect.d.ts +0 -3
- package/types/global/globalEffect.d.ts.map +0 -11
- package/types/global/globalValue.d.ts +0 -24
- package/types/global/globalValue.d.ts.map +0 -11
- package/types/index.d.ts +0 -78
- package/types/index.d.ts.map +0 -11
- package/types/number/formatNumber.d.ts +0 -13
- package/types/number/formatNumber.d.ts.map +0 -11
- package/types/object/decorateObject.d.ts +0 -3
- package/types/object/decorateObject.d.ts.map +0 -11
- package/types/object/isEqualDeep.d.ts +0 -6
- package/types/object/isEqualDeep.d.ts.map +0 -14
- package/types/object/isEqualIdentity.d.ts +0 -3
- package/types/object/isEqualIdentity.d.ts.map +0 -11
- package/types/object/isEqualJSON.d.ts +0 -3
- package/types/object/isEqualJSON.d.ts.map +0 -11
- package/types/object/isEqualNever.d.ts +0 -3
- package/types/object/isEqualNever.d.ts.map +0 -11
- package/types/object/mapObject.d.ts +0 -6
- package/types/object/mapObject.d.ts.map +0 -11
- package/types/object/object.d.ts +0 -12
- package/types/object/object.d.ts.map +0 -11
- package/types/object/objectUniqueKey.d.ts +0 -3
- package/types/object/objectUniqueKey.d.ts.map +0 -11
- package/types/react/createGlobalContext.d.ts +0 -4
- package/types/react/createGlobalContext.d.ts.map +0 -11
- package/types/react/getCurrentComponentStack.d.ts +0 -3
- package/types/react/getCurrentComponentStack.d.ts.map +0 -11
- package/types/server/ensureEnv.d.ts +0 -3
- package/types/server/ensureEnv.d.ts.map +0 -11
- package/types/server/getHeaders.d.ts +0 -3
- package/types/server/getHeaders.d.ts.map +0 -11
- package/types/server/prettyPrintRequest.d.ts +0 -3
- package/types/server/prettyPrintRequest.d.ts.map +0 -11
- package/types/server/prettyPrintResponse.d.ts +0 -3
- package/types/server/prettyPrintResponse.d.ts.map +0 -11
- package/types/server/streamToString.d.ts +0 -3
- package/types/server/streamToString.d.ts.map +0 -11
- package/types/server-only.d.ts +0 -2
- package/types/server-only.d.ts.map +0 -11
- package/types/storage/createStorage.d.ts +0 -65
- package/types/storage/createStorage.d.ts.map +0 -11
- package/types/storage/driver.d.ts +0 -5
- package/types/storage/driver.d.ts.map +0 -11
- package/types/storage/storage.test.d.ts +0 -3
- package/types/storage/storage.test.d.ts.map +0 -11
- package/types/storage/types.d.ts +0 -8
- package/types/storage/types.d.ts.map +0 -11
- package/types/string/dedent.d.ts +0 -3
- package/types/string/dedent.d.ts.map +0 -11
- package/types/string/ellipsis.d.ts +0 -3
- package/types/string/ellipsis.d.ts.map +0 -11
- package/types/string/hash.d.ts +0 -4
- package/types/string/hash.d.ts.map +0 -11
- package/types/string/insertAtIndex.d.ts +0 -3
- package/types/string/insertAtIndex.d.ts.map +0 -11
- package/types/string/nbspLastWord.d.ts +0 -7
- package/types/string/nbspLastWord.d.ts.map +0 -11
- package/types/string/pickLast.d.ts +0 -3
- package/types/string/pickLast.d.ts.map +0 -11
- package/types/string/pluralize.d.ts +0 -5
- package/types/string/pluralize.d.ts.map +0 -11
- package/types/string/pluralize.native.d.ts +0 -4
- package/types/string/pluralize.native.d.ts.map +0 -13
- package/types/string/randomId.d.ts +0 -3
- package/types/string/randomId.d.ts.map +0 -11
- package/types/string/slugify.d.ts +0 -3
- package/types/string/slugify.d.ts.map +0 -11
- package/types/string/truncateList.d.ts +0 -17
- package/types/string/truncateList.d.ts.map +0 -11
- package/types/time/formatDate.d.ts +0 -5
- package/types/time/formatDate.d.ts.map +0 -11
- package/types/time/formatDateRelative.d.ts +0 -3
- package/types/time/formatDateRelative.d.ts.map +0 -11
- package/types/time/formatDistanceToNow.d.ts +0 -3
- package/types/time/formatDistanceToNow.d.ts.map +0 -11
- package/types/time/time.d.ts +0 -29
- package/types/time/time.d.ts.map +0 -13
- package/types/time/useTimer.d.ts +0 -11
- package/types/time/useTimer.d.ts.map +0 -11
- package/types/types/NullToOptional.d.ts +0 -3
- package/types/types/NullToOptional.d.ts.map +0 -11
- package/types/types/object.d.ts +0 -16
- package/types/types/object.d.ts.map +0 -11
- package/types/types/react.d.ts +0 -3
- package/types/types/react.d.ts.map +0 -11
- package/types/types/timer.d.ts +0 -3
- package/types/types/timer.d.ts.map +0 -11
- package/types/types/tuple.d.ts +0 -3
- package/types/types/tuple.d.ts.map +0 -11
- package/types/url/urlSanitize.d.ts +0 -3
- package/types/url/urlSanitize.d.ts.map +0 -11
- package/types/url/urlValidate.d.ts +0 -3
- package/types/url/urlValidate.d.ts.map +0 -11
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAEA,OAAO,iBAAS,cAAc,GAC5B,WAAW,GAAG,MAAM,SAAS,MAAM,eAAe,QAChD,GAAG,MAAM,SAAS,MAAM,eAAe",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/debug/debugUseState.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"import { useCallback } from 'react'\n\nexport function debugUseState<T>(\n useState: [T, React.Dispatch<React.SetStateAction<T>>]\n): [T, React.Dispatch<React.SetStateAction<T>>] {\n const [state, setState] = useState\n\n const wrappedSetState = useCallback(\n (newValue: T | ((prevState: T) => T)) => {\n if (typeof newValue === 'function') {\n // Handle callback style\n setState((prevState: T) => {\n const nextState = (newValue as (prevState: T) => T)(prevState)\n console.trace('State update (callback):', {\n prevState,\n nextState,\n stack: new Error().stack,\n })\n return nextState\n })\n } else {\n // Handle direct value style\n console.trace('State update (direct):', {\n prevState: state,\n nextState: newValue,\n stack: new Error().stack,\n })\n setState(newValue)\n }\n },\n [setState, state]\n )\n\n return [state, wrappedSetState]\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
package/types/emitter.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { JSX, PropsWithChildren } from "react";
|
|
2
|
-
type EmitterOptions<T> = CreateEmitterOpts<T> & {
|
|
3
|
-
name: string;
|
|
4
|
-
};
|
|
5
|
-
type CreateEmitterOpts<T> = {
|
|
6
|
-
silent?: boolean;
|
|
7
|
-
comparator?: (a: T, b: T) => boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare class Emitter<const T> {
|
|
10
|
-
private disposables;
|
|
11
|
-
value: T;
|
|
12
|
-
options?: EmitterOptions<T>;
|
|
13
|
-
constructor(value: T, options?: EmitterOptions<T>);
|
|
14
|
-
listen: (disposable: (cb: T) => void) => (() => void);
|
|
15
|
-
emit: (next: T) => void;
|
|
16
|
-
nextValue: () => Promise<T>;
|
|
17
|
-
}
|
|
18
|
-
export declare function createGlobalEmitter<T>(name: string, defaultValue: T, options?: CreateEmitterOpts<T>): Emitter<T>;
|
|
19
|
-
export declare function createEmitter<T>(name: string, defaultValue: T, options?: CreateEmitterOpts<T>): Emitter<T>;
|
|
20
|
-
export type EmitterType<E extends Emitter<any>> = E extends Emitter<infer Val> ? Val : never;
|
|
21
|
-
export declare const useEmitter: <E extends Emitter<any>>(emitter: E, cb: (cb: EmitterType<E>) => void, args?: any[]) => void;
|
|
22
|
-
export declare const useEmitterValue: <E extends Emitter<any>>(emitter: E, options?: {
|
|
23
|
-
disable?: boolean;
|
|
24
|
-
}) => EmitterType<E>;
|
|
25
|
-
/**
|
|
26
|
-
* By default selectors run every render, as well as when emitters update. This is a change
|
|
27
|
-
* from the previous behavior where they only ran when emitters changed value.
|
|
28
|
-
*
|
|
29
|
-
* The reason for this is because emitters capture the variables in scope of the component
|
|
30
|
-
* each render already by using "useGet" by default, which makes them easier to use - you
|
|
31
|
-
* don't need to pass an args[] array except for edge cases.
|
|
32
|
-
*
|
|
33
|
-
* Before explaining why we switched to the default, understand the different uses:
|
|
34
|
-
*
|
|
35
|
-
* - Default behavior - selector is updated every render, and ran every render, as well as
|
|
36
|
-
* when emitter value changes, so you basically are always up to date.
|
|
37
|
-
*
|
|
38
|
-
* - Set an args[] array as the fourth argument - this will stop the automatic capturing
|
|
39
|
-
* and instead update selector only when you change args[] yourself. This is good for when you
|
|
40
|
-
* want explicit control over re-selection and rendering.
|
|
41
|
-
*
|
|
42
|
-
* - With { lazy: true }, the selector only runs when the emitter value changes. If used with
|
|
43
|
-
* args[], you capture the context of the selector based on args[], if not, it's based on the
|
|
44
|
-
* current render.
|
|
45
|
-
*
|
|
46
|
-
* I made this change when we had 16 usages of useEmitterSelector and 100% of them are doing very
|
|
47
|
-
* cheap calculations, so this feels like the right pattern. For the rare case of a heavy selector,
|
|
48
|
-
* you have the option to control it.
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
export declare const useEmitterSelector: <
|
|
52
|
-
E extends Emitter<any>,
|
|
53
|
-
T extends EmitterType<E>,
|
|
54
|
-
R
|
|
55
|
-
>(emitter: E, selector: (value: T) => R, options?: {
|
|
56
|
-
disable?: boolean;
|
|
57
|
-
lazy?: boolean;
|
|
58
|
-
}, args?: any[]) => R;
|
|
59
|
-
export declare const useEmittersSelector: <
|
|
60
|
-
const E extends readonly Emitter<any>[],
|
|
61
|
-
R
|
|
62
|
-
>(emitters: E, selector: (values: { [K in keyof E] : EmitterType<E[K]> }) => R, options?: {
|
|
63
|
-
disable?: boolean;
|
|
64
|
-
isEqual?: (a: R, b: R) => boolean;
|
|
65
|
-
}) => R;
|
|
66
|
-
export declare const createUseEmitter: <E extends Emitter<any>>(emitter: E) => ((cb: (val: EmitterType<E>) => void, args?: any[]) => void);
|
|
67
|
-
export declare const createUseSelector: <E extends Emitter<any>>(emitter: E) => (<R>(selector: (value: EmitterType<E>) => R, options?: {
|
|
68
|
-
disable?: boolean;
|
|
69
|
-
lazy?: boolean;
|
|
70
|
-
}, args?: any[]) => R);
|
|
71
|
-
export declare function createContextualEmitter<T>(name: string, defaultValue: T, defaultOptions?: Omit<EmitterOptions<T>, "name">): readonly [() => Emitter<T>, (props: PropsWithChildren<{
|
|
72
|
-
value?: T;
|
|
73
|
-
silent?: boolean;
|
|
74
|
-
}>) => JSX.Element];
|
|
75
|
-
export {};
|
|
76
|
-
|
|
77
|
-
//# sourceMappingURL=emitter.d.ts.map
|
package/types/emitter.d.ts.map
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAUA,cAAc,KAAK,yBAAyB;KAwBvC,eAAe,KAAK,kBAAkB,KAAK;CAC9C;;KAGG,kBAAkB,KAAK;CAC1B;CACA,cAAc,GAAG,GAAG,GAAG;;AAGzB,OAAO,cAAM,cAAc,GAAG;CAC5B,QAAQ;CACR,OAAO;CACP,UAAU,eAAe;CAEzB,YAAY,OAAO,GAAG,UAAU,eAAe;CAK/C,SAAU,aAAa,IAAI;CAO3B,OAAQ,MAAM;CAqCd,iBAAgB,QAAQ;;AAW1B,OAAO,iBAAS,oBAAoB,GAClC,cACA,cAAc,GACd,UAAU,kBAAkB,KAC3B,QAAQ;AAIX,OAAO,iBAAS,cAAc,GAC5B,cACA,cAAc,GACd,UAAU,kBAAkB,KAC3B,QAAQ;AAKX,YAAY,YAAY,UAAU,gBAChC,UAAU,cAAc,OAAO;AAEjC,OAAO,cAAM,aAAc,UAAU,cACnC,SAAS,GACT,KAAK,IAAI,YAAY,aACrB;AAkBF,OAAO,cAAM,kBAAmB,UAAU,cACxC,SAAS,GACT,UAAU;CAAE;MACX,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDf,OAAO,cAAM;CAAsB,UAAU;CAAc,UAAU,YAAY;CAAI;EACnF,SAAS,GACT,WAAW,OAAO,MAAM,GACxB,UAAU;CACR;CACA;GAEF,iBACC;AAgCH,OAAO,cAAM;OAA6B,mBAAmB;CAAgB;EAC3E,UAAU,GACV,WAAW,WAAW,WAAW,KAAI,YAAY,EAAE,UAAU,GAC7D,UAAU;CAAE;CAAmB,WAAW,GAAG,GAAG,GAAG;MAClD;AAgDH,OAAO,cAAM,mBAAoB,UAAU,cACzC,SAAS,QACN,KAAK,KAAK,YAAY,aAAa;AAKxC,OAAO,cAAM,oBAAqB,UAAU,cAC1C,SAAS,QACN,GACH,WAAW,OAAO,YAAY,OAAO,GACrC,UAAU;CAAE;CAAmB;GAC/B,iBACG;AAUL,OAAO,iBAAS,wBAAwB,GACtC,cACA,cAAc,GACd,iBAAiB,KAAK,eAAe,IAAI,0BAEnC,QAAQ,KACb,OAAO,kBAAkB;CAAE,QAAQ;CAAG;OAAwB,IAAI",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/emitter.tsx"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"import { dequal } from 'dequal'\nimport * as React from 'react'\nimport { use, useLayoutEffect, useState } from 'react'\n\nimport { handleAbortError } from './async/abortable'\nimport { DEBUG_LEVEL, EMPTY_ARRAY } from './constants'\nimport { AbortError } from './error/errors'\nimport { globalValue } from './global/globalValue'\nimport { createGlobalContext } from './react/createGlobalContext'\n\nimport type { JSX, PropsWithChildren } from 'react'\n\n// keeps a reference to the current value easily\n\n// TODO can replace with useEffectEvent\nfunction useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = React.useRef<any>(initialValue ?? currentValue)\n\n useLayoutEffect(() => {\n curRef.current = currentValue\n })\n\n return React.useCallback(\n forwardToFunction\n ? (...args) => curRef.current?.apply(null, args)\n : () => curRef.current,\n []\n )\n}\n\ntype EmitterOptions<T> = CreateEmitterOpts<T> & {\n name: string\n}\n\ntype CreateEmitterOpts<T> = {\n silent?: boolean\n comparator?: (a: T, b: T) => boolean\n}\n\nexport class Emitter<const T> {\n private disposables = new Set<(cb: any) => void>()\n value: T\n options?: EmitterOptions<T>\n\n constructor(value: T, options?: EmitterOptions<T>) {\n this.value = value\n this.options = options\n }\n\n listen = (disposable: (cb: T) => void): (() => void) => {\n this.disposables.add(disposable)\n return (): void => {\n this.disposables.delete(disposable)\n }\n }\n\n emit = (next: T): void => {\n if (process.env.NODE_ENV === 'development') {\n setCache(this, next)\n }\n const compare = this.options?.comparator\n if (compare) {\n if (this.value && compare(this.value, next)) {\n return\n }\n } else {\n if (this.value === next) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `[emitter] ${this.options?.name} no comparator option but received same value!\n \nthis will emit the same value again, which can be desirable, but we warn to ensure it's not unintended:\n\n- if you want this behavior, add { comparator: isEqualNever }\n- if you want only non-equal values: { comparator: isEqualIdentity }\n- if you want only deeply non-equal values: { comparator: isEqualDeep }`\n )\n }\n }\n }\n this.value = next\n if (DEBUG_LEVEL > 1) {\n if (!this.options?.silent) {\n const name = this.options?.name\n console.groupCollapsed(`📣 ${name}`)\n console.info(next)\n console.trace(`trace >`)\n console.groupEnd()\n }\n }\n this.disposables.forEach((cb) => cb(next))\n }\n\n nextValue = (): Promise<T> => {\n return new Promise<T>((res) => {\n const dispose = this.listen((val) => {\n dispose()\n res(val)\n })\n })\n }\n}\n\n// just createEmitter but ensures it doesn't mess up on HMR\nexport function createGlobalEmitter<T>(\n name: string,\n defaultValue: T,\n options?: CreateEmitterOpts<T>\n): Emitter<T> {\n return globalValue(name, () => createEmitter(name, defaultValue, options))\n}\n\nexport function createEmitter<T>(\n name: string,\n defaultValue: T,\n options?: CreateEmitterOpts<T>\n): Emitter<T> {\n const existing = createOrUpdateCache(name, defaultValue) as T\n return new Emitter<T>(existing || defaultValue, { name, ...options })\n}\n\nexport type EmitterType<E extends Emitter<any>> =\n E extends Emitter<infer Val> ? Val : never\n\nexport const useEmitter = <E extends Emitter<any>>(\n emitter: E,\n cb: (cb: EmitterType<E>) => void,\n args?: any[]\n): void => {\n const getCallback = useGet(cb)\n\n useLayoutEffect(() => {\n return emitter.listen((val) => {\n try {\n getCallback()(val)\n } catch (err) {\n handleAbortError(err)\n }\n })\n }, [emitter, getCallback])\n}\n\n// i think this was useSyncExternalStore but removed for concurrent rendering improvements\n// wondering if we could just always return a deferred value? or default to it?\n\nexport const useEmitterValue = <E extends Emitter<any>>(\n emitter: E,\n options?: { disable?: boolean }\n): EmitterType<E> => {\n const disabled = options?.disable\n\n // use a function initializer to get current emitter value\n const [state, setState] = useState<EmitterType<E>>(() => emitter.value)\n\n useLayoutEffect(() => {\n if (disabled) return\n\n // sync immediately in case emitter changed between render and effect\n if (emitter.value !== state) {\n setState(emitter.value)\n }\n\n return emitter.listen(setState)\n // intentionally omit state from deps - we only want to re-subscribe when emitter changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [disabled, emitter])\n\n return state\n}\n\n/**\n * By default selectors run every render, as well as when emitters update. This is a change\n * from the previous behavior where they only ran when emitters changed value.\n *\n * The reason for this is because emitters capture the variables in scope of the component\n * each render already by using \"useGet\" by default, which makes them easier to use - you\n * don't need to pass an args[] array except for edge cases.\n *\n * Before explaining why we switched to the default, understand the different uses:\n *\n * - Default behavior - selector is updated every render, and ran every render, as well as\n * when emitter value changes, so you basically are always up to date.\n *\n * - Set an args[] array as the fourth argument - this will stop the automatic capturing\n * and instead update selector only when you change args[] yourself. This is good for when you\n * want explicit control over re-selection and rendering.\n *\n * - With { lazy: true }, the selector only runs when the emitter value changes. If used with\n * args[], you capture the context of the selector based on args[], if not, it's based on the\n * current render.\n *\n * I made this change when we had 16 usages of useEmitterSelector and 100% of them are doing very\n * cheap calculations, so this feels like the right pattern. For the rare case of a heavy selector,\n * you have the option to control it.\n *\n */\nexport const useEmitterSelector = <E extends Emitter<any>, T extends EmitterType<E>, R>(\n emitter: E,\n selector: (value: T) => R,\n options?: {\n disable?: boolean\n lazy?: boolean\n },\n args: any[] = EMPTY_ARRAY\n): R => {\n const [state, setState] = useState<R>(() => selector(emitter.value))\n const disabled = options?.disable\n const getSelector = useGet(selector)\n\n if (options?.lazy !== true) {\n const next = selector(emitter.value)\n if (next !== state) {\n setState(next)\n }\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n if (disabled) return\n return emitter.listen((val) => {\n try {\n const selectorFn = args !== EMPTY_ARRAY ? selector : getSelector()\n const next = selectorFn(val)\n setState(next)\n } catch (error) {\n if (error instanceof AbortError) {\n return\n }\n throw error\n }\n })\n }, [disabled, emitter, getSelector, ...args])\n\n return state\n}\n\nexport const useEmittersSelector = <const E extends readonly Emitter<any>[], R>(\n emitters: E,\n selector: (values: { [K in keyof E]: EmitterType<E[K]> }) => R,\n options?: { disable?: boolean; isEqual?: (a: R, b: R) => boolean }\n): R => {\n const getSelector = useGet(selector)\n const disabled = options?.disable\n\n const [state, setState] = useState<R>(() => {\n const values = emitters.map((e) => e.value) as { [K in keyof E]: EmitterType<E[K]> }\n return getSelector()(values)\n })\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n if (disabled) {\n return\n }\n\n const handler = () => {\n const values = emitters.map((e) => e.value) as {\n [K in keyof E]: EmitterType<E[K]>\n }\n try {\n const next = getSelector()(values)\n setState((prev) => {\n if (options?.isEqual?.(prev, next)) {\n return prev\n }\n if (dequal(prev, next)) {\n return prev\n }\n return next\n })\n } catch (error) {\n if (error instanceof AbortError) {\n return\n }\n throw error\n }\n }\n\n const disposals = emitters.map((emitter) => emitter.listen(handler))\n\n return () => {\n disposals.forEach((d) => d())\n }\n }, [disabled, getSelector, ...emitters])\n\n return state\n}\n\nexport const createUseEmitter = <E extends Emitter<any>>(\n emitter: E\n): ((cb: (val: EmitterType<E>) => void, args?: any[]) => void) => {\n return (cb: (val: EmitterType<E>) => void, args?: any[]) =>\n useEmitter(emitter, cb, args)\n}\n\nexport const createUseSelector = <E extends Emitter<any>>(\n emitter: E\n): (<R>(\n selector: (value: EmitterType<E>) => R,\n options?: { disable?: boolean; lazy?: boolean },\n args?: any[]\n) => R) => {\n return <R,>(\n selector: (value: EmitterType<E>) => R,\n options?: { disable?: boolean; lazy?: boolean },\n args?: any[]\n ): R => {\n return useEmitterSelector(emitter, selector, options, args)\n }\n}\n\nexport function createContextualEmitter<T>(\n name: string,\n defaultValue: T,\n defaultOptions?: Omit<EmitterOptions<T>, 'name'>\n): readonly [\n () => Emitter<T>,\n (props: PropsWithChildren<{ value?: T; silent?: boolean }>) => JSX.Element,\n] {\n const id = Math.random().toString(36)\n const EmitterContext = createGlobalContext<Emitter<T> | null>(\n `contextual-emitter/${id}`,\n null\n )\n\n const useContextEmitter = () => {\n const emitter = use(EmitterContext)\n if (!emitter) {\n throw new Error('useContextEmitter must be used within an EmitterProvider')\n }\n return emitter\n }\n\n type ProvideEmitterProps = PropsWithChildren<{\n value?: T\n silent?: boolean\n }>\n\n const ProvideEmitter = (props: ProvideEmitterProps) => {\n const { children, value, silent } = props\n const [emitter] = useState(\n () => new Emitter<T>(value ?? defaultValue, { name, silent, ...defaultOptions })\n )\n\n useLayoutEffect(() => {\n if (value !== undefined && value !== emitter.value) {\n emitter.emit(value)\n }\n }, [value, emitter])\n\n return <EmitterContext.Provider value={emitter}>{children}</EmitterContext.Provider>\n }\n\n return [useContextEmitter, ProvideEmitter] as const\n}\n\nconst HMRCache =\n process.env.NODE_ENV === 'development'\n ? new Map<string, { originalDefaultValue: unknown; currentValue: unknown }>()\n : null\n\nfunction setCache(emitter: Emitter<any>, value: unknown) {\n const name = emitter.options?.name\n if (!name) return\n const cache = HMRCache?.get(name)\n if (!cache) return\n cache.currentValue = value\n}\n\nfunction createOrUpdateCache(name: string, defaultValueProp: unknown) {\n const existing = HMRCache?.get(name)\n const defaultValue = dequal(existing?.originalDefaultValue, defaultValueProp)\n ? existing?.currentValue\n : defaultValueProp\n\n if (!existing) {\n HMRCache?.set(name, {\n originalDefaultValue: defaultValueProp,\n currentValue: defaultValue,\n })\n }\n\n return defaultValue\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
package/types/ensure/ensure.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare function ensureExists<T>(value: T | undefined | null, msg?: string): asserts value is T;
|
|
2
|
-
export declare function ensure<T>(value: T, msg?: string): asserts value is Exclude<T, null | undefined | false>;
|
|
3
|
-
export declare function ensureError(val: unknown): asserts val is Error;
|
|
4
|
-
export declare function ensureString(val: unknown, name?: string): asserts val is string;
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=ensure.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAEA,OAAO,iBAAS,aAAa,GAC3B,OAAO,sBACP,uBACS,SAAS;AAMpB,OAAO,iBAAS,OAAO,GACrB,OAAO,GACP,uBACS,SAAS,QAAQ,sBAAsB;AAMlD,OAAO,iBAAS,YAAY,uBAAuB,OAAO;AAM1D,OAAO,iBAAS,aAAa,cAAc,wBAA6B",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/ensure/ensure.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"import { EnsureError } from '../error/errors'\n\nexport function ensureExists<T>(\n value: T | undefined | null,\n msg = ''\n): asserts value is T {\n if (value === undefined || value === null) {\n throw new EnsureError(`Invalid nullish value (${value}): ${msg}`)\n }\n}\n\nexport function ensure<T>(\n value: T,\n msg = ''\n): asserts value is Exclude<T, null | undefined | false> {\n if (!value) {\n throw new EnsureError(`ensure() invalid: (${value}): ${msg} ${new Error().stack}`)\n }\n}\n\nexport function ensureError(val: unknown): asserts val is Error {\n if (!(val instanceof Error)) {\n throw val\n }\n}\n\nexport function ensureString(val: unknown, name = '(unnamed)'): asserts val is string {\n if (typeof val !== 'string') {\n throw new EnsureError(`No string ${name}`)\n }\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAIA,OAAO,iBAAS,UAAU,GAAG,aAAa,UAAU,QAAQ,gBAAgB,IAAI",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/ensure/ensureOne.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"// Ensures only one instance ever exists, but replaces it every time it's called\n\nconst Controllers = new WeakMap<symbol, AbortController>()\n\nexport function ensureOne<T>(key: string, factory: (signal: AbortSignal) => T): T {\n const symbolKey = Symbol.for(key)\n const g = globalThis as Record<symbol, unknown>\n\n if (g[symbolKey]) {\n Controllers.get(symbolKey)?.abort()\n }\n\n const controller = new AbortController()\n g[symbolKey] = factory(controller.signal)\n\n return g[symbolKey] as T\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
package/types/error/errors.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,OAAO,cAAM,mBAAmB,MAAM;CACpC,YAAY;;AAMd,OAAO,cAAM,oBAAoB,MAAM;CACrC,YAAY",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/error/errors.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export class AbortError extends Error {\n constructor(message = '') {\n super(message)\n this.name = 'AbortError'\n }\n}\n\nexport class EnsureError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'EnsureError'\n }\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface ThrottleOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Fire immediately on the first call.
|
|
4
|
-
*/
|
|
5
|
-
start?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Fire as soon as `wait` has passed.
|
|
8
|
-
*/
|
|
9
|
-
middle?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Cancel after the first successful call.
|
|
12
|
-
*/
|
|
13
|
-
once?: boolean;
|
|
14
|
-
}
|
|
15
|
-
interface Throttler<T extends unknown[]> {
|
|
16
|
-
(...args: T): void;
|
|
17
|
-
cancel(): void;
|
|
18
|
-
}
|
|
19
|
-
export declare function throttle<T extends unknown[]>(callback: (...args: T) => unknown, wait?: number, { start, middle, once }?: ThrottleOptions): Throttler<T>;
|
|
20
|
-
export declare function debounce<T extends unknown[]>(callback: (...args: T) => unknown, wait?: number, { start, middle, once }?: ThrottleOptions): Throttler<T>;
|
|
21
|
-
export {};
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=throttle.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAIA,iBAAiB,gBAAgB;;;;CAI/B;;;;CAIA;;;;CAIA;;UAGQ,UAAU,qBAAqB;EACtC,GAAG,MAAM;CACV;;AAGF,OAAO,iBAAS,SAAS,qBACvB,WAAW,GAAG,MAAM,eACpB,eACA,EAAE,OAAc,QAAe,SAAgB,kBAC9C,UAAU;AAqCb,OAAO,iBAAS,SAAS,qBACvB,WAAW,GAAG,MAAM,eACpB,eACA,EAAE,OAAe,QAAgB,SAAgB,kBAChD,UAAU",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/function/throttle.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"// via @github/mini-throttle https://raw.githubusercontent.com/github/mini-throttle/refs/heads/main/index.ts\n\nimport type { Timer } from '../types/timer'\n\nexport interface ThrottleOptions {\n /**\n * Fire immediately on the first call.\n */\n start?: boolean\n /**\n * Fire as soon as `wait` has passed.\n */\n middle?: boolean\n /**\n * Cancel after the first successful call.\n */\n once?: boolean\n}\n\ninterface Throttler<T extends unknown[]> {\n (...args: T): void\n cancel(): void\n}\n\nexport function throttle<T extends unknown[]>(\n callback: (...args: T) => unknown,\n wait = 0,\n { start = true, middle = true, once = false }: ThrottleOptions = {}\n): Throttler<T> {\n let innerStart = start\n let last = 0\n let timer: Timer\n let cancelled = false\n function fn(this: unknown, ...args: T) {\n if (cancelled) return\n const delta = Date.now() - last\n last = Date.now()\n\n if (start && middle && delta >= wait) {\n innerStart = true\n }\n\n if (innerStart) {\n innerStart = false\n callback.apply(this, args)\n if (once) fn.cancel()\n } else if ((middle && delta < wait) || !middle) {\n clearTimeout(timer)\n timer = setTimeout(\n () => {\n last = Date.now()\n callback.apply(this, args)\n if (once) fn.cancel()\n },\n !middle ? wait : wait - delta\n )\n }\n }\n fn.cancel = () => {\n clearTimeout(timer)\n cancelled = true\n }\n return fn\n}\n\nexport function debounce<T extends unknown[]>(\n callback: (...args: T) => unknown,\n wait = 0,\n { start = false, middle = false, once = false }: ThrottleOptions = {}\n): Throttler<T> {\n return throttle(callback, wait, { start, middle, once })\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,OAAO,iBAAS,aAAa,aAAa",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/global/globalEffect.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export function globalEffect(key: string, factory: () => void | (() => void)): void {\n const disposeKey = Symbol.for(key)\n const g = globalThis as Record<symbol, () => void>\n\n if (g[disposeKey]) {\n g[disposeKey]?.()\n }\n\n const dispose = factory()\n\n if (dispose) {\n g[disposeKey] = dispose\n }\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper to store a value that's not duplicated within the global context Uses
|
|
3
|
-
* a symbol stored on `globalThis` to achieve it.
|
|
4
|
-
*
|
|
5
|
-
* There's two main uses for this (for us, so far):
|
|
6
|
-
*
|
|
7
|
-
* - in dev mode, HMR re-runs files, but you may want to preserve globals
|
|
8
|
-
*
|
|
9
|
-
* - in published node modules, sometimes Vite or other bundlers can cause
|
|
10
|
-
* duplicate dependencies either through bad setup or heuristics, they may
|
|
11
|
-
* compile a module but then another code path doesn't compile it, so you
|
|
12
|
-
* have duplicate modules. in this case it can be good to just use a
|
|
13
|
-
* globalValue and warn the end-user. because you can't account for ever
|
|
14
|
-
* possible weird configuration, and often fixing that config can be a
|
|
15
|
-
* massive pain in the ass, it's better to retain functionality while
|
|
16
|
-
* warning them so they can fix it at their own pace. this often happens
|
|
17
|
-
* with WeakMaps.
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
export declare function globalValue<T>(key: string, factory: () => T, opts?: {
|
|
21
|
-
warnMessage?: string;
|
|
22
|
-
}): T;
|
|
23
|
-
|
|
24
|
-
//# sourceMappingURL=globalValue.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAoBA,OAAO,iBAAS,YAAY,GAC1B,aACA,eAAe,GACf,OAAO;CACL;IAED",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/global/globalValue.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"/**\n * Helper to store a value that's not duplicated within the global context Uses\n * a symbol stored on `globalThis` to achieve it.\n *\n * There's two main uses for this (for us, so far):\n *\n * - in dev mode, HMR re-runs files, but you may want to preserve globals\n *\n * - in published node modules, sometimes Vite or other bundlers can cause\n * duplicate dependencies either through bad setup or heuristics, they may\n * compile a module but then another code path doesn't compile it, so you\n * have duplicate modules. in this case it can be good to just use a\n * globalValue and warn the end-user. because you can't account for ever\n * possible weird configuration, and often fixing that config can be a\n * massive pain in the ass, it's better to retain functionality while\n * warning them so they can fix it at their own pace. this often happens\n * with WeakMaps.\n *\n */\n\nexport function globalValue<T>(\n key: string,\n factory: () => T,\n opts?: {\n warnMessage?: string\n }\n): T {\n const symbolKey = Symbol.for(key)\n const g = globalThis as Record<symbol, unknown>\n\n if (!g[symbolKey]) {\n g[symbolKey] = factory()\n } else {\n if (opts?.warnMessage) {\n console.warn(`[globalValue] ${opts.warnMessage}`)\n }\n }\n\n return g[symbolKey] as T\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
|
-
export * from "./emitter";
|
|
3
|
-
export * from "./array/getRandomItem";
|
|
4
|
-
export * from "./array/takeLast";
|
|
5
|
-
export * from "./array/uniqBy";
|
|
6
|
-
export * from "./assert";
|
|
7
|
-
export * from "./async/abortable";
|
|
8
|
-
export * from "./async/asyncContext";
|
|
9
|
-
export * from "./async/idle";
|
|
10
|
-
export * from "./async/interval";
|
|
11
|
-
export * from "./async/isAborted";
|
|
12
|
-
export * from "./async/sleep";
|
|
13
|
-
export * from "./async/useAsync";
|
|
14
|
-
export * from "./async/useAsyncEffect";
|
|
15
|
-
export * from "./async/useLazyMount";
|
|
16
|
-
export * from "./async/useLazyValue";
|
|
17
|
-
export * from "./browser/clearIndexedDB";
|
|
18
|
-
export * from "./clipboard/clipboard";
|
|
19
|
-
export * from "./color/toHex";
|
|
20
|
-
export * from "./color/generateColors";
|
|
21
|
-
export * from "./color/lum";
|
|
22
|
-
export * from "./color/extractOpacityFromColor";
|
|
23
|
-
export * from "./browser/isActiveElementFormField";
|
|
24
|
-
export * from "./browser/openPopup";
|
|
25
|
-
export * from "./debug/debugLog";
|
|
26
|
-
export * from "./debug/debugUseState";
|
|
27
|
-
export * from "./ensure/ensure";
|
|
28
|
-
export * from "./ensure/ensureOne";
|
|
29
|
-
export * from "./error/errors";
|
|
30
|
-
export * from "./function/emptyFn";
|
|
31
|
-
export * from "./function/identityFn";
|
|
32
|
-
export * from "./function/throttle";
|
|
33
|
-
export * from "./global/globalEffect";
|
|
34
|
-
export * from "./global/globalValue";
|
|
35
|
-
export * from "./number/formatNumber";
|
|
36
|
-
export * from "./object/decorateObject";
|
|
37
|
-
export * from "./object/isEqualDeep";
|
|
38
|
-
export { isEqualDeepLite } from "./object/isEqualDeep";
|
|
39
|
-
export * from "./object/isEqualIdentity";
|
|
40
|
-
export * from "./object/isEqualJSON";
|
|
41
|
-
export * from "./object/isEqualNever";
|
|
42
|
-
export * from "./object/mapObject";
|
|
43
|
-
export * from "./object/object";
|
|
44
|
-
export * from "./object/objectUniqueKey";
|
|
45
|
-
export * from "./react/createGlobalContext";
|
|
46
|
-
export * from "./react/getCurrentComponentStack";
|
|
47
|
-
export * from "./storage/createStorage";
|
|
48
|
-
export * from "./storage/driver";
|
|
49
|
-
export type { StorageDriver } from "./storage/types";
|
|
50
|
-
export * from "./server/ensureEnv";
|
|
51
|
-
export * from "./server/getHeaders";
|
|
52
|
-
export * from "./server/prettyPrintRequest";
|
|
53
|
-
export * from "./server/prettyPrintResponse";
|
|
54
|
-
export * from "./server/streamToString";
|
|
55
|
-
export * from "./string/dedent";
|
|
56
|
-
export * from "./string/ellipsis";
|
|
57
|
-
export * from "./string/hash";
|
|
58
|
-
export * from "./string/insertAtIndex";
|
|
59
|
-
export * from "./string/nbspLastWord";
|
|
60
|
-
export * from "./string/pickLast";
|
|
61
|
-
export * from "./string/pluralize";
|
|
62
|
-
export * from "./string/randomId";
|
|
63
|
-
export * from "./string/slugify";
|
|
64
|
-
export * from "./string/truncateList";
|
|
65
|
-
export * from "./time/formatDate";
|
|
66
|
-
export * from "./time/formatDateRelative";
|
|
67
|
-
export * from "./time/formatDistanceToNow";
|
|
68
|
-
export * from "./time/time";
|
|
69
|
-
export * from "./time/useTimer";
|
|
70
|
-
export type * from "./types/NullToOptional";
|
|
71
|
-
export type * from "./types/object";
|
|
72
|
-
export type * from "./types/react";
|
|
73
|
-
export type * from "./types/timer";
|
|
74
|
-
export type * from "./types/tuple";
|
|
75
|
-
export * from "./url/urlSanitize";
|
|
76
|
-
export * from "./url/urlValidate";
|
|
77
|
-
|
|
78
|
-
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,SAAS,uBAAuB;AAChC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc,qBAAqB;AAGnC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AAGnB,cAAc;AACd,cAAc",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/index.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export * from './constants'\nexport * from './emitter'\n\n// array\nexport * from './array/getRandomItem'\nexport * from './array/takeLast'\nexport * from './array/uniqBy'\n\n// assert\nexport * from './assert'\n\n// async\nexport * from './async/abortable'\nexport * from './async/asyncContext'\nexport * from './async/idle'\nexport * from './async/interval'\nexport * from './async/isAborted'\nexport * from './async/sleep'\nexport * from './async/useAsync'\nexport * from './async/useAsyncEffect'\nexport * from './async/useLazyMount'\nexport * from './async/useLazyValue'\n\n// browser\nexport * from './browser/clearIndexedDB'\n\n// clipboard\nexport * from './clipboard/clipboard'\n\n// color\nexport * from './color/toHex'\nexport * from './color/generateColors'\nexport * from './color/lum'\nexport * from './color/extractOpacityFromColor'\nexport * from './browser/isActiveElementFormField'\nexport * from './browser/openPopup'\n\n// debug\nexport * from './debug/debugLog'\nexport * from './debug/debugUseState'\n\n// ensure\nexport * from './ensure/ensure'\nexport * from './ensure/ensureOne'\n\n// error\nexport * from './error/errors'\n\n// files\n\n// function\nexport * from './function/emptyFn'\nexport * from './function/identityFn'\nexport * from './function/throttle'\n\n// global\nexport * from './global/globalEffect'\nexport * from './global/globalValue'\n\n// number\nexport * from './number/formatNumber'\n\n// object\nexport * from './object/decorateObject'\nexport * from './object/isEqualDeep'\nexport { isEqualDeepLite } from './object/isEqualDeep'\nexport * from './object/isEqualIdentity'\nexport * from './object/isEqualJSON'\nexport * from './object/isEqualNever'\nexport * from './object/mapObject'\nexport * from './object/object'\nexport * from './object/objectUniqueKey'\n\n// react\nexport * from './react/createGlobalContext'\nexport * from './react/getCurrentComponentStack'\n\n// storage\nexport * from './storage/createStorage'\nexport * from './storage/driver'\nexport type { StorageDriver } from './storage/types'\n\n// server\nexport * from './server/ensureEnv'\nexport * from './server/getHeaders'\nexport * from './server/prettyPrintRequest'\nexport * from './server/prettyPrintResponse'\nexport * from './server/streamToString'\n\n// string\nexport * from './string/dedent'\nexport * from './string/ellipsis'\nexport * from './string/hash'\nexport * from './string/insertAtIndex'\nexport * from './string/nbspLastWord'\nexport * from './string/pickLast'\nexport * from './string/pluralize'\nexport * from './string/randomId'\nexport * from './string/slugify'\nexport * from './string/truncateList'\n\n// time\nexport * from './time/formatDate'\nexport * from './time/formatDateRelative'\nexport * from './time/formatDistanceToNow'\nexport * from './time/time'\nexport * from './time/useTimer'\n\n// types\nexport type * from './types/NullToOptional'\nexport type * from './types/object'\nexport type * from './types/react'\nexport type * from './types/timer'\nexport type * from './types/tuple'\n\n// url\nexport * from './url/urlSanitize'\nexport * from './url/urlValidate'\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface FormatNumberOptions {
|
|
2
|
-
locale?: string;
|
|
3
|
-
maximumFractionDigits?: number;
|
|
4
|
-
minimumFractionDigits?: number;
|
|
5
|
-
forceCompact?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare function formatNumber(value: number, options?: FormatNumberOptions): string;
|
|
8
|
-
export declare function abbreviateNumber(value: number): string;
|
|
9
|
-
export declare function formatCount(value: number): string;
|
|
10
|
-
export declare function formatReactionCount(value: number | string): string;
|
|
11
|
-
export declare function formatPhoneNumber(value: string): string;
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=formatNumber.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,iBAAiB,oBAAoB;CACnC;CACA;CACA;CACA;;AAGF,OAAO,iBAAS,aAAa,eAAe,UAAS;AAuBrD,OAAO,iBAAS,iBAAiB;AAIjC,OAAO,iBAAS,YAAY;AAO5B,OAAO,iBAAS,oBAAoB;AAWpC,OAAO,iBAAS,kBAAkB",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/number/formatNumber.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export interface FormatNumberOptions {\n locale?: string\n maximumFractionDigits?: number\n minimumFractionDigits?: number\n forceCompact?: boolean\n}\n\nexport function formatNumber(value: number, options: FormatNumberOptions = {}): string {\n const {\n locale = 'en-US',\n maximumFractionDigits = 1,\n minimumFractionDigits = 0,\n forceCompact = false,\n } = options\n\n if (!forceCompact && Math.abs(value) < 1000) {\n return new Intl.NumberFormat(locale, {\n maximumFractionDigits,\n minimumFractionDigits,\n }).format(value)\n }\n\n return new Intl.NumberFormat(locale, {\n notation: 'compact',\n compactDisplay: 'short',\n maximumFractionDigits,\n minimumFractionDigits,\n }).format(value)\n}\n\nexport function abbreviateNumber(value: number): string {\n return formatNumber(value, { maximumFractionDigits: 1 })\n}\n\nexport function formatCount(value: number): string {\n return formatNumber(value, {\n maximumFractionDigits: 0,\n forceCompact: value >= 1000,\n })\n}\n\nexport function formatReactionCount(value: number | string): string {\n if (typeof value === 'string') return value\n if (value >= 1000000) {\n return `${(value / 1000000).toFixed(1)}M`\n }\n if (value >= 1000) {\n return `${(value / 1000).toFixed(1)}K`\n }\n return value.toString()\n}\n\nexport function formatPhoneNumber(value: string): string {\n return value\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,OAAO,iBAAS,eAAe,UAAU,qBACvC,KAAK,GACL,YAAY,IAAI,aAAa,WAC5B",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/object/decorateObject.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export function decorateObject<T extends Record<string, any>>(\n obj: T,\n decorator: (fn: Function) => Function\n): T {\n const decorated = {} as T\n\n for (const [key, value] of Object.entries(obj)) {\n if (typeof value === 'function') {\n ;(decorated as any)[key] = decorator(value)\n } else {\n ;(decorated as any)[key] = value\n }\n }\n\n return decorated\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "KAGK,cAAc,UAAU;AAE7B,OAAO,cAAMA,aAAa;AAC1B,OAAO,cAAMC,iBAAiB",
|
|
3
|
-
"names": [
|
|
4
|
-
"isEqualDeep: EqualityFn",
|
|
5
|
-
"isEqualDeepLite: EqualityFn"
|
|
6
|
-
],
|
|
7
|
-
"sources": [
|
|
8
|
-
"src/object/isEqualDeep.ts"
|
|
9
|
-
],
|
|
10
|
-
"sourcesContent": [
|
|
11
|
-
"import { dequal } from 'dequal'\nimport { dequal as dequalLite } from 'dequal/lite'\n\ntype EqualityFn = (foo: any, bar: any) => boolean\n\nexport const isEqualDeep: EqualityFn = dequal\nexport const isEqualDeepLite: EqualityFn = dequalLite\n"
|
|
12
|
-
],
|
|
13
|
-
"version": 3
|
|
14
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,OAAO,cAAM,cAAe,QAAQ",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/object/isEqualJSON.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export const isEqualJSON = (a: any, b: any): boolean =>\n JSON.stringify(a) === JSON.stringify(b)\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,OAAO,iBAAS;CAAU,UAAU;CAAqB;EACvD,KAAK,GACL,KAAK,gBAAgB,GAAG,OAAO,EAAE,IAAI,KAAK,MAAM,OAC5C,WAAW,KAAI",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/object/mapObject.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"export function mapObject<T extends Record<string, any>, R>(\n obj: T,\n fn: <K extends keyof T>(value: T[K], key: K) => R\n): { [K in keyof T]: R } {\n const result = {} as { [K in keyof T]: R }\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n result[key] = fn(obj[key], key)\n }\n }\n\n return result\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
package/types/object/object.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { EntriesToObject, EntriesType, ObjectEntries, ObjectType } from "../types/object";
|
|
2
|
-
export declare function postfixObjKeys<
|
|
3
|
-
A extends {
|
|
4
|
-
[key: string]: string;
|
|
5
|
-
},
|
|
6
|
-
B extends string
|
|
7
|
-
>(obj: A, postfix: B): { [Key in `${keyof A extends string ? keyof A : never}${B}`] : string };
|
|
8
|
-
export declare function objectFromEntries<ARR_T extends EntriesType>(arr: ARR_T): EntriesToObject<ARR_T>;
|
|
9
|
-
export declare function objectKeys<O extends object>(obj: O): Array<keyof O>;
|
|
10
|
-
export declare function objectEntries<OBJ_T extends ObjectType>(obj: OBJ_T): ObjectEntries<OBJ_T>;
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,cACE,iBACA,aACA,eACA,kBACK;AAEP,OAAO,iBAAS;CAAe,UAAU;;;CAA2B;EAClE,KAAK,GACL,SAAS,OAER,gBAAgB,yBAAyB,YAAY;AAOxD,OAAO,iBAAS,kBAAkB,cAAc,aAC9C,KAAK,QACJ,gBAAgB;AAInB,OAAO,iBAAS,WAAW,kBAAkB,KAAK,IACrB,YAAY;AAGzC,OAAO,iBAAS,cAAc,cAAc,YAC1C,KAAK,QACJ,cAAc",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/object/object.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"import type {\n EntriesToObject,\n EntriesType,\n ObjectEntries,\n ObjectType,\n} from '../types/object'\n\nexport function postfixObjKeys<A extends { [key: string]: string }, B extends string>(\n obj: A,\n postfix: B\n): {\n [Key in `${keyof A extends string ? keyof A : never}${B}`]: string\n} {\n return Object.fromEntries(\n Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v])\n ) as any\n}\n\nexport function objectFromEntries<ARR_T extends EntriesType>(\n arr: ARR_T\n): EntriesToObject<ARR_T> {\n return Object.fromEntries(arr) as EntriesToObject<ARR_T>\n}\n\nexport function objectKeys<O extends object>(obj: O) {\n return Object.keys(obj) as Array<keyof O>\n}\n\nexport function objectEntries<OBJ_T extends ObjectType>(\n obj: OBJ_T\n): ObjectEntries<OBJ_T> {\n return Object.entries(obj) as ObjectEntries<OBJ_T>\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAEA,OAAO,cAAM,kBAAmB",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/object/objectUniqueKey.ts"
|
|
6
|
-
],
|
|
7
|
-
"sourcesContent": [
|
|
8
|
-
"const w = new WeakMap<any, string>()\n\nexport const objectUniqueKey = (item: any): string => {\n return (\n w.get(item) ??\n (() => {\n const k = `${Math.random()}`\n w.set(item, k)\n return k\n })()\n )\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"version": 3
|
|
11
|
-
}
|