yummies 5.4.5 → 5.4.6
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/FUNDING.yml +1 -0
- package/.github/workflows/main.yml +34 -0
- package/.github/workflows/version-or-publish.yml +45 -0
- package/.nvmrc +1 -0
- package/.vscode/settings.json +19 -0
- package/CHANGELOG.md +215 -0
- package/CONTRIBUTING.md +8 -0
- package/Makefile +7 -0
- package/assets/logo.png +0 -0
- package/assets/logo.pxz +0 -0
- package/biome.json +3 -0
- package/commitfmt.toml +18 -0
- package/lefthook.yml +14 -0
- package/package.json +3 -389
- package/scripts/post-build.ts +71 -0
- package/src/async.ts +86 -0
- package/src/common.ts +26 -0
- package/src/complex/counter.test.ts +41 -0
- package/src/complex/counter.ts +40 -0
- package/src/complex/global-config.ts +55 -0
- package/src/complex/index.ts +3 -0
- package/src/complex/modules-factory.ts +65 -0
- package/src/cookie.ts +11 -0
- package/src/css.ts +60 -0
- package/src/data.test.ts +99 -0
- package/src/data.ts +65 -0
- package/src/date-time.test.ts +119 -0
- package/src/date-time.ts +236 -0
- package/src/device.ts +42 -0
- package/src/encodings.ts +270 -0
- package/src/errors.ts +40 -0
- package/src/file.ts +25 -0
- package/src/format/_exports.ts +4 -0
- package/{dist/format/constants.js → src/format/constants.ts} +2 -0
- package/{dist/format/index.js → src/format/index.ts} +2 -1
- package/src/format/number.test.ts +16 -0
- package/src/format/number.ts +96 -0
- package/src/format/percent.ts +40 -0
- package/src/format/skip-spaces.ts +4 -0
- package/src/html.ts +238 -0
- package/{dist/id.js → src/id.ts} +16 -6
- package/src/imports.ts +52 -0
- package/src/math.ts +20 -0
- package/src/media.ts +134 -0
- package/src/mobx/apply-observable.ts +20 -0
- package/src/mobx/create-enhanced-atom.ts +28 -0
- package/src/mobx/deep-observable-struct.test.ts +69 -0
- package/src/mobx/deep-observable-struct.ts +69 -0
- package/src/mobx/get-mobx-administration.ts +10 -0
- package/src/mobx/index.ts +5 -0
- package/src/mobx/lazy-observe.ts +59 -0
- package/src/ms.ts +20 -0
- package/src/number.ts +14 -0
- package/src/parser/_exports.ts +3 -0
- package/{dist/parser/index.js → src/parser/index.ts} +2 -1
- package/src/parser/number.test.ts +38 -0
- package/src/parser/number.ts +73 -0
- package/src/parser/percent.ts +11 -0
- package/src/parser/string.ts +29 -0
- package/src/price.ts +33 -0
- package/src/random.ts +27 -0
- package/src/react/hooks/index.ts +21 -0
- package/src/react/hooks/use-abort-controller.ts +15 -0
- package/src/react/hooks/use-abort-signal.ts +5 -0
- package/src/react/hooks/use-click-outside.ts +27 -0
- package/{dist/react/hooks/use-constant.js → src/react/hooks/use-constant.ts} +9 -6
- package/{dist/react/hooks/use-define-ref.js → src/react/hooks/use-define-ref.ts} +10 -7
- package/src/react/hooks/use-element-ref.ts +11 -0
- package/src/react/hooks/use-event-listener.ts +29 -0
- package/src/react/hooks/use-event.ts +23 -0
- package/src/react/hooks/use-flag.ts +27 -0
- package/src/react/hooks/use-force-update.ts +9 -0
- package/src/react/hooks/use-initial-height.ts +16 -0
- package/{dist/react/hooks/use-instance.js → src/react/hooks/use-instance.ts} +31 -9
- package/src/react/hooks/use-intersection-observer.ts +18 -0
- package/src/react/hooks/use-last-defined-value.ts +9 -0
- package/src/react/hooks/use-last-value-ref.ts +11 -0
- package/src/react/hooks/use-life-cycle.ts +17 -0
- package/src/react/hooks/use-resize-observer.ts +14 -0
- package/src/react/hooks/use-sync-ref.ts +7 -0
- package/src/react/hooks/use-toggle.ts +9 -0
- package/src/react/hooks/use-value.ts +10 -0
- package/src/react/hooks/use-visibility-state.ts +19 -0
- package/src/react/index.ts +1 -0
- package/src/sound.ts +15 -0
- package/src/storage.ts +137 -0
- package/src/text.test.ts +91 -0
- package/src/text.ts +60 -0
- package/src/type-guard/_exports.ts +154 -0
- package/src/type-guard/index.test.ts +127 -0
- package/{dist/type-guard/index.js → src/type-guard/index.ts} +2 -1
- package/src/vibrate.ts +8 -0
- package/tsconfig.json +26 -0
- package/tsconfig.test.json +33 -0
- package/vitest.config.ts +20 -0
- package/dist/async.cjs +0 -70
- package/dist/async.d.cts +0 -28
- package/dist/async.d.cts.map +0 -1
- package/dist/async.d.ts +0 -28
- package/dist/async.d.ts.map +0 -1
- package/dist/async.js +0 -62
- package/dist/common.cjs +0 -18
- package/dist/common.d.cts +0 -15
- package/dist/common.d.cts.map +0 -1
- package/dist/common.d.ts +0 -15
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -14
- package/dist/complex/counter.cjs +0 -21
- package/dist/complex/counter.d.cts +0 -15
- package/dist/complex/counter.d.cts.map +0 -1
- package/dist/complex/counter.d.ts +0 -15
- package/dist/complex/counter.d.ts.map +0 -1
- package/dist/complex/counter.js +0 -17
- package/dist/complex/global-config.cjs +0 -46
- package/dist/complex/global-config.d.cts +0 -11
- package/dist/complex/global-config.d.cts.map +0 -1
- package/dist/complex/global-config.d.ts +0 -11
- package/dist/complex/global-config.d.ts.map +0 -1
- package/dist/complex/global-config.js +0 -41
- package/dist/complex/index.cjs +0 -19
- package/dist/complex/index.d.cts +0 -4
- package/dist/complex/index.d.cts.map +0 -1
- package/dist/complex/index.d.ts +0 -4
- package/dist/complex/index.d.ts.map +0 -1
- package/dist/complex/index.js +0 -3
- package/dist/complex/modules-factory.cjs +0 -50
- package/dist/complex/modules-factory.d.cts +0 -49
- package/dist/complex/modules-factory.d.cts.map +0 -1
- package/dist/complex/modules-factory.d.ts +0 -49
- package/dist/complex/modules-factory.d.ts.map +0 -1
- package/dist/complex/modules-factory.js +0 -46
- package/dist/cookie.cjs +0 -13
- package/dist/cookie.d.cts +0 -3
- package/dist/cookie.d.cts.map +0 -1
- package/dist/cookie.d.ts +0 -3
- package/dist/cookie.d.ts.map +0 -1
- package/dist/cookie.js +0 -9
- package/dist/css.cjs +0 -28
- package/dist/css.d.cts +0 -36
- package/dist/css.d.cts.map +0 -1
- package/dist/css.d.ts +0 -36
- package/dist/css.d.ts.map +0 -1
- package/dist/css.js +0 -20
- package/dist/data.cjs +0 -58
- package/dist/data.d.cts +0 -4
- package/dist/data.d.cts.map +0 -1
- package/dist/data.d.ts +0 -4
- package/dist/data.d.ts.map +0 -1
- package/dist/data.js +0 -52
- package/dist/date-time.cjs +0 -171
- package/dist/date-time.d.cts +0 -28
- package/dist/date-time.d.cts.map +0 -1
- package/dist/date-time.d.ts +0 -28
- package/dist/date-time.d.ts.map +0 -1
- package/dist/date-time.js +0 -160
- package/dist/device.cjs +0 -28
- package/dist/device.d.cts +0 -8
- package/dist/device.d.cts.map +0 -1
- package/dist/device.d.ts +0 -8
- package/dist/device.d.ts.map +0 -1
- package/dist/device.js +0 -21
- package/dist/encodings.cjs +0 -270
- package/dist/encodings.d.cts +0 -2
- package/dist/encodings.d.cts.map +0 -1
- package/dist/encodings.d.ts +0 -2
- package/dist/encodings.d.ts.map +0 -1
- package/dist/encodings.js +0 -267
- package/dist/errors.cjs +0 -34
- package/dist/errors.d.cts +0 -19
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.ts +0 -19
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -30
- package/dist/file.cjs +0 -29
- package/dist/file.d.cts +0 -3
- package/dist/file.d.cts.map +0 -1
- package/dist/file.d.ts +0 -3
- package/dist/file.d.ts.map +0 -1
- package/dist/file.js +0 -24
- package/dist/format/_exports.cjs +0 -20
- package/dist/format/_exports.d.cts +0 -5
- package/dist/format/_exports.d.cts.map +0 -1
- package/dist/format/_exports.d.ts +0 -5
- package/dist/format/_exports.d.ts.map +0 -1
- package/dist/format/_exports.js +0 -4
- package/dist/format/constants.cjs +0 -6
- package/dist/format/constants.d.cts +0 -4
- package/dist/format/constants.d.cts.map +0 -1
- package/dist/format/constants.d.ts +0 -4
- package/dist/format/constants.d.ts.map +0 -1
- package/dist/format/index.cjs +0 -40
- package/dist/format/index.d.cts +0 -3
- package/dist/format/index.d.cts.map +0 -1
- package/dist/format/index.d.ts +0 -3
- package/dist/format/index.d.ts.map +0 -1
- package/dist/format/number.cjs +0 -48
- package/dist/format/number.d.cts +0 -36
- package/dist/format/number.d.cts.map +0 -1
- package/dist/format/number.d.ts +0 -36
- package/dist/format/number.d.ts.map +0 -1
- package/dist/format/number.js +0 -44
- package/dist/format/percent.cjs +0 -27
- package/dist/format/percent.d.cts +0 -15
- package/dist/format/percent.d.cts.map +0 -1
- package/dist/format/percent.d.ts +0 -15
- package/dist/format/percent.d.ts.map +0 -1
- package/dist/format/percent.js +0 -23
- package/dist/format/skip-spaces.cjs +0 -8
- package/dist/format/skip-spaces.d.cts +0 -5
- package/dist/format/skip-spaces.d.cts.map +0 -1
- package/dist/format/skip-spaces.d.ts +0 -5
- package/dist/format/skip-spaces.d.ts.map +0 -1
- package/dist/format/skip-spaces.js +0 -4
- package/dist/html.cjs +0 -202
- package/dist/html.d.cts +0 -44
- package/dist/html.d.cts.map +0 -1
- package/dist/html.d.ts +0 -44
- package/dist/html.d.ts.map +0 -1
- package/dist/html.js +0 -182
- package/dist/id.cjs +0 -76
- package/dist/id.d.cts +0 -63
- package/dist/id.d.cts.map +0 -1
- package/dist/id.d.ts +0 -63
- package/dist/id.d.ts.map +0 -1
- package/dist/imports.cjs +0 -45
- package/dist/imports.d.cts +0 -15
- package/dist/imports.d.cts.map +0 -1
- package/dist/imports.d.ts +0 -15
- package/dist/imports.d.ts.map +0 -1
- package/dist/imports.js +0 -40
- package/dist/math.cjs +0 -23
- package/dist/math.d.cts +0 -13
- package/dist/math.d.cts.map +0 -1
- package/dist/math.d.ts +0 -13
- package/dist/math.d.ts.map +0 -1
- package/dist/math.js +0 -17
- package/dist/media.cjs +0 -115
- package/dist/media.d.cts +0 -20
- package/dist/media.d.cts.map +0 -1
- package/dist/media.d.ts +0 -20
- package/dist/media.d.ts.map +0 -1
- package/dist/media.js +0 -103
- package/dist/mobx/apply-observable.cjs +0 -16
- package/dist/mobx/apply-observable.d.cts +0 -4
- package/dist/mobx/apply-observable.d.cts.map +0 -1
- package/dist/mobx/apply-observable.d.ts +0 -4
- package/dist/mobx/apply-observable.d.ts.map +0 -1
- package/dist/mobx/apply-observable.js +0 -12
- package/dist/mobx/create-enhanced-atom.cjs +0 -16
- package/dist/mobx/create-enhanced-atom.d.cts +0 -11
- package/dist/mobx/create-enhanced-atom.d.cts.map +0 -1
- package/dist/mobx/create-enhanced-atom.d.ts +0 -11
- package/dist/mobx/create-enhanced-atom.d.ts.map +0 -1
- package/dist/mobx/create-enhanced-atom.js +0 -12
- package/dist/mobx/deep-observable-struct.cjs +0 -61
- package/dist/mobx/deep-observable-struct.d.cts +0 -7
- package/dist/mobx/deep-observable-struct.d.cts.map +0 -1
- package/dist/mobx/deep-observable-struct.d.ts +0 -7
- package/dist/mobx/deep-observable-struct.d.ts.map +0 -1
- package/dist/mobx/deep-observable-struct.js +0 -57
- package/dist/mobx/get-mobx-administration.cjs +0 -6
- package/dist/mobx/get-mobx-administration.d.cts +0 -6
- package/dist/mobx/get-mobx-administration.d.cts.map +0 -1
- package/dist/mobx/get-mobx-administration.d.ts +0 -6
- package/dist/mobx/get-mobx-administration.d.ts.map +0 -1
- package/dist/mobx/get-mobx-administration.js +0 -2
- package/dist/mobx/index.cjs +0 -21
- package/dist/mobx/index.d.cts +0 -6
- package/dist/mobx/index.d.cts.map +0 -1
- package/dist/mobx/index.d.ts +0 -6
- package/dist/mobx/index.d.ts.map +0 -1
- package/dist/mobx/index.js +0 -5
- package/dist/mobx/lazy-observe.cjs +0 -47
- package/dist/mobx/lazy-observe.d.cts +0 -8
- package/dist/mobx/lazy-observe.d.cts.map +0 -1
- package/dist/mobx/lazy-observe.d.ts +0 -8
- package/dist/mobx/lazy-observe.d.ts.map +0 -1
- package/dist/mobx/lazy-observe.js +0 -43
- package/dist/ms.cjs +0 -22
- package/dist/ms.d.cts +0 -19
- package/dist/ms.d.cts.map +0 -1
- package/dist/ms.d.ts +0 -19
- package/dist/ms.d.ts.map +0 -1
- package/dist/ms.js +0 -18
- package/dist/number.cjs +0 -16
- package/dist/number.d.cts +0 -8
- package/dist/number.d.cts.map +0 -1
- package/dist/number.d.ts +0 -8
- package/dist/number.d.ts.map +0 -1
- package/dist/number.js +0 -13
- package/dist/parser/_exports.cjs +0 -19
- package/dist/parser/_exports.d.cts +0 -4
- package/dist/parser/_exports.d.cts.map +0 -1
- package/dist/parser/_exports.d.ts +0 -4
- package/dist/parser/_exports.d.ts.map +0 -1
- package/dist/parser/_exports.js +0 -3
- package/dist/parser/index.cjs +0 -40
- package/dist/parser/index.d.cts +0 -3
- package/dist/parser/index.d.cts.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/parser/number.cjs +0 -48
- package/dist/parser/number.d.cts +0 -21
- package/dist/parser/number.d.cts.map +0 -1
- package/dist/parser/number.d.ts +0 -21
- package/dist/parser/number.d.ts.map +0 -1
- package/dist/parser/number.js +0 -44
- package/dist/parser/percent.cjs +0 -8
- package/dist/parser/percent.d.cts +0 -4
- package/dist/parser/percent.d.cts.map +0 -1
- package/dist/parser/percent.d.ts +0 -4
- package/dist/parser/percent.d.ts.map +0 -1
- package/dist/parser/percent.js +0 -4
- package/dist/parser/string.cjs +0 -18
- package/dist/parser/string.d.cts +0 -7
- package/dist/parser/string.d.cts.map +0 -1
- package/dist/parser/string.d.ts +0 -7
- package/dist/parser/string.d.ts.map +0 -1
- package/dist/parser/string.js +0 -14
- package/dist/price.cjs +0 -21
- package/dist/price.d.cts +0 -6
- package/dist/price.d.cts.map +0 -1
- package/dist/price.d.ts +0 -6
- package/dist/price.d.ts.map +0 -1
- package/dist/price.js +0 -17
- package/dist/random.cjs +0 -25
- package/dist/random.d.cts +0 -9
- package/dist/random.d.cts.map +0 -1
- package/dist/random.d.ts +0 -9
- package/dist/random.d.ts.map +0 -1
- package/dist/random.js +0 -14
- package/dist/react/hooks/index.cjs +0 -37
- package/dist/react/hooks/index.d.cts +0 -22
- package/dist/react/hooks/index.d.cts.map +0 -1
- package/dist/react/hooks/index.d.ts +0 -22
- package/dist/react/hooks/index.d.ts.map +0 -1
- package/dist/react/hooks/index.js +0 -21
- package/dist/react/hooks/use-abort-controller.cjs +0 -15
- package/dist/react/hooks/use-abort-controller.d.cts +0 -2
- package/dist/react/hooks/use-abort-controller.d.cts.map +0 -1
- package/dist/react/hooks/use-abort-controller.d.ts +0 -2
- package/dist/react/hooks/use-abort-controller.d.ts.map +0 -1
- package/dist/react/hooks/use-abort-controller.js +0 -11
- package/dist/react/hooks/use-abort-signal.cjs +0 -8
- package/dist/react/hooks/use-abort-signal.d.cts +0 -2
- package/dist/react/hooks/use-abort-signal.d.cts.map +0 -1
- package/dist/react/hooks/use-abort-signal.d.ts +0 -2
- package/dist/react/hooks/use-abort-signal.d.ts.map +0 -1
- package/dist/react/hooks/use-abort-signal.js +0 -4
- package/dist/react/hooks/use-click-outside.cjs +0 -17
- package/dist/react/hooks/use-click-outside.d.cts +0 -9
- package/dist/react/hooks/use-click-outside.d.cts.map +0 -1
- package/dist/react/hooks/use-click-outside.d.ts +0 -9
- package/dist/react/hooks/use-click-outside.d.ts.map +0 -1
- package/dist/react/hooks/use-click-outside.js +0 -13
- package/dist/react/hooks/use-constant.cjs +0 -19
- package/dist/react/hooks/use-constant.d.cts +0 -9
- package/dist/react/hooks/use-constant.d.cts.map +0 -1
- package/dist/react/hooks/use-constant.d.ts +0 -9
- package/dist/react/hooks/use-constant.d.ts.map +0 -1
- package/dist/react/hooks/use-define-ref.cjs +0 -19
- package/dist/react/hooks/use-define-ref.d.cts +0 -10
- package/dist/react/hooks/use-define-ref.d.cts.map +0 -1
- package/dist/react/hooks/use-define-ref.d.ts +0 -10
- package/dist/react/hooks/use-define-ref.d.ts.map +0 -1
- package/dist/react/hooks/use-element-ref.cjs +0 -12
- package/dist/react/hooks/use-element-ref.d.cts +0 -2
- package/dist/react/hooks/use-element-ref.d.cts.map +0 -1
- package/dist/react/hooks/use-element-ref.d.ts +0 -2
- package/dist/react/hooks/use-element-ref.d.ts.map +0 -1
- package/dist/react/hooks/use-element-ref.js +0 -8
- package/dist/react/hooks/use-event-listener.cjs +0 -17
- package/dist/react/hooks/use-event-listener.d.cts +0 -8
- package/dist/react/hooks/use-event-listener.d.cts.map +0 -1
- package/dist/react/hooks/use-event-listener.d.ts +0 -8
- package/dist/react/hooks/use-event-listener.d.ts.map +0 -1
- package/dist/react/hooks/use-event-listener.js +0 -13
- package/dist/react/hooks/use-event.cjs +0 -23
- package/dist/react/hooks/use-event.d.cts +0 -3
- package/dist/react/hooks/use-event.d.cts.map +0 -1
- package/dist/react/hooks/use-event.d.ts +0 -3
- package/dist/react/hooks/use-event.d.ts.map +0 -1
- package/dist/react/hooks/use-event.js +0 -19
- package/dist/react/hooks/use-flag.cjs +0 -19
- package/dist/react/hooks/use-flag.d.cts +0 -8
- package/dist/react/hooks/use-flag.d.cts.map +0 -1
- package/dist/react/hooks/use-flag.d.ts +0 -8
- package/dist/react/hooks/use-flag.d.ts.map +0 -1
- package/dist/react/hooks/use-flag.js +0 -15
- package/dist/react/hooks/use-force-update.cjs +0 -11
- package/dist/react/hooks/use-force-update.d.cts +0 -2
- package/dist/react/hooks/use-force-update.d.cts.map +0 -1
- package/dist/react/hooks/use-force-update.d.ts +0 -2
- package/dist/react/hooks/use-force-update.d.ts.map +0 -1
- package/dist/react/hooks/use-force-update.js +0 -7
- package/dist/react/hooks/use-initial-height.cjs +0 -15
- package/dist/react/hooks/use-initial-height.d.cts +0 -5
- package/dist/react/hooks/use-initial-height.d.cts.map +0 -1
- package/dist/react/hooks/use-initial-height.d.ts +0 -5
- package/dist/react/hooks/use-initial-height.d.ts.map +0 -1
- package/dist/react/hooks/use-initial-height.js +0 -11
- package/dist/react/hooks/use-instance.cjs +0 -31
- package/dist/react/hooks/use-instance.d.cts +0 -27
- package/dist/react/hooks/use-instance.d.cts.map +0 -1
- package/dist/react/hooks/use-instance.d.ts +0 -27
- package/dist/react/hooks/use-instance.d.ts.map +0 -1
- package/dist/react/hooks/use-intersection-observer.cjs +0 -14
- package/dist/react/hooks/use-intersection-observer.d.cts +0 -2
- package/dist/react/hooks/use-intersection-observer.d.cts.map +0 -1
- package/dist/react/hooks/use-intersection-observer.d.ts +0 -2
- package/dist/react/hooks/use-intersection-observer.d.ts.map +0 -1
- package/dist/react/hooks/use-intersection-observer.js +0 -10
- package/dist/react/hooks/use-last-defined-value.cjs +0 -12
- package/dist/react/hooks/use-last-defined-value.d.cts +0 -2
- package/dist/react/hooks/use-last-defined-value.d.cts.map +0 -1
- package/dist/react/hooks/use-last-defined-value.d.ts +0 -2
- package/dist/react/hooks/use-last-defined-value.d.ts.map +0 -1
- package/dist/react/hooks/use-last-defined-value.js +0 -8
- package/dist/react/hooks/use-last-value-ref.cjs +0 -12
- package/dist/react/hooks/use-last-value-ref.d.cts +0 -2
- package/dist/react/hooks/use-last-value-ref.d.cts.map +0 -1
- package/dist/react/hooks/use-last-value-ref.d.ts +0 -2
- package/dist/react/hooks/use-last-value-ref.d.ts.map +0 -1
- package/dist/react/hooks/use-last-value-ref.js +0 -8
- package/dist/react/hooks/use-life-cycle.cjs +0 -14
- package/dist/react/hooks/use-life-cycle.d.cts +0 -5
- package/dist/react/hooks/use-life-cycle.d.cts.map +0 -1
- package/dist/react/hooks/use-life-cycle.d.ts +0 -5
- package/dist/react/hooks/use-life-cycle.d.ts.map +0 -1
- package/dist/react/hooks/use-life-cycle.js +0 -10
- package/dist/react/hooks/use-resize-observer.cjs +0 -15
- package/dist/react/hooks/use-resize-observer.d.cts +0 -2
- package/dist/react/hooks/use-resize-observer.d.cts.map +0 -1
- package/dist/react/hooks/use-resize-observer.d.ts +0 -2
- package/dist/react/hooks/use-resize-observer.d.ts.map +0 -1
- package/dist/react/hooks/use-resize-observer.js +0 -11
- package/dist/react/hooks/use-sync-ref.cjs +0 -10
- package/dist/react/hooks/use-sync-ref.d.cts +0 -2
- package/dist/react/hooks/use-sync-ref.d.cts.map +0 -1
- package/dist/react/hooks/use-sync-ref.d.ts +0 -2
- package/dist/react/hooks/use-sync-ref.d.ts.map +0 -1
- package/dist/react/hooks/use-sync-ref.js +0 -6
- package/dist/react/hooks/use-toggle.cjs +0 -10
- package/dist/react/hooks/use-toggle.d.cts +0 -2
- package/dist/react/hooks/use-toggle.d.cts.map +0 -1
- package/dist/react/hooks/use-toggle.d.ts +0 -2
- package/dist/react/hooks/use-toggle.d.ts.map +0 -1
- package/dist/react/hooks/use-toggle.js +0 -6
- package/dist/react/hooks/use-value.cjs +0 -12
- package/dist/react/hooks/use-value.d.cts +0 -5
- package/dist/react/hooks/use-value.d.cts.map +0 -1
- package/dist/react/hooks/use-value.d.ts +0 -5
- package/dist/react/hooks/use-value.d.ts.map +0 -1
- package/dist/react/hooks/use-value.js +0 -8
- package/dist/react/hooks/use-visibility-state.cjs +0 -18
- package/dist/react/hooks/use-visibility-state.d.cts +0 -2
- package/dist/react/hooks/use-visibility-state.d.cts.map +0 -1
- package/dist/react/hooks/use-visibility-state.d.ts +0 -2
- package/dist/react/hooks/use-visibility-state.d.ts.map +0 -1
- package/dist/react/hooks/use-visibility-state.js +0 -14
- package/dist/react/index.cjs +0 -17
- package/dist/react/index.d.cts +0 -2
- package/dist/react/index.d.cts.map +0 -1
- package/dist/react/index.d.ts +0 -2
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -1
- package/dist/sound.cjs +0 -16
- package/dist/sound.d.cts +0 -7
- package/dist/sound.d.cts.map +0 -1
- package/dist/sound.d.ts +0 -7
- package/dist/sound.d.ts.map +0 -1
- package/dist/sound.js +0 -12
- package/dist/storage.cjs +0 -48
- package/dist/storage.d.cts +0 -39
- package/dist/storage.d.cts.map +0 -1
- package/dist/storage.d.ts +0 -39
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -43
- package/dist/text.cjs +0 -53
- package/dist/text.d.cts +0 -15
- package/dist/text.d.cts.map +0 -1
- package/dist/text.d.ts +0 -15
- package/dist/text.d.ts.map +0 -1
- package/dist/text.js +0 -48
- package/dist/type-guard/_exports.cjs +0 -129
- package/dist/type-guard/_exports.d.cts +0 -86
- package/dist/type-guard/_exports.d.cts.map +0 -1
- package/dist/type-guard/_exports.d.ts +0 -86
- package/dist/type-guard/_exports.d.ts.map +0 -1
- package/dist/type-guard/_exports.js +0 -125
- package/dist/type-guard/index.cjs +0 -40
- package/dist/type-guard/index.d.cts +0 -3
- package/dist/type-guard/index.d.cts.map +0 -1
- package/dist/type-guard/index.d.ts +0 -3
- package/dist/type-guard/index.d.ts.map +0 -1
- package/dist/utils/types.cjs +0 -2
- package/dist/utils/types.d.cts +0 -395
- package/dist/utils/types.d.cts.map +0 -1
- package/dist/utils/types.d.ts +0 -395
- package/dist/utils/types.d.ts.map +0 -1
- package/dist/utils/types.js +0 -1
- package/dist/vibrate.cjs +0 -12
- package/dist/vibrate.d.cts +0 -5
- package/dist/vibrate.d.cts.map +0 -1
- package/dist/vibrate.d.ts +0 -5
- package/dist/vibrate.d.ts.map +0 -1
- package/dist/vibrate.js +0 -8
- package/utility-types.d.ts +0 -395
- package/utils/types.cjs +0 -2
- package/utils/types.d.cts +0 -395
- package/utils/types.d.cts.map +0 -1
- package/utils/types.d.ts +0 -395
- package/utils/types.d.ts.map +0 -1
- package/utils/types.js +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { reaction } from 'mobx';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { DeepObservableStruct } from './deep-observable-struct';
|
|
4
|
+
|
|
5
|
+
const dataSet = {
|
|
6
|
+
values: {
|
|
7
|
+
a1: 1,
|
|
8
|
+
a2: 'string',
|
|
9
|
+
a3: 'strign',
|
|
10
|
+
a4: 1,
|
|
11
|
+
a5: { a5_1: 0, a5_2: 0, a5_3: 0, a5_4: 0 },
|
|
12
|
+
a6: {
|
|
13
|
+
a6_1: ['1', '2', '3'],
|
|
14
|
+
a6_2: false,
|
|
15
|
+
a6_3: false,
|
|
16
|
+
a6_4: ['1', '2', '3'],
|
|
17
|
+
a6_5: [],
|
|
18
|
+
},
|
|
19
|
+
a7: {},
|
|
20
|
+
a8: {
|
|
21
|
+
a8_1: { a8_1_1: true, a8_1_2: '' },
|
|
22
|
+
},
|
|
23
|
+
a9: 'string',
|
|
24
|
+
a10: 'string',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('DeepObservableStruct', () => {
|
|
29
|
+
it('should set data correctly', () => {
|
|
30
|
+
const sourceValue = structuredClone(dataSet);
|
|
31
|
+
const struct = new DeepObservableStruct(sourceValue);
|
|
32
|
+
|
|
33
|
+
expect(struct.data).toEqual(structuredClone(dataSet));
|
|
34
|
+
|
|
35
|
+
const nextData = structuredClone(dataSet);
|
|
36
|
+
nextData.values.a8.a8_1.a8_1_2 = 'new value';
|
|
37
|
+
|
|
38
|
+
struct.set(nextData);
|
|
39
|
+
|
|
40
|
+
expect(struct.data).toEqual(nextData);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should MobX reaction ignores all updates expect real changes', () => {
|
|
44
|
+
const sourceValue = structuredClone(dataSet);
|
|
45
|
+
const struct = new DeepObservableStruct(sourceValue);
|
|
46
|
+
|
|
47
|
+
expect(struct.data).toEqual(structuredClone(dataSet));
|
|
48
|
+
|
|
49
|
+
const reaction1Spy = vi.fn();
|
|
50
|
+
const reaction2Spy = vi.fn();
|
|
51
|
+
const reaction3Spy = vi.fn();
|
|
52
|
+
const reaction4Spy = vi.fn();
|
|
53
|
+
|
|
54
|
+
reaction(() => struct.data.values.a2, reaction1Spy);
|
|
55
|
+
reaction(() => struct.data.values.a8, reaction2Spy);
|
|
56
|
+
reaction(() => struct.data.values.a8.a8_1, reaction3Spy);
|
|
57
|
+
reaction(() => struct.data.values.a8.a8_1.a8_1_2, reaction4Spy);
|
|
58
|
+
|
|
59
|
+
const nextData = structuredClone(dataSet);
|
|
60
|
+
nextData.values.a8.a8_1.a8_1_2 = 'new value';
|
|
61
|
+
|
|
62
|
+
struct.set(nextData);
|
|
63
|
+
|
|
64
|
+
expect(reaction1Spy).not.toBeCalled();
|
|
65
|
+
expect(reaction2Spy).not.toBeCalled();
|
|
66
|
+
expect(reaction3Spy).not.toBeCalled();
|
|
67
|
+
expect(reaction4Spy).toBeCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
+
import { typeGuard } from '../type-guard/index.js';
|
|
3
|
+
import type { AnyObject } from '../utils/types.js';
|
|
4
|
+
|
|
5
|
+
export class DeepObservableStruct<TData extends AnyObject> {
|
|
6
|
+
data: TData;
|
|
7
|
+
|
|
8
|
+
constructor(data: TData) {
|
|
9
|
+
this.data = data;
|
|
10
|
+
|
|
11
|
+
makeObservable(this, {
|
|
12
|
+
data: observable.deep,
|
|
13
|
+
set: action,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set(newData: Partial<TData>) {
|
|
18
|
+
type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];
|
|
19
|
+
|
|
20
|
+
const stack: StackItem[] = Object.keys(this.data).map((key) => [
|
|
21
|
+
key,
|
|
22
|
+
this.data,
|
|
23
|
+
newData,
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
let currentIndex = 0;
|
|
27
|
+
let stackLength = stack.length;
|
|
28
|
+
|
|
29
|
+
while (currentIndex < stackLength) {
|
|
30
|
+
const [key, currObservableData, newData] = stack[currentIndex];
|
|
31
|
+
const newValue = newData[key];
|
|
32
|
+
const currValue = currObservableData[key];
|
|
33
|
+
|
|
34
|
+
currentIndex++;
|
|
35
|
+
|
|
36
|
+
if (key in newData) {
|
|
37
|
+
if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {
|
|
38
|
+
const newValueKeys = Object.keys(newValue);
|
|
39
|
+
|
|
40
|
+
Object.keys(currValue).forEach((childKey) => {
|
|
41
|
+
if (!(childKey in newValue)) {
|
|
42
|
+
delete currObservableData[key][childKey];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
newValueKeys.forEach((childKey) => {
|
|
47
|
+
const length = stack.push([
|
|
48
|
+
childKey,
|
|
49
|
+
currObservableData[key],
|
|
50
|
+
newValue,
|
|
51
|
+
]);
|
|
52
|
+
stackLength = length;
|
|
53
|
+
});
|
|
54
|
+
} else if (newValue !== currValue) {
|
|
55
|
+
currObservableData[key] = newValue;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
delete currObservableData[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Object.keys(newData).forEach((newDataKey) => {
|
|
63
|
+
if (!this.data[newDataKey]) {
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
this.data[newDataKey] = newData[newDataKey];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { $mobx, type AnnotationMapEntry } from 'mobx';
|
|
2
|
+
import type { AnyObject } from '../utils/types.js';
|
|
3
|
+
|
|
4
|
+
type ObservableObjectAdministration = Parameters<
|
|
5
|
+
Exclude<AnnotationMapEntry, boolean>['make_']
|
|
6
|
+
>[0];
|
|
7
|
+
|
|
8
|
+
export const getMobxAdministration = (
|
|
9
|
+
context: AnyObject,
|
|
10
|
+
): ObservableObjectAdministration => context[$mobx];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { onBecomeObserved, onBecomeUnobserved } from 'mobx';
|
|
2
|
+
|
|
3
|
+
export const lazyObserve = <TMetaData = void>({
|
|
4
|
+
context,
|
|
5
|
+
property,
|
|
6
|
+
onStart,
|
|
7
|
+
onEnd,
|
|
8
|
+
endDelay = 0,
|
|
9
|
+
}: {
|
|
10
|
+
context?: any;
|
|
11
|
+
property: any | any[];
|
|
12
|
+
onStart: () => TMetaData;
|
|
13
|
+
onEnd: (metaData: TMetaData, cleanupFn: VoidFunction) => void;
|
|
14
|
+
endDelay?: number;
|
|
15
|
+
}) => {
|
|
16
|
+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
17
|
+
let metaData: TMetaData | undefined;
|
|
18
|
+
const properties = Array.isArray(property) ? property : [property];
|
|
19
|
+
let isObserving = false;
|
|
20
|
+
|
|
21
|
+
const start = () => {
|
|
22
|
+
if (isObserving) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
isObserving = true;
|
|
26
|
+
if (timeoutId) {
|
|
27
|
+
clearTimeout(timeoutId);
|
|
28
|
+
timeoutId = undefined;
|
|
29
|
+
}
|
|
30
|
+
metaData = onStart();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const cleanup = () => {
|
|
34
|
+
if (!isObserving) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (timeoutId) {
|
|
38
|
+
clearTimeout(timeoutId);
|
|
39
|
+
timeoutId = undefined;
|
|
40
|
+
}
|
|
41
|
+
timeoutId = setTimeout(() => {
|
|
42
|
+
onEnd(metaData!, cleanup);
|
|
43
|
+
timeoutId = undefined;
|
|
44
|
+
metaData = undefined;
|
|
45
|
+
}, endDelay);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
properties.forEach((property) => {
|
|
49
|
+
if (context) {
|
|
50
|
+
onBecomeObserved(context, property, start);
|
|
51
|
+
onBecomeUnobserved(context, property, cleanup);
|
|
52
|
+
} else {
|
|
53
|
+
onBecomeObserved(property, start);
|
|
54
|
+
onBecomeUnobserved(property, cleanup);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return cleanup;
|
|
59
|
+
};
|
package/src/ms.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Переводит значение в юнитах в миллисекунды
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* ms(1, 'min') // 60_000
|
|
16
|
+
* ms(30, 'sec') // 30_000
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>
|
|
20
|
+
value * unitsToMs[unit];
|
package/src/number.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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: number, decimalPlaces: number = 0): number {
|
|
8
|
+
if (!decimalPlaces) {
|
|
9
|
+
return Math.round(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const factor = 10 ** decimalPlaces;
|
|
13
|
+
return Math.round(value * factor) / factor;
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { number } from './number';
|
|
3
|
+
|
|
4
|
+
describe('parser.number', () => {
|
|
5
|
+
test('empty string should return 0', () => {
|
|
6
|
+
expect(number('')).toBe(0);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('empty string with fallback should return fallback', () => {
|
|
10
|
+
expect(number('', { fallback: 'kek' })).toBe('kek');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('Checking the logic of the function', () => {
|
|
14
|
+
expect(number(1)).toBe(1);
|
|
15
|
+
expect(number(100)).toBe(100);
|
|
16
|
+
expect(number(500)).toBe(500);
|
|
17
|
+
expect(number(1, { clamped: [400] })).toBe(400);
|
|
18
|
+
expect(number(1001, { clamped: [null, 1000] })).toBe(1000);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('Rounding down', () => {
|
|
22
|
+
expect(number(5.9, { floor: true })).toBe(5);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('Rounding up', () => {
|
|
26
|
+
expect(number(5.1, { ceil: true })).toBe(6);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('Processing invalid values', () => {
|
|
30
|
+
expect(number(null)).toBe(0);
|
|
31
|
+
expect(number(undefined)).toBe(0);
|
|
32
|
+
expect(number('-')).toBe(0);
|
|
33
|
+
expect(number('test')).toBe(0);
|
|
34
|
+
|
|
35
|
+
expect(number(null, null)).toBe(0);
|
|
36
|
+
expect(number(undefined, undefined)).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { skipSpaces } from '../format/skip-spaces.js';
|
|
2
|
+
import { typeGuard } from '../type-guard/index.js';
|
|
3
|
+
import type { Maybe } from '../utils/types.js';
|
|
4
|
+
|
|
5
|
+
export interface NumberParserSettings<TFallback = number> {
|
|
6
|
+
digits?: number;
|
|
7
|
+
fallback?: TFallback;
|
|
8
|
+
/**
|
|
9
|
+
* Round to upper boundary
|
|
10
|
+
* 5.1 -> 6
|
|
11
|
+
*/
|
|
12
|
+
ceil?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Round to bottom boundary
|
|
15
|
+
* 5.9 -> 5
|
|
16
|
+
*/
|
|
17
|
+
floor?: boolean;
|
|
18
|
+
clamped?: [min?: Maybe<number>, max?: Maybe<number>];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const number = <TFallback = number>(
|
|
22
|
+
input: Maybe<unknown>,
|
|
23
|
+
userSettings?: Maybe<NumberParserSettings<TFallback>>,
|
|
24
|
+
): number | TFallback => {
|
|
25
|
+
const settings = {
|
|
26
|
+
...number.defaultSettings,
|
|
27
|
+
...userSettings,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const fallback = settings?.fallback ?? 0;
|
|
31
|
+
|
|
32
|
+
let result: number;
|
|
33
|
+
|
|
34
|
+
if (typeGuard.isNumber(input)) {
|
|
35
|
+
result = input;
|
|
36
|
+
} else if (typeGuard.isString(input)) {
|
|
37
|
+
const formattedInput = skipSpaces(input).replace(',', '.');
|
|
38
|
+
if (formattedInput === '') {
|
|
39
|
+
result = fallback as any;
|
|
40
|
+
} else {
|
|
41
|
+
result = Number(formattedInput);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
result = fallback as any;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeGuard.isNumber(result)) {
|
|
48
|
+
if (settings?.clamped != null) {
|
|
49
|
+
result = Math.max(
|
|
50
|
+
settings.clamped[0] ?? -Infinity,
|
|
51
|
+
Math.min(result, settings.clamped[1] ?? Infinity),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (settings?.ceil != null) {
|
|
56
|
+
result = Math.ceil(result);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (settings?.floor != null) {
|
|
60
|
+
result = Math.floor(result);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (settings?.digits != null) {
|
|
64
|
+
result = +result.toFixed(settings.digits);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
} else {
|
|
69
|
+
return fallback;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
number.defaultSettings = {} as NumberParserSettings;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Maybe } from '../utils/types.js';
|
|
2
|
+
|
|
3
|
+
import { type NumberParserSettings, number } from './number.js';
|
|
4
|
+
|
|
5
|
+
export const percent = <TFallback = number>(
|
|
6
|
+
value: Maybe<string | number>,
|
|
7
|
+
maxValue?: Maybe<string | number>,
|
|
8
|
+
settings?: Maybe<NumberParserSettings<TFallback>>,
|
|
9
|
+
) => {
|
|
10
|
+
return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { typeGuard } from '../type-guard/index.js';
|
|
2
|
+
import type { Maybe } from '../utils/types.js';
|
|
3
|
+
|
|
4
|
+
export interface StringParserSettings<TFallback = string> {
|
|
5
|
+
fallback?: TFallback;
|
|
6
|
+
prettyJson?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const string = <TFallback = string>(
|
|
10
|
+
input: Maybe<unknown>,
|
|
11
|
+
settings?: Maybe<StringParserSettings<TFallback>>,
|
|
12
|
+
): string | TFallback => {
|
|
13
|
+
const fallback =
|
|
14
|
+
settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';
|
|
15
|
+
|
|
16
|
+
if (input == null) {
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeGuard.isObject(input)) {
|
|
21
|
+
if (settings?.prettyJson) {
|
|
22
|
+
return JSON.stringify(input, null, 2);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return JSON.stringify(input);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return String(input);
|
|
29
|
+
};
|
package/src/price.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface PriceFormatOptions
|
|
2
|
+
extends Partial<Omit<Intl.NumberFormatOptions, 'currency'>> {
|
|
3
|
+
withoutSymbol?: boolean;
|
|
4
|
+
customSymbol?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const formatPrice = (
|
|
8
|
+
price: number,
|
|
9
|
+
locale: string,
|
|
10
|
+
currency?: string,
|
|
11
|
+
{ withoutSymbol, customSymbol, ...options }: PriceFormatOptions = {},
|
|
12
|
+
) => {
|
|
13
|
+
const priceFormatter = new Intl.NumberFormat(locale, {
|
|
14
|
+
style: 'currency',
|
|
15
|
+
currency,
|
|
16
|
+
minimumFractionDigits: 0,
|
|
17
|
+
currencyDisplay: 'narrowSymbol',
|
|
18
|
+
...options,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const zeroPrice = priceFormatter.format(0);
|
|
22
|
+
const currencySymbol = zeroPrice.replace('0', '');
|
|
23
|
+
const rawPrice = priceFormatter.format(price);
|
|
24
|
+
const priceWithoutCurrency = rawPrice.replace(currencySymbol, '');
|
|
25
|
+
|
|
26
|
+
if (withoutSymbol) {
|
|
27
|
+
return priceWithoutCurrency;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return `${priceWithoutCurrency} ${
|
|
31
|
+
customSymbol ?? (currency === 'RUB' ? 'р' : currencySymbol)
|
|
32
|
+
}`.replace(/\s{2,}/, ' ');
|
|
33
|
+
};
|
package/src/random.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const getRandomFloat = <T extends number = number>(
|
|
2
|
+
min = 0,
|
|
3
|
+
max = 1,
|
|
4
|
+
): T => (Math.random() * (max - min) + min) as T;
|
|
5
|
+
|
|
6
|
+
export const getRandomInt = <T extends number = number>(min = 0, max = 1): T =>
|
|
7
|
+
min === max ? (min as T) : (Math.round(getRandomFloat(min, max)) as T);
|
|
8
|
+
|
|
9
|
+
export const getRandomChoice = <T>(arr: T[]): T =>
|
|
10
|
+
arr[getRandomInt(0, arr.length - 1)];
|
|
11
|
+
|
|
12
|
+
export const getRandomSizeArray = (min = 0, max = 10) =>
|
|
13
|
+
Array.from({ length: getRandomInt(min, max) }).fill(null);
|
|
14
|
+
|
|
15
|
+
export const getRandomBool = () => getRandomInt(0, 1) === 1;
|
|
16
|
+
|
|
17
|
+
export const getMajorRandomBool = () => {
|
|
18
|
+
return getRandomInt(0, 10) <= 6;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getMinorRandomBool = () => {
|
|
22
|
+
return !getMajorRandomBool();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const getFrequencyValue = (frequency: number) => {
|
|
26
|
+
return Math.random() < frequency;
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './use-abort-controller.js';
|
|
2
|
+
export * from './use-abort-signal.js';
|
|
3
|
+
export * from './use-click-outside.js';
|
|
4
|
+
export * from './use-constant.js';
|
|
5
|
+
export * from './use-define-ref.js';
|
|
6
|
+
export * from './use-element-ref.js';
|
|
7
|
+
export * from './use-event.js';
|
|
8
|
+
export * from './use-event-listener.js';
|
|
9
|
+
export * from './use-flag.js';
|
|
10
|
+
export * from './use-force-update.js';
|
|
11
|
+
export * from './use-initial-height.js';
|
|
12
|
+
export * from './use-instance.js';
|
|
13
|
+
export * from './use-intersection-observer.js';
|
|
14
|
+
export * from './use-last-defined-value.js';
|
|
15
|
+
export * from './use-last-value-ref.js';
|
|
16
|
+
export * from './use-life-cycle.js';
|
|
17
|
+
export * from './use-resize-observer.js';
|
|
18
|
+
export * from './use-sync-ref.js';
|
|
19
|
+
export * from './use-toggle.js';
|
|
20
|
+
export * from './use-value.js';
|
|
21
|
+
export * from './use-visibility-state.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useConstant } from './use-constant.js';
|
|
4
|
+
|
|
5
|
+
export const useAbortController = () => {
|
|
6
|
+
const controller = useConstant(() => new AbortController());
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
return () => {
|
|
10
|
+
controller.abort();
|
|
11
|
+
};
|
|
12
|
+
}, []);
|
|
13
|
+
|
|
14
|
+
return controller;
|
|
15
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import { useEventListener } from './use-event-listener.js';
|
|
3
|
+
|
|
4
|
+
type ClickOutsideInput = {
|
|
5
|
+
contentRef: MutableRefObject<HTMLElement | null>;
|
|
6
|
+
onClick: VoidFunction;
|
|
7
|
+
options?: AddEventListenerOptions;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const useClickOutside = ({
|
|
11
|
+
contentRef,
|
|
12
|
+
onClick,
|
|
13
|
+
options,
|
|
14
|
+
}: ClickOutsideInput) => {
|
|
15
|
+
useEventListener({
|
|
16
|
+
event: 'mousedown',
|
|
17
|
+
handler: (event) => {
|
|
18
|
+
if (
|
|
19
|
+
contentRef.current &&
|
|
20
|
+
!contentRef.current.contains(event.target as Node)
|
|
21
|
+
) {
|
|
22
|
+
onClick();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
options,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* React hook for creating a value exactly once.
|
|
4
5
|
* useMemo doesn't give this guarantee unfortunately -
|
|
@@ -6,10 +7,12 @@ import { useRef } from 'react';
|
|
|
6
7
|
* https://reactjs.org/docs/hooks-reference.html#usememo
|
|
7
8
|
* @param defineValue Function which returns defined value.
|
|
8
9
|
*/
|
|
9
|
-
export const useConstant = (defineValue) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
10
|
+
export const useConstant = <T>(defineValue: () => T): T => {
|
|
11
|
+
const ref = useRef<{ value: T }>();
|
|
12
|
+
|
|
13
|
+
if (!ref.current) {
|
|
14
|
+
ref.current = { value: defineValue() };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return ref.current.value;
|
|
15
18
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
1
|
+
import { type MutableRefObject, useRef } from 'react';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* React hook for creating a value exactly once.
|
|
4
5
|
* useMemo doesn't give this guarantee unfortunately -
|
|
@@ -6,10 +7,12 @@ import { useRef } from 'react';
|
|
|
6
7
|
* https://reactjs.org/docs/hooks-reference.html#usememo
|
|
7
8
|
* @param defineFn Function which returns defined value.
|
|
8
9
|
*/
|
|
9
|
-
export const useDefineRef = (defineFn) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export const useDefineRef = <T>(defineFn: () => T): MutableRefObject<T> => {
|
|
11
|
+
const ref = useRef<T>(void 0 as T);
|
|
12
|
+
|
|
13
|
+
if (!ref.current) {
|
|
14
|
+
ref.current = defineFn();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return ref;
|
|
15
18
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useSyncRef } from './use-sync-ref.js';
|
|
4
|
+
|
|
5
|
+
export const useEventListener = <EventName extends keyof HTMLElementEventMap>({
|
|
6
|
+
event,
|
|
7
|
+
handler,
|
|
8
|
+
options,
|
|
9
|
+
deps = [],
|
|
10
|
+
node = document,
|
|
11
|
+
}: {
|
|
12
|
+
event: EventName;
|
|
13
|
+
handler: (e: HTMLElementEventMap[EventName]) => void;
|
|
14
|
+
options?: boolean | AddEventListenerOptions;
|
|
15
|
+
deps?: unknown[];
|
|
16
|
+
node?: HTMLElement | Document | Window;
|
|
17
|
+
}) => {
|
|
18
|
+
const handlerRef = useSyncRef(handler);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const handleEvent = (e: HTMLElementEventMap[EventName]) =>
|
|
22
|
+
handlerRef.current(e);
|
|
23
|
+
|
|
24
|
+
// @ts-expect-error
|
|
25
|
+
node.addEventListener(event, handleEvent, options);
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
return () => node.removeEventListener(event, handleEvent, options);
|
|
28
|
+
}, deps);
|
|
29
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Hook to define an event handler with an always-stable function identity.
|
|
3
|
+
*
|
|
4
|
+
* borrowed from @gaeron
|
|
5
|
+
* https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
|
|
6
|
+
*/
|
|
7
|
+
import { useCallback, useLayoutEffect, useRef } from 'react';
|
|
8
|
+
import type { AnyFunction } from '../../utils/types.js';
|
|
9
|
+
|
|
10
|
+
export const useEvent = <H extends AnyFunction>(handler: H): H => {
|
|
11
|
+
const handlerRef = useRef<H>(handler);
|
|
12
|
+
|
|
13
|
+
// In a real implementation, this would run before layout effects
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
handlerRef.current = handler;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return useCallback((...args: unknown[]) => {
|
|
19
|
+
// In a real implementation, this would throw if called during render
|
|
20
|
+
const fn = handlerRef.current as AnyFunction;
|
|
21
|
+
return fn(...args);
|
|
22
|
+
}, []) as unknown as H;
|
|
23
|
+
};
|