yummies 5.4.6 → 5.4.7
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/async.d.ts +28 -0
- package/async.d.ts.map +1 -0
- package/async.js +62 -0
- package/{src/common.ts → common.d.ts} +3 -14
- package/common.d.ts.map +1 -0
- package/common.js +14 -0
- package/complex/counter.d.ts +15 -0
- package/complex/counter.d.ts.map +1 -0
- package/complex/counter.js +17 -0
- package/complex/global-config.d.ts +11 -0
- package/complex/global-config.d.ts.map +1 -0
- package/complex/global-config.js +41 -0
- package/complex/index.d.ts +4 -0
- package/complex/index.d.ts.map +1 -0
- package/complex/modules-factory.d.ts +49 -0
- package/complex/modules-factory.d.ts.map +1 -0
- package/complex/modules-factory.js +46 -0
- package/cookie.d.ts +3 -0
- package/cookie.d.ts.map +1 -0
- package/cookie.js +9 -0
- package/css.d.ts +36 -0
- package/css.d.ts.map +1 -0
- package/css.js +20 -0
- package/data.d.ts +4 -0
- package/data.d.ts.map +1 -0
- package/data.js +52 -0
- package/date-time.d.ts +28 -0
- package/date-time.d.ts.map +1 -0
- package/date-time.js +160 -0
- package/device.d.ts +8 -0
- package/device.d.ts.map +1 -0
- package/device.js +21 -0
- package/encodings.d.ts +2 -0
- package/encodings.d.ts.map +1 -0
- package/encodings.js +267 -0
- package/errors.d.ts +19 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +30 -0
- package/file.d.ts +3 -0
- package/file.d.ts.map +1 -0
- package/file.js +24 -0
- package/format/_exports.d.ts +5 -0
- package/format/_exports.d.ts.map +1 -0
- package/format/constants.d.ts +4 -0
- package/format/constants.d.ts.map +1 -0
- package/{src/format/constants.ts → format/constants.js} +0 -2
- package/format/index.d.ts +3 -0
- package/format/index.d.ts.map +1 -0
- package/{src/format/index.ts → format/index.js} +0 -1
- package/format/number.d.ts +36 -0
- package/format/number.d.ts.map +1 -0
- package/format/number.js +44 -0
- package/format/percent.d.ts +15 -0
- package/format/percent.d.ts.map +1 -0
- package/format/percent.js +23 -0
- package/format/skip-spaces.d.ts +5 -0
- package/format/skip-spaces.d.ts.map +1 -0
- package/format/skip-spaces.js +4 -0
- package/html.d.ts +44 -0
- package/html.d.ts.map +1 -0
- package/html.js +182 -0
- package/id.d.ts +63 -0
- package/id.d.ts.map +1 -0
- package/{src/id.ts → id.js} +6 -16
- package/imports.d.ts +15 -0
- package/imports.d.ts.map +1 -0
- package/imports.js +40 -0
- package/math.d.ts +13 -0
- package/math.d.ts.map +1 -0
- package/math.js +17 -0
- package/media.d.ts +20 -0
- package/media.d.ts.map +1 -0
- package/media.js +103 -0
- package/mobx/apply-observable.d.ts +4 -0
- package/mobx/apply-observable.d.ts.map +1 -0
- package/mobx/apply-observable.js +12 -0
- package/mobx/create-enhanced-atom.d.ts +11 -0
- package/mobx/create-enhanced-atom.d.ts.map +1 -0
- package/mobx/create-enhanced-atom.js +12 -0
- package/mobx/deep-observable-struct.d.ts +7 -0
- package/mobx/deep-observable-struct.d.ts.map +1 -0
- package/mobx/deep-observable-struct.js +57 -0
- package/mobx/get-mobx-administration.d.ts +6 -0
- package/mobx/get-mobx-administration.d.ts.map +1 -0
- package/mobx/get-mobx-administration.js +2 -0
- package/mobx/index.d.ts +6 -0
- package/mobx/index.d.ts.map +1 -0
- package/mobx/lazy-observe.d.ts +8 -0
- package/mobx/lazy-observe.d.ts.map +1 -0
- package/mobx/lazy-observe.js +43 -0
- package/ms.d.ts +19 -0
- package/ms.d.ts.map +1 -0
- package/ms.js +18 -0
- package/number.d.ts +8 -0
- package/number.d.ts.map +1 -0
- package/number.js +13 -0
- package/package.json +399 -3
- package/parser/_exports.d.ts +4 -0
- package/parser/_exports.d.ts.map +1 -0
- package/parser/index.d.ts +3 -0
- package/parser/index.d.ts.map +1 -0
- package/{src/parser/index.ts → parser/index.js} +0 -1
- package/parser/number.d.ts +21 -0
- package/parser/number.d.ts.map +1 -0
- package/parser/number.js +44 -0
- package/parser/percent.d.ts +4 -0
- package/parser/percent.d.ts.map +1 -0
- package/parser/percent.js +4 -0
- package/parser/string.d.ts +7 -0
- package/parser/string.d.ts.map +1 -0
- package/parser/string.js +14 -0
- package/price.d.ts +6 -0
- package/price.d.ts.map +1 -0
- package/price.js +17 -0
- package/random.d.ts +9 -0
- package/random.d.ts.map +1 -0
- package/random.js +14 -0
- package/react/hooks/index.d.ts +22 -0
- package/react/hooks/index.d.ts.map +1 -0
- package/react/hooks/use-abort-controller.d.ts +2 -0
- package/react/hooks/use-abort-controller.d.ts.map +1 -0
- package/react/hooks/use-abort-controller.js +11 -0
- package/react/hooks/use-abort-signal.d.ts +2 -0
- package/react/hooks/use-abort-signal.d.ts.map +1 -0
- package/{src/react/hooks/use-abort-signal.ts → react/hooks/use-abort-signal.js} +1 -2
- package/react/hooks/use-click-outside.d.ts +9 -0
- package/react/hooks/use-click-outside.d.ts.map +1 -0
- package/react/hooks/use-click-outside.js +13 -0
- package/react/hooks/use-constant.d.ts +9 -0
- package/react/hooks/use-constant.d.ts.map +1 -0
- package/{src/react/hooks/use-constant.ts → react/hooks/use-constant.js} +6 -9
- package/react/hooks/use-define-ref.d.ts +10 -0
- package/react/hooks/use-define-ref.d.ts.map +1 -0
- package/{src/react/hooks/use-define-ref.ts → react/hooks/use-define-ref.js} +7 -10
- package/react/hooks/use-element-ref.d.ts +2 -0
- package/react/hooks/use-element-ref.d.ts.map +1 -0
- package/react/hooks/use-element-ref.js +8 -0
- package/react/hooks/use-event-listener.d.ts +8 -0
- package/react/hooks/use-event-listener.d.ts.map +1 -0
- package/react/hooks/use-event-listener.js +13 -0
- package/react/hooks/use-event.d.ts +3 -0
- package/react/hooks/use-event.d.ts.map +1 -0
- package/react/hooks/use-event.js +19 -0
- package/react/hooks/use-flag.d.ts +8 -0
- package/react/hooks/use-flag.d.ts.map +1 -0
- package/react/hooks/use-flag.js +15 -0
- package/react/hooks/use-force-update.d.ts +2 -0
- package/react/hooks/use-force-update.d.ts.map +1 -0
- package/react/hooks/use-force-update.js +7 -0
- package/react/hooks/use-initial-height.d.ts +5 -0
- package/react/hooks/use-initial-height.d.ts.map +1 -0
- package/react/hooks/use-initial-height.js +11 -0
- package/react/hooks/use-instance.d.ts +27 -0
- package/react/hooks/use-instance.d.ts.map +1 -0
- package/{src/react/hooks/use-instance.ts → react/hooks/use-instance.js} +7 -29
- package/react/hooks/use-intersection-observer.d.ts +2 -0
- package/react/hooks/use-intersection-observer.d.ts.map +1 -0
- package/react/hooks/use-intersection-observer.js +10 -0
- package/react/hooks/use-last-defined-value.d.ts +2 -0
- package/react/hooks/use-last-defined-value.d.ts.map +1 -0
- package/react/hooks/use-last-defined-value.js +8 -0
- package/react/hooks/use-last-value-ref.d.ts +2 -0
- package/react/hooks/use-last-value-ref.d.ts.map +1 -0
- package/react/hooks/use-last-value-ref.js +8 -0
- package/react/hooks/use-life-cycle.d.ts +5 -0
- package/react/hooks/use-life-cycle.d.ts.map +1 -0
- package/react/hooks/use-life-cycle.js +10 -0
- package/react/hooks/use-resize-observer.d.ts +2 -0
- package/react/hooks/use-resize-observer.d.ts.map +1 -0
- package/react/hooks/use-resize-observer.js +11 -0
- package/react/hooks/use-sync-ref.d.ts +2 -0
- package/react/hooks/use-sync-ref.d.ts.map +1 -0
- package/react/hooks/use-sync-ref.js +6 -0
- package/react/hooks/use-toggle.d.ts +2 -0
- package/react/hooks/use-toggle.d.ts.map +1 -0
- package/react/hooks/use-toggle.js +6 -0
- package/react/hooks/use-value.d.ts +5 -0
- package/react/hooks/use-value.d.ts.map +1 -0
- package/react/hooks/use-value.js +8 -0
- package/react/hooks/use-visibility-state.d.ts +2 -0
- package/react/hooks/use-visibility-state.d.ts.map +1 -0
- package/react/hooks/use-visibility-state.js +14 -0
- package/react/index.d.ts +2 -0
- package/react/index.d.ts.map +1 -0
- package/sound.d.ts +7 -0
- package/sound.d.ts.map +1 -0
- package/sound.js +12 -0
- package/storage.d.ts +39 -0
- package/storage.d.ts.map +1 -0
- package/storage.js +43 -0
- package/text.d.ts +15 -0
- package/text.d.ts.map +1 -0
- package/text.js +48 -0
- package/type-guard/_exports.d.ts +86 -0
- package/type-guard/_exports.d.ts.map +1 -0
- package/type-guard/_exports.js +125 -0
- package/type-guard/index.d.ts +3 -0
- package/type-guard/index.d.ts.map +1 -0
- package/{src/type-guard/index.ts → type-guard/index.js} +0 -1
- package/utility-types.d.ts +395 -0
- package/utils/types.d.ts +395 -0
- package/utils/types.d.ts.map +1 -0
- package/utils/types.js +1 -0
- package/vibrate.d.ts +5 -0
- package/vibrate.d.ts.map +1 -0
- package/vibrate.js +8 -0
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.github/FUNDING.yml +0 -1
- package/.github/workflows/main.yml +0 -34
- package/.github/workflows/version-or-publish.yml +0 -45
- package/.nvmrc +0 -1
- package/.vscode/settings.json +0 -19
- package/CHANGELOG.md +0 -215
- package/CONTRIBUTING.md +0 -8
- package/Makefile +0 -7
- package/biome.json +0 -3
- package/commitfmt.toml +0 -18
- package/lefthook.yml +0 -14
- package/scripts/post-build.ts +0 -71
- package/src/async.ts +0 -86
- package/src/complex/counter.test.ts +0 -41
- package/src/complex/counter.ts +0 -40
- package/src/complex/global-config.ts +0 -55
- package/src/complex/modules-factory.ts +0 -65
- package/src/cookie.ts +0 -11
- package/src/css.ts +0 -60
- package/src/data.test.ts +0 -99
- package/src/data.ts +0 -65
- package/src/date-time.test.ts +0 -119
- package/src/date-time.ts +0 -236
- package/src/device.ts +0 -42
- package/src/encodings.ts +0 -270
- package/src/errors.ts +0 -40
- package/src/file.ts +0 -25
- package/src/format/number.test.ts +0 -16
- package/src/format/number.ts +0 -96
- package/src/format/percent.ts +0 -40
- package/src/format/skip-spaces.ts +0 -4
- package/src/html.ts +0 -238
- package/src/imports.ts +0 -52
- package/src/math.ts +0 -20
- package/src/media.ts +0 -134
- package/src/mobx/apply-observable.ts +0 -20
- package/src/mobx/create-enhanced-atom.ts +0 -28
- package/src/mobx/deep-observable-struct.test.ts +0 -69
- package/src/mobx/deep-observable-struct.ts +0 -69
- package/src/mobx/get-mobx-administration.ts +0 -10
- package/src/mobx/lazy-observe.ts +0 -59
- package/src/ms.ts +0 -20
- package/src/number.ts +0 -14
- package/src/parser/number.test.ts +0 -38
- package/src/parser/number.ts +0 -73
- package/src/parser/percent.ts +0 -11
- package/src/parser/string.ts +0 -29
- package/src/price.ts +0 -33
- package/src/random.ts +0 -27
- package/src/react/hooks/use-abort-controller.ts +0 -15
- package/src/react/hooks/use-click-outside.ts +0 -27
- package/src/react/hooks/use-element-ref.ts +0 -11
- package/src/react/hooks/use-event-listener.ts +0 -29
- package/src/react/hooks/use-event.ts +0 -23
- package/src/react/hooks/use-flag.ts +0 -27
- package/src/react/hooks/use-force-update.ts +0 -9
- package/src/react/hooks/use-initial-height.ts +0 -16
- package/src/react/hooks/use-intersection-observer.ts +0 -18
- package/src/react/hooks/use-last-defined-value.ts +0 -9
- package/src/react/hooks/use-last-value-ref.ts +0 -11
- package/src/react/hooks/use-life-cycle.ts +0 -17
- package/src/react/hooks/use-resize-observer.ts +0 -14
- package/src/react/hooks/use-sync-ref.ts +0 -7
- package/src/react/hooks/use-toggle.ts +0 -9
- package/src/react/hooks/use-value.ts +0 -10
- package/src/react/hooks/use-visibility-state.ts +0 -19
- package/src/sound.ts +0 -15
- package/src/storage.ts +0 -137
- package/src/text.test.ts +0 -91
- package/src/text.ts +0 -60
- package/src/type-guard/_exports.ts +0 -154
- package/src/type-guard/index.test.ts +0 -127
- package/src/vibrate.ts +0 -8
- package/tsconfig.json +0 -26
- package/tsconfig.test.json +0 -33
- package/vitest.config.ts +0 -20
- /package/{src/complex/index.ts → complex/index.js} +0 -0
- /package/{src/format/_exports.ts → format/_exports.js} +0 -0
- /package/{src/mobx/index.ts → mobx/index.js} +0 -0
- /package/{src/parser/_exports.ts → parser/_exports.js} +0 -0
- /package/{src/react/hooks/index.ts → react/hooks/index.js} +0 -0
- /package/{src/react/index.ts → react/index.js} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { makeObservable } from 'mobx';
|
|
2
|
+
export const applyObservable = (context, annotationsArray, useDecorators) => {
|
|
3
|
+
if (useDecorators) {
|
|
4
|
+
annotationsArray.forEach(([field, annotation]) => {
|
|
5
|
+
annotation(context, field);
|
|
6
|
+
});
|
|
7
|
+
makeObservable(context);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
makeObservable(context, Object.fromEntries(annotationsArray));
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IAtom } from 'mobx';
|
|
2
|
+
import type { AnyObject } from '../utils/types.js';
|
|
3
|
+
export interface IEnhancedAtom<TMeta extends AnyObject = AnyObject> extends IAtom {
|
|
4
|
+
meta: TMeta;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates an enhanced atom with meta data
|
|
8
|
+
* And bind `reportChanged` and `reportObserved` method to the atom
|
|
9
|
+
*/
|
|
10
|
+
export declare const createEnhancedAtom: <TMeta extends AnyObject>(name: string, onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void, onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void, meta?: TMeta) => IEnhancedAtom<TMeta>;
|
|
11
|
+
//# sourceMappingURL=create-enhanced-atom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-enhanced-atom.d.ts","sourceRoot":"","sources":["../../src/mobx/create-enhanced-atom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAa,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS,CAChE,SAAQ,KAAK;IACb,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,SAAS,SAAS,EACxD,MAAM,MAAM,EACZ,0BAA0B,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,EAC9D,4BAA4B,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,EAChE,OAAO,KAAK,KACX,aAAa,CAAC,KAAK,CAUrB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createAtom } from 'mobx';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an enhanced atom with meta data
|
|
4
|
+
* And bind `reportChanged` and `reportObserved` method to the atom
|
|
5
|
+
*/
|
|
6
|
+
export const createEnhancedAtom = (name, onBecomeObservedHandler, onBecomeUnobservedHandler, meta) => {
|
|
7
|
+
const atom = createAtom(name, onBecomeObservedHandler && (() => onBecomeObservedHandler?.(atom)), onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler?.(atom)));
|
|
8
|
+
atom.meta = meta ?? {};
|
|
9
|
+
atom.reportChanged = atom.reportChanged.bind(atom);
|
|
10
|
+
atom.reportObserved = atom.reportObserved.bind(atom);
|
|
11
|
+
return atom;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-observable-struct.d.ts","sourceRoot":"","sources":["../../src/mobx/deep-observable-struct.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,oBAAoB,CAAC,KAAK,SAAS,SAAS;IACvD,IAAI,EAAE,KAAK,CAAC;gBAEA,IAAI,EAAE,KAAK;IASvB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;CAoD5B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
+
import { typeGuard } from '../type-guard/index.js';
|
|
3
|
+
export class DeepObservableStruct {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
makeObservable(this, {
|
|
8
|
+
data: observable.deep,
|
|
9
|
+
set: action,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
set(newData) {
|
|
13
|
+
const stack = Object.keys(this.data).map((key) => [
|
|
14
|
+
key,
|
|
15
|
+
this.data,
|
|
16
|
+
newData,
|
|
17
|
+
]);
|
|
18
|
+
let currentIndex = 0;
|
|
19
|
+
let stackLength = stack.length;
|
|
20
|
+
while (currentIndex < stackLength) {
|
|
21
|
+
const [key, currObservableData, newData] = stack[currentIndex];
|
|
22
|
+
const newValue = newData[key];
|
|
23
|
+
const currValue = currObservableData[key];
|
|
24
|
+
currentIndex++;
|
|
25
|
+
if (key in newData) {
|
|
26
|
+
if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {
|
|
27
|
+
const newValueKeys = Object.keys(newValue);
|
|
28
|
+
Object.keys(currValue).forEach((childKey) => {
|
|
29
|
+
if (!(childKey in newValue)) {
|
|
30
|
+
delete currObservableData[key][childKey];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
newValueKeys.forEach((childKey) => {
|
|
34
|
+
const length = stack.push([
|
|
35
|
+
childKey,
|
|
36
|
+
currObservableData[key],
|
|
37
|
+
newValue,
|
|
38
|
+
]);
|
|
39
|
+
stackLength = length;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else if (newValue !== currValue) {
|
|
43
|
+
currObservableData[key] = newValue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
delete currObservableData[key];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
Object.keys(newData).forEach((newDataKey) => {
|
|
51
|
+
if (!this.data[newDataKey]) {
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
this.data[newDataKey] = newData[newDataKey];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AnnotationMapEntry } from 'mobx';
|
|
2
|
+
import type { AnyObject } from '../utils/types.js';
|
|
3
|
+
type ObservableObjectAdministration = Parameters<Exclude<AnnotationMapEntry, boolean>['make_']>[0];
|
|
4
|
+
export declare const getMobxAdministration: (context: AnyObject) => ObservableObjectAdministration;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=get-mobx-administration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-mobx-administration.d.ts","sourceRoot":"","sources":["../../src/mobx/get-mobx-administration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,KAAK,8BAA8B,GAAG,UAAU,CAC9C,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAC9C,CAAC,CAAC,CAAC,CAAC;AAEL,eAAO,MAAM,qBAAqB,GAChC,SAAS,SAAS,KACjB,8BAAgD,CAAC"}
|
package/mobx/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mobx/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const lazyObserve: <TMetaData = void>({ context, property, onStart, onEnd, endDelay, }: {
|
|
2
|
+
context?: any;
|
|
3
|
+
property: any | any[];
|
|
4
|
+
onStart: () => TMetaData;
|
|
5
|
+
onEnd: (metaData: TMetaData, cleanupFn: VoidFunction) => void;
|
|
6
|
+
endDelay?: number;
|
|
7
|
+
}) => () => void;
|
|
8
|
+
//# sourceMappingURL=lazy-observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-observe.d.ts","sourceRoot":"","sources":["../../src/mobx/lazy-observe.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,GAAI,SAAS,GAAG,IAAI,EAAE,kDAM3C;IACD,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,SAAS,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,KAAK,IAAI,CAAC;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,eA4CA,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { onBecomeObserved, onBecomeUnobserved } from 'mobx';
|
|
2
|
+
export const lazyObserve = ({ context, property, onStart, onEnd, endDelay = 0, }) => {
|
|
3
|
+
let timeoutId;
|
|
4
|
+
let metaData;
|
|
5
|
+
const properties = Array.isArray(property) ? property : [property];
|
|
6
|
+
let isObserving = false;
|
|
7
|
+
const start = () => {
|
|
8
|
+
if (isObserving) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
isObserving = true;
|
|
12
|
+
if (timeoutId) {
|
|
13
|
+
clearTimeout(timeoutId);
|
|
14
|
+
timeoutId = undefined;
|
|
15
|
+
}
|
|
16
|
+
metaData = onStart();
|
|
17
|
+
};
|
|
18
|
+
const cleanup = () => {
|
|
19
|
+
if (!isObserving) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (timeoutId) {
|
|
23
|
+
clearTimeout(timeoutId);
|
|
24
|
+
timeoutId = undefined;
|
|
25
|
+
}
|
|
26
|
+
timeoutId = setTimeout(() => {
|
|
27
|
+
onEnd(metaData, cleanup);
|
|
28
|
+
timeoutId = undefined;
|
|
29
|
+
metaData = undefined;
|
|
30
|
+
}, endDelay);
|
|
31
|
+
};
|
|
32
|
+
properties.forEach((property) => {
|
|
33
|
+
if (context) {
|
|
34
|
+
onBecomeObserved(context, property, start);
|
|
35
|
+
onBecomeUnobserved(context, property, cleanup);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
onBecomeObserved(property, start);
|
|
39
|
+
onBecomeUnobserved(property, cleanup);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return cleanup;
|
|
43
|
+
};
|
package/ms.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const unitsToMs: {
|
|
2
|
+
readonly ms: 1;
|
|
3
|
+
readonly sec: 1000;
|
|
4
|
+
readonly min: number;
|
|
5
|
+
readonly hour: number;
|
|
6
|
+
readonly day: number;
|
|
7
|
+
readonly week: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Переводит значение в юнитах в миллисекунды
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* ms(1, 'min') // 60_000
|
|
15
|
+
* ms(30, 'sec') // 30_000
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const ms: (value: number, unit?: keyof typeof unitsToMs) => number;
|
|
19
|
+
//# sourceMappingURL=ms.d.ts.map
|
package/ms.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ms.d.ts","sourceRoot":"","sources":["../src/ms.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;;CAOZ,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,EAAE,GAAI,OAAO,MAAM,EAAE,OAAM,MAAM,OAAO,SAAgB,WAC5C,CAAC"}
|
package/ms.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const unitsToMs = {
|
|
2
|
+
ms: 1,
|
|
3
|
+
sec: 1000,
|
|
4
|
+
min: 1000 * 60,
|
|
5
|
+
hour: 1000 * 60 * 60,
|
|
6
|
+
day: 1000 * 60 * 60 * 24,
|
|
7
|
+
week: 1000 * 60 * 60 * 24 * 7,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Переводит значение в юнитах в миллисекунды
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* ms(1, 'min') // 60_000
|
|
15
|
+
* ms(30, 'sec') // 30_000
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const ms = (value, unit = 'ms') => value * unitsToMs[unit];
|
package/number.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Works like `parseFloat(number.toFixed(4))` but performance better
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* round(191.212999999999999999999999, 4) // 191.213
|
|
6
|
+
*/
|
|
7
|
+
export declare function round(value: number, decimalPlaces?: number): number;
|
|
8
|
+
//# sourceMappingURL=number.d.ts.map
|
package/number.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,GAAE,MAAU,GAAG,MAAM,CAOtE"}
|
package/number.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Works like `parseFloat(number.toFixed(4))` but performance better
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* round(191.212999999999999999999999, 4) // 191.213
|
|
6
|
+
*/
|
|
7
|
+
export function round(value, decimalPlaces = 0) {
|
|
8
|
+
if (!decimalPlaces) {
|
|
9
|
+
return Math.round(value);
|
|
10
|
+
}
|
|
11
|
+
const factor = 10 ** decimalPlaces;
|
|
12
|
+
return Math.round(value * factor) / factor;
|
|
13
|
+
}
|