yummies 5.4.4 → 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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface FlagHook {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
toggle: VoidFunction;
|
|
6
|
+
enable: VoidFunction;
|
|
7
|
+
disable: VoidFunction;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useFlag = (defaultValue = false): FlagHook => {
|
|
11
|
+
const [enabled, setEnabled] = useState(defaultValue);
|
|
12
|
+
|
|
13
|
+
const toggle = useCallback(() => setEnabled((value) => !value), []);
|
|
14
|
+
const enable = useCallback(() => setEnabled(true), []);
|
|
15
|
+
const disable = useCallback(() => setEnabled(false), []);
|
|
16
|
+
|
|
17
|
+
const flagObjRef = useRef<FlagHook>({
|
|
18
|
+
enabled,
|
|
19
|
+
toggle,
|
|
20
|
+
enable,
|
|
21
|
+
disable,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
flagObjRef.current.enabled = enabled;
|
|
25
|
+
|
|
26
|
+
return flagObjRef.current;
|
|
27
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useInitialHeight = <T extends HTMLElement>() => {
|
|
4
|
+
const ref = useRef<T | null>(null);
|
|
5
|
+
const [initialHeight, setInitialHeight] = useState<number | undefined>(
|
|
6
|
+
undefined,
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (ref.current && !initialHeight) {
|
|
11
|
+
setInitialHeight(ref.current.offsetHeight);
|
|
12
|
+
}
|
|
13
|
+
}, [initialHeight]);
|
|
14
|
+
|
|
15
|
+
return { ref, initialHeight };
|
|
16
|
+
};
|
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
import { useLayoutEffect } from 'react';
|
|
2
|
-
import { useAbortSignal } from
|
|
3
|
-
import { useConstant } from
|
|
4
|
-
|
|
2
|
+
import { useAbortSignal } from './use-abort-signal.js';
|
|
3
|
+
import { useConstant } from './use-constant.js';
|
|
4
|
+
|
|
5
|
+
export type InstanceCreateConfig<TPayload, TExtension = {}> = TExtension & {
|
|
6
|
+
abortSignal: AbortSignal;
|
|
7
|
+
payload: TPayload;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const createUseInstanceHook =
|
|
11
|
+
<TExtension = {}>(extension?: TExtension) =>
|
|
12
|
+
<TInstance, TPayload>(
|
|
13
|
+
factory: (
|
|
14
|
+
config: InstanceCreateConfig<NoInfer<TPayload>, TExtension>,
|
|
15
|
+
) => TInstance,
|
|
16
|
+
config?: {
|
|
17
|
+
payload?: TPayload;
|
|
18
|
+
onUpdate?: (payload: TPayload) => void;
|
|
19
|
+
},
|
|
20
|
+
) => {
|
|
5
21
|
const abortSignal = useAbortSignal();
|
|
6
|
-
|
|
7
|
-
|
|
22
|
+
|
|
23
|
+
const instance = useConstant(() =>
|
|
24
|
+
factory({
|
|
25
|
+
...(extension as TExtension),
|
|
8
26
|
abortSignal,
|
|
9
|
-
payload: config?.payload,
|
|
10
|
-
|
|
27
|
+
payload: config?.payload as any,
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
|
|
11
31
|
useLayoutEffect(() => {
|
|
12
|
-
|
|
32
|
+
config?.onUpdate?.(config.payload!);
|
|
13
33
|
}, [config?.payload]);
|
|
34
|
+
|
|
14
35
|
return instance;
|
|
15
|
-
};
|
|
36
|
+
};
|
|
37
|
+
|
|
16
38
|
/**
|
|
17
39
|
* The `useInstance` hook is used to create and manage an instance of an object
|
|
18
40
|
* that requires access to the root store and an abort signal.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useIntersectionObserver = (
|
|
4
|
+
callback: IntersectionObserverCallback,
|
|
5
|
+
options?: IntersectionObserverInit,
|
|
6
|
+
) => {
|
|
7
|
+
const [intersectionObserver] = useState(
|
|
8
|
+
() => new IntersectionObserver(callback, options),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
return () => {
|
|
13
|
+
intersectionObserver.disconnect();
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
|
|
17
|
+
return intersectionObserver;
|
|
18
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useSyncRef } from './use-sync-ref.js';
|
|
3
|
+
|
|
4
|
+
export const useLifeCycle = (
|
|
5
|
+
fn: () => {
|
|
6
|
+
mount?: VoidFunction;
|
|
7
|
+
unmount?: VoidFunction;
|
|
8
|
+
},
|
|
9
|
+
) => {
|
|
10
|
+
const fnRef = useSyncRef(fn);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const fnOperation = fnRef.current();
|
|
14
|
+
fnOperation.mount?.();
|
|
15
|
+
return fnOperation.unmount?.();
|
|
16
|
+
}, []);
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
import { useDefineRef } from './use-define-ref.js';
|
|
3
|
+
|
|
4
|
+
export const useResizeObserver = (callback: ResizeObserverCallback) => {
|
|
5
|
+
const resizeObserverRef = useDefineRef(() => new ResizeObserver(callback));
|
|
6
|
+
|
|
7
|
+
useLayoutEffect(() => {
|
|
8
|
+
return () => {
|
|
9
|
+
resizeObserverRef.current.disconnect();
|
|
10
|
+
};
|
|
11
|
+
}, []);
|
|
12
|
+
|
|
13
|
+
return resizeObserverRef;
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useToggle = (initialState?: boolean) => {
|
|
4
|
+
const [toggled, setToggled] = useState(!!initialState);
|
|
5
|
+
|
|
6
|
+
const toggle = useCallback(() => setToggled((toggled) => !toggled), []);
|
|
7
|
+
|
|
8
|
+
return [toggled, toggle, setToggled] as const;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useVisibilityState = () => {
|
|
4
|
+
const [state, setState] = useState<DocumentVisibilityState>();
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const handleVisibilityChange = () => {
|
|
8
|
+
setState(document.visibilityState);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
12
|
+
|
|
13
|
+
return () => {
|
|
14
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
return state;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks/index.js';
|
package/src/sound.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Воспроизводит звук из файла
|
|
3
|
+
*/
|
|
4
|
+
export const playSound = async (
|
|
5
|
+
file: string,
|
|
6
|
+
{ volume = 1 }: { volume?: number } = {},
|
|
7
|
+
) => {
|
|
8
|
+
let audio = new Audio(file);
|
|
9
|
+
audio.volume = volume;
|
|
10
|
+
audio.muted = !volume;
|
|
11
|
+
await audio.play();
|
|
12
|
+
audio.remove();
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
audio = null;
|
|
15
|
+
};
|
package/src/storage.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export type StorageType = 'session' | 'local';
|
|
2
|
+
|
|
3
|
+
const storages: Record<StorageType, Storage> = {
|
|
4
|
+
session: sessionStorage,
|
|
5
|
+
local: localStorage,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const createStorageKey = (
|
|
9
|
+
prefix: string,
|
|
10
|
+
key: string,
|
|
11
|
+
namespace?: string,
|
|
12
|
+
) => `${prefix}${namespace ? `/${namespace}` : ''}/${key}`;
|
|
13
|
+
|
|
14
|
+
const parseStorageValue = <V>(value: unknown): V | null => {
|
|
15
|
+
if (typeof value !== 'string') {
|
|
16
|
+
return value as V;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(value);
|
|
21
|
+
return parsed;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const formatValueToStorage = (value: unknown): string => {
|
|
28
|
+
return JSON.stringify(value);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export interface SetToStorageConfig<V>
|
|
32
|
+
extends Omit<GetFromStorageConfig<V>, 'fallback'> {
|
|
33
|
+
value: V;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface GetFromStorageConfig<V> {
|
|
37
|
+
/**
|
|
38
|
+
* Ключ по которому можно получить значение из хранилища (имя ключа не полное, оно дополняется неймпспейсом проекта)
|
|
39
|
+
*/
|
|
40
|
+
key: string;
|
|
41
|
+
/**
|
|
42
|
+
* Тип хранилища
|
|
43
|
+
*/
|
|
44
|
+
type: StorageType;
|
|
45
|
+
/**
|
|
46
|
+
* дефолтное значение, которое будет использоваться если значения нет в хранилище
|
|
47
|
+
*/
|
|
48
|
+
fallback?: V;
|
|
49
|
+
/**
|
|
50
|
+
* Доп. делитель в ключ/utils/types'е
|
|
51
|
+
*/
|
|
52
|
+
namespace?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Доп. делитель
|
|
55
|
+
*/
|
|
56
|
+
prefix?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type SetToStorageWrappedConfig<
|
|
60
|
+
V,
|
|
61
|
+
BaseConfig extends StorageConfigBase,
|
|
62
|
+
> = Omit<
|
|
63
|
+
SetToStorageConfig<V>,
|
|
64
|
+
Extract<keyof SetToStorageConfig<V>, keyof BaseConfig>
|
|
65
|
+
> &
|
|
66
|
+
Partial<
|
|
67
|
+
Pick<
|
|
68
|
+
SetToStorageConfig<V>,
|
|
69
|
+
Extract<keyof SetToStorageConfig<V>, keyof BaseConfig>
|
|
70
|
+
>
|
|
71
|
+
> &
|
|
72
|
+
Pick<BaseConfig, Exclude<keyof BaseConfig, keyof SetToStorageConfig<V>>>;
|
|
73
|
+
|
|
74
|
+
export type GetFromStorageWrappedConfig<
|
|
75
|
+
V,
|
|
76
|
+
BaseConfig extends StorageConfigBase,
|
|
77
|
+
> = Omit<
|
|
78
|
+
GetFromStorageConfig<V>,
|
|
79
|
+
Extract<keyof GetFromStorageConfig<V>, keyof BaseConfig>
|
|
80
|
+
> &
|
|
81
|
+
Partial<
|
|
82
|
+
Pick<
|
|
83
|
+
GetFromStorageConfig<V>,
|
|
84
|
+
Extract<keyof GetFromStorageConfig<V>, keyof BaseConfig>
|
|
85
|
+
>
|
|
86
|
+
> &
|
|
87
|
+
Pick<BaseConfig, Exclude<keyof BaseConfig, keyof GetFromStorageConfig<V>>>;
|
|
88
|
+
|
|
89
|
+
export type StorageConfigBase = Partial<
|
|
90
|
+
Pick<GetFromStorageConfig<any>, 'prefix' | 'type'>
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
export interface StorageApi<BaseConfig extends StorageConfigBase> {
|
|
94
|
+
set<Value>(config: SetToStorageWrappedConfig<Value, BaseConfig>): void;
|
|
95
|
+
get<Value>(
|
|
96
|
+
config: GetFromStorageWrappedConfig<Value, BaseConfig>,
|
|
97
|
+
): Value | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Создает интерфейс для работы с хранилищем (localStorage, sessionStorage)
|
|
102
|
+
*/
|
|
103
|
+
export function createStorage<BaseConfig extends StorageConfigBase>(
|
|
104
|
+
storageConfig: BaseConfig,
|
|
105
|
+
): StorageApi<BaseConfig> {
|
|
106
|
+
return {
|
|
107
|
+
set: <Value>(cfg: SetToStorageWrappedConfig<Value, BaseConfig>) => {
|
|
108
|
+
const config = cfg as unknown as SetToStorageConfig<Value>;
|
|
109
|
+
const storageType = (config.type ?? storageConfig.type!) as StorageType;
|
|
110
|
+
const storagePrefix = (config.prefix ?? storageConfig.prefix!) as string;
|
|
111
|
+
|
|
112
|
+
const storage = storages[storageType];
|
|
113
|
+
|
|
114
|
+
storage.setItem(
|
|
115
|
+
createStorageKey(storagePrefix, config.key, config.namespace),
|
|
116
|
+
formatValueToStorage(config.value),
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
get: <Value>(cfg: GetFromStorageWrappedConfig<Value, BaseConfig>) => {
|
|
120
|
+
const config = cfg as unknown as GetFromStorageConfig<Value>;
|
|
121
|
+
const storageType = (config.type ?? storageConfig.type!) as StorageType;
|
|
122
|
+
const storagePrefix = (config.prefix ?? storageConfig.prefix!) as string;
|
|
123
|
+
|
|
124
|
+
const storage = storages[storageType];
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
parseStorageValue<Value>(
|
|
128
|
+
storage.getItem(
|
|
129
|
+
createStorageKey(storagePrefix, config.key, config.namespace),
|
|
130
|
+
),
|
|
131
|
+
) ??
|
|
132
|
+
config.fallback ??
|
|
133
|
+
null
|
|
134
|
+
);
|
|
135
|
+
},
|
|
136
|
+
} as const;
|
|
137
|
+
}
|
package/src/text.test.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { splitTextByLines } from './text.js';
|
|
4
|
+
|
|
5
|
+
describe('text', () => {
|
|
6
|
+
describe('splitTextByLines', () => {
|
|
7
|
+
const testCases: {
|
|
8
|
+
input: Parameters<typeof splitTextByLines>;
|
|
9
|
+
expected: ReturnType<typeof splitTextByLines>;
|
|
10
|
+
}[] = [
|
|
11
|
+
{
|
|
12
|
+
input: [
|
|
13
|
+
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi pariatur magnam excepturi nesciunt tempora deserunt? Pariatur sit quam, ducimus molestias quia aut maxime eligendi repudiandae expedita repellat, harum dignissimos aliquam.',
|
|
14
|
+
60,
|
|
15
|
+
],
|
|
16
|
+
expected: [
|
|
17
|
+
'Lorem ipsum dolor sit amet consectetur adipisicing elit.',
|
|
18
|
+
'Commodi pariatur magnam excepturi nesciunt tempora deserunt?',
|
|
19
|
+
'Pariatur sit quam, ducimus molestias quia aut maxime',
|
|
20
|
+
'eligendi repudiandae expedita repellat, harum dignissimos',
|
|
21
|
+
'aliquam.',
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
input: ['', 60],
|
|
26
|
+
expected: [''],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
input: [
|
|
30
|
+
'Supercalifragilisticexpialidocious is a long word that needs splitting',
|
|
31
|
+
20,
|
|
32
|
+
],
|
|
33
|
+
expected: [
|
|
34
|
+
'Supercalifragilistic',
|
|
35
|
+
'expialidocious',
|
|
36
|
+
'is a long word that',
|
|
37
|
+
'needs splitting',
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
input: [
|
|
42
|
+
' Multiple spaces and tabs\t\tbetween\twords ',
|
|
43
|
+
15,
|
|
44
|
+
],
|
|
45
|
+
expected: ['Multiple spaces', 'and tabs', 'between words'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
input: [
|
|
49
|
+
'Precise-length testing with exact match requirements for assessment',
|
|
50
|
+
20,
|
|
51
|
+
],
|
|
52
|
+
expected: [
|
|
53
|
+
'Precise-length',
|
|
54
|
+
'testing with exact',
|
|
55
|
+
'match requirements',
|
|
56
|
+
'for assessment',
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
input: [
|
|
61
|
+
`Special characters: @#$%^&*()_+={}[]|\\:";'<>?,./ and backticks \`code\` should work!`,
|
|
62
|
+
30,
|
|
63
|
+
],
|
|
64
|
+
expected: [
|
|
65
|
+
'Special characters:',
|
|
66
|
+
String.raw`@#$%^&*()_+={}[]|\:";'<>?,./`,
|
|
67
|
+
'and backticks `code` should',
|
|
68
|
+
'work!',
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
input: ['ThisIsACombinedWordThatExceedsLimit and normal words', 15],
|
|
73
|
+
expected: [
|
|
74
|
+
'ThisIsACombined',
|
|
75
|
+
'WordThatExceeds',
|
|
76
|
+
'Limit',
|
|
77
|
+
'and normal',
|
|
78
|
+
'words',
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
testCases.forEach((testCase, i) => {
|
|
84
|
+
test(`test case #${i + 1}`, () => {
|
|
85
|
+
expect(splitTextByLines(...testCase.input)).toStrictEqual(
|
|
86
|
+
testCase.expected,
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
package/src/text.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Склонение слова в зависимости от количества
|
|
3
|
+
* @example
|
|
4
|
+
* declension(1, ['слово', 'слова', 'слов']) // 'слово'
|
|
5
|
+
* @example
|
|
6
|
+
* declension(2, ['слово', 'слова', 'слов']) // 'слова'
|
|
7
|
+
* @example
|
|
8
|
+
* declension(5, ['слово', 'слова', 'слов']) // 'слов'
|
|
9
|
+
*/
|
|
10
|
+
export const declension = (
|
|
11
|
+
count: number,
|
|
12
|
+
txt: readonly [one: string, two: string, five: string],
|
|
13
|
+
cases = [2, 0, 1, 1, 1, 2],
|
|
14
|
+
) =>
|
|
15
|
+
txt[count % 100 > 4 && count % 100 < 20 ? 2 : cases[Math.min(count % 10, 5)]];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Разбиение текста на линии
|
|
19
|
+
*/
|
|
20
|
+
export const splitTextByLines = (
|
|
21
|
+
text: string,
|
|
22
|
+
lineLingth: number = 60,
|
|
23
|
+
): string[] => {
|
|
24
|
+
const words = text.split(/\s+/).filter((word) => word !== '');
|
|
25
|
+
const lines = [];
|
|
26
|
+
let currentLine = '';
|
|
27
|
+
|
|
28
|
+
for (const word of words) {
|
|
29
|
+
if (word.length > lineLingth) {
|
|
30
|
+
if (currentLine !== '') {
|
|
31
|
+
lines.push(currentLine);
|
|
32
|
+
currentLine = '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let start = 0;
|
|
36
|
+
while (start < word.length) {
|
|
37
|
+
const chunk = word.slice(start, start + lineLingth);
|
|
38
|
+
lines.push(chunk);
|
|
39
|
+
start += lineLingth;
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Проверка возможности добавления слова в текущую строку
|
|
45
|
+
if (currentLine === '') {
|
|
46
|
+
currentLine = word;
|
|
47
|
+
} else if (currentLine.length + 1 + word.length <= lineLingth) {
|
|
48
|
+
currentLine += ` ${word}`;
|
|
49
|
+
} else {
|
|
50
|
+
lines.push(currentLine);
|
|
51
|
+
currentLine = word;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (currentLine !== '' || lines.length === 0) {
|
|
56
|
+
lines.push(currentLine);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return lines;
|
|
60
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { AnyFunction, AnyObject } from '../utils/types.js';
|
|
2
|
+
|
|
3
|
+
enum Type {
|
|
4
|
+
Null = 'null',
|
|
5
|
+
Undefined = 'undefined',
|
|
6
|
+
NaN = 'nan',
|
|
7
|
+
Object = '[object Object]',
|
|
8
|
+
Array = '[object Array]',
|
|
9
|
+
String = '[object String]',
|
|
10
|
+
Number = '[object Number]',
|
|
11
|
+
Boolean = '[object Boolean]',
|
|
12
|
+
Function = '[object Function]',
|
|
13
|
+
RegExp = '[object RegExp]',
|
|
14
|
+
Symbol = '[object Symbol]',
|
|
15
|
+
Infinite = 'infinite',
|
|
16
|
+
Element = 'element',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getType(value: unknown): Type {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
return Type.Undefined;
|
|
22
|
+
}
|
|
23
|
+
if (value === null) {
|
|
24
|
+
return Type.Null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// handle DOM elements
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
if (value && (value.nodeType === 1 || value.nodeType === 9)) {
|
|
30
|
+
return Type.Element;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const stringifiedValue = Object.prototype.toString.call(value);
|
|
34
|
+
|
|
35
|
+
// handle NaN and Infinity
|
|
36
|
+
if (stringifiedValue === Type.Number) {
|
|
37
|
+
if (Number.isNaN(value as number)) {
|
|
38
|
+
return Type.NaN;
|
|
39
|
+
}
|
|
40
|
+
if (!Number.isFinite(value as number)) {
|
|
41
|
+
return Type.Infinite;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return stringifiedValue as Type;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const createTypeGuard =
|
|
49
|
+
<T>(type: Type) =>
|
|
50
|
+
(value: unknown): value is T =>
|
|
51
|
+
getType(value) === type;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if a value is not null or undefined
|
|
55
|
+
* @param value the value to check
|
|
56
|
+
* @returns boolean
|
|
57
|
+
*/
|
|
58
|
+
export const isDefined = <T>(value: T | undefined | null): value is T =>
|
|
59
|
+
value != null;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Check if a value is null
|
|
63
|
+
* @param value the value to check
|
|
64
|
+
* @returns boolean
|
|
65
|
+
*/
|
|
66
|
+
export const isNull = createTypeGuard<null>(Type.Null);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Check if a value is undefined
|
|
70
|
+
* @param value the value to check
|
|
71
|
+
* @returns boolean
|
|
72
|
+
*/
|
|
73
|
+
export const isUndefined = createTypeGuard<undefined>(Type.Undefined);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Check if a value is an object
|
|
77
|
+
* @param value the value to check
|
|
78
|
+
* @returns boolean
|
|
79
|
+
*/
|
|
80
|
+
export const isObject = createTypeGuard<AnyObject>(Type.Object);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Check if a value is an array
|
|
84
|
+
* @param value the value to check
|
|
85
|
+
* @returns boolean
|
|
86
|
+
*/
|
|
87
|
+
export const isArray = createTypeGuard<unknown[]>(Type.Array);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Check if a value is a string
|
|
91
|
+
* @param value the value to check
|
|
92
|
+
* @returns boolean
|
|
93
|
+
*/
|
|
94
|
+
export const isString = createTypeGuard<string>(Type.String);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Check if a value is a number
|
|
98
|
+
* @param value the value to check
|
|
99
|
+
* @returns boolean
|
|
100
|
+
*/
|
|
101
|
+
export const isNumber = createTypeGuard<number>(Type.Number);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Check if a value is a boolean
|
|
105
|
+
* @param value the value to check
|
|
106
|
+
* @returns boolean
|
|
107
|
+
*/
|
|
108
|
+
export const isBoolean = createTypeGuard<boolean>(Type.Boolean);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Check if a value is a function
|
|
112
|
+
* @param value the value to check
|
|
113
|
+
* @returns boolean
|
|
114
|
+
*/
|
|
115
|
+
export const isFunction = createTypeGuard<AnyFunction>(Type.Function);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Check if a value is a regular expression
|
|
119
|
+
* @param value the value to check
|
|
120
|
+
* @returns boolean
|
|
121
|
+
*/
|
|
122
|
+
export const isRegExp = createTypeGuard<RegExp>(Type.RegExp);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Check if a value is a DOM element
|
|
126
|
+
* @param value the value to check
|
|
127
|
+
* @returns boolean
|
|
128
|
+
*/
|
|
129
|
+
export const isElement = createTypeGuard<HTMLElement>(Type.Element);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Check if a value is NaN
|
|
133
|
+
* @param value the value to check
|
|
134
|
+
* @returns boolean
|
|
135
|
+
*/
|
|
136
|
+
export const isNaN = createTypeGuard<number>(Type.NaN) as (
|
|
137
|
+
value: unknown,
|
|
138
|
+
) => boolean;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Check if a value is infinity
|
|
142
|
+
* @param value the value to check
|
|
143
|
+
* @returns boolean
|
|
144
|
+
*/
|
|
145
|
+
export const isInfinite = createTypeGuard<number>(Type.Infinite) as (
|
|
146
|
+
value: unknown,
|
|
147
|
+
) => boolean;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Check if a value is a symbol
|
|
151
|
+
* @param value the value to check
|
|
152
|
+
* @returns boolean
|
|
153
|
+
*/
|
|
154
|
+
export const isSymbol = createTypeGuard<symbol>(Type.Symbol);
|