@splendidlabz/utils 1.11.3 → 1.11.5
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/dist/cjs/dom/accessibility.cjs +53 -0
- package/dist/cjs/dom/actions/index.cjs +410 -0
- package/dist/cjs/dom/actions/masonry.cjs +152 -0
- package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +157 -0
- package/dist/cjs/dom/actions/sticky.cjs +213 -0
- package/dist/cjs/dom/bounding-box.cjs +70 -0
- package/dist/cjs/dom/clipboard.cjs +37 -0
- package/dist/cjs/dom/cookie.cjs +57 -0
- package/dist/cjs/dom/css-vars.cjs +57 -0
- package/dist/cjs/dom/events.cjs +59 -0
- package/{src/dom/focusable.js → dist/cjs/dom/focusable.cjs} +51 -73
- package/dist/cjs/dom/font-size.cjs +80 -0
- package/dist/cjs/dom/get-element.cjs +98 -0
- package/dist/cjs/dom/hash.cjs +35 -0
- package/dist/cjs/dom/index.cjs +1267 -0
- package/dist/cjs/dom/keyboard.cjs +51 -0
- package/dist/cjs/dom/local-store.cjs +79 -0
- package/dist/cjs/dom/media.cjs +59 -0
- package/dist/cjs/dom/observers/index.cjs +253 -0
- package/dist/cjs/dom/observers/intersection-observer.cjs +91 -0
- package/dist/cjs/dom/observers/mutation-observer.cjs +95 -0
- package/dist/cjs/dom/observers/observer.cjs +48 -0
- package/dist/cjs/dom/observers/resize-observer.cjs +84 -0
- package/dist/cjs/dom/observers/scroll-observer.cjs +177 -0
- package/dist/cjs/dom/pkce.cjs +53 -0
- package/dist/cjs/dom/query-params.cjs +38 -0
- package/dist/cjs/dom/random-string.cjs +38 -0
- package/dist/cjs/dom/sanitize.cjs +65 -0
- package/dist/cjs/dom/session-store.cjs +49 -0
- package/dist/cjs/dom/spam-prevention.cjs +50 -0
- package/dist/cjs/dom/trap-focus.cjs +197 -0
- package/dist/cjs/dom/ui/aria-current.cjs +43 -0
- package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +35 -0
- package/dist/cjs/dom/ui/index.cjs +105 -0
- package/dist/cjs/dom/ui/scroll-container.cjs +47 -0
- package/dist/cjs/dom/ui/traverse-and-scramble.cjs +50 -0
- package/dist/cjs/lib/arrays/index.cjs +139 -0
- package/dist/cjs/lib/arrays/item-position.cjs +42 -0
- package/dist/cjs/lib/arrays/join.cjs +43 -0
- package/dist/cjs/lib/arrays/shuffle.cjs +42 -0
- package/dist/cjs/lib/arrays/sort.cjs +67 -0
- package/dist/cjs/lib/arrays/split-array.cjs +41 -0
- package/dist/cjs/lib/arrays/unique.cjs +31 -0
- package/dist/cjs/lib/auth/index.cjs +53 -0
- package/dist/cjs/lib/auth/route-manager.cjs +51 -0
- package/dist/cjs/lib/checks.cjs +63 -0
- package/dist/cjs/lib/date/days.cjs +37 -0
- package/dist/cjs/lib/date/index.cjs +208 -0
- package/dist/cjs/lib/date/months.cjs +102 -0
- package/dist/cjs/lib/date/time.cjs +117 -0
- package/dist/cjs/lib/form/form-data.cjs +83 -0
- package/dist/cjs/lib/form/index.cjs +122 -0
- package/dist/cjs/lib/form/sanitize.cjs +61 -0
- package/dist/cjs/lib/functions/callback.cjs +31 -0
- package/dist/cjs/lib/functions/debounce.cjs +43 -0
- package/dist/cjs/lib/functions/env.cjs +32 -0
- package/dist/cjs/lib/functions/functional.cjs +82 -0
- package/dist/cjs/lib/functions/index.cjs +142 -0
- package/dist/cjs/lib/functions/throttle.cjs +38 -0
- package/dist/cjs/lib/functions/timeout.cjs +41 -0
- package/dist/cjs/lib/hash.cjs +43 -0
- package/dist/cjs/lib/index.cjs +1178 -0
- package/dist/cjs/lib/numbers/index.cjs +49 -0
- package/dist/cjs/lib/numbers/math.cjs +36 -0
- package/dist/cjs/lib/objects/camelcase-keys.cjs +80 -0
- package/dist/cjs/lib/objects/empty.cjs +39 -0
- package/dist/cjs/lib/objects/equal.cjs +47 -0
- package/dist/cjs/lib/objects/extend.cjs +147 -0
- package/dist/cjs/lib/objects/flatten.cjs +48 -0
- package/dist/cjs/lib/objects/index.cjs +378 -0
- package/dist/cjs/lib/objects/json.cjs +35 -0
- package/dist/cjs/lib/objects/loop.cjs +40 -0
- package/dist/cjs/lib/objects/mix/mix.cjs +115 -0
- package/dist/cjs/lib/objects/nested-property.cjs +45 -0
- package/dist/cjs/lib/objects/normalize-object.cjs +106 -0
- package/dist/cjs/lib/objects/omit-empty.cjs +40 -0
- package/dist/cjs/lib/objects/size.cjs +63 -0
- package/dist/cjs/lib/objects/split.cjs +39 -0
- package/dist/cjs/lib/promises/index.cjs +69 -0
- package/dist/cjs/lib/promises/reject.cjs +67 -0
- package/dist/cjs/lib/sse.cjs +99 -0
- package/dist/cjs/lib/strings/convert-case/convert-case.cjs +96 -0
- package/dist/cjs/lib/strings/index.cjs +197 -0
- package/dist/cjs/lib/strings/markdown.cjs +76 -0
- package/dist/cjs/lib/strings/name.cjs +46 -0
- package/dist/cjs/lib/strings/pluralize.cjs +40 -0
- package/dist/cjs/lib/strings/query-string.cjs +43 -0
- package/dist/cjs/lib/style/index.cjs +64 -0
- package/dist/cjs/lib/symbols/index.cjs +40 -0
- package/dist/cjs/lib/symbols/symbols.cjs +38 -0
- package/dist/cjs/node/dirname.cjs +49 -0
- package/dist/cjs/node/file-cache.cjs +200 -0
- package/dist/cjs/node/file.cjs +50 -0
- package/dist/cjs/node/hash.cjs +42 -0
- package/dist/cjs/node/index.cjs +296 -0
- package/dist/cjs/node/pkce.cjs +64 -0
- package/dist/cjs/node/random-string.cjs +43 -0
- package/dist/cjs/node/sanitize.cjs +65 -0
- package/dist/cjs/node/uuid.cjs +42 -0
- package/dist/esm/dom/accessibility.js +26 -0
- package/dist/esm/dom/actions/index.js +3 -0
- package/dist/esm/dom/actions/masonry.js +38 -0
- package/dist/esm/dom/actions/prefer-horizontal-scroll.js +90 -0
- package/dist/esm/dom/actions/sticky.js +70 -0
- package/dist/esm/dom/bounding-box.js +44 -0
- package/dist/esm/dom/clipboard.js +12 -0
- package/dist/esm/dom/cookie.js +31 -0
- package/dist/esm/dom/css-vars.js +21 -0
- package/dist/esm/dom/events.js +31 -0
- package/dist/esm/dom/focusable.js +117 -0
- package/dist/esm/dom/font-size.js +40 -0
- package/dist/esm/dom/get-element.js +66 -0
- package/dist/esm/dom/hash.js +10 -0
- package/dist/esm/dom/index.js +23 -0
- package/dist/esm/dom/keyboard.js +22 -0
- package/{src → dist/esm}/dom/local-store.js +16 -28
- package/dist/esm/dom/media.js +32 -0
- package/dist/esm/dom/observers/index.js +4 -0
- package/dist/esm/dom/observers/intersection-observer.js +36 -0
- package/dist/esm/dom/observers/mutation-observer.js +40 -0
- package/dist/esm/dom/observers/observer.js +15 -0
- package/dist/esm/dom/observers/resize-observer.js +29 -0
- package/dist/esm/dom/observers/scroll-observer.js +95 -0
- package/dist/esm/dom/pkce.js +20 -0
- package/dist/esm/dom/query-params.js +13 -0
- package/dist/esm/dom/random-string.js +12 -0
- package/dist/esm/dom/sanitize.js +8 -0
- package/dist/esm/dom/session-store.js +24 -0
- package/dist/esm/dom/spam-prevention.js +25 -0
- package/dist/esm/dom/trap-focus.js +51 -0
- package/dist/esm/dom/ui/aria-current.js +17 -0
- package/dist/esm/dom/ui/inconsistent-button-fix.js +10 -0
- package/dist/esm/dom/ui/index.js +4 -0
- package/dist/esm/dom/ui/scroll-container.js +22 -0
- package/dist/esm/dom/ui/traverse-and-scramble.js +25 -0
- package/dist/esm/lib/arrays/index.js +6 -0
- package/dist/esm/lib/arrays/item-position.js +15 -0
- package/dist/esm/lib/arrays/join.js +12 -0
- package/dist/esm/lib/arrays/shuffle.js +17 -0
- package/dist/esm/lib/arrays/sort.js +36 -0
- package/dist/esm/lib/arrays/split-array.js +16 -0
- package/dist/esm/lib/arrays/unique.js +6 -0
- package/dist/esm/lib/auth/index.js +1 -0
- package/dist/esm/lib/auth/route-manager.js +25 -0
- package/dist/esm/lib/checks.js +34 -0
- package/dist/esm/lib/date/days.js +12 -0
- package/dist/esm/lib/date/index.js +3 -0
- package/dist/esm/lib/date/months.js +77 -0
- package/dist/esm/lib/date/time.js +75 -0
- package/dist/esm/lib/form/form-data.js +57 -0
- package/dist/esm/lib/form/index.js +2 -0
- package/dist/esm/lib/form/sanitize.js +34 -0
- package/dist/esm/lib/functions/callback.js +6 -0
- package/dist/esm/lib/functions/debounce.js +18 -0
- package/dist/esm/lib/functions/env.js +7 -0
- package/dist/esm/lib/functions/functional.js +52 -0
- package/dist/esm/lib/functions/index.js +5 -0
- package/dist/esm/lib/functions/throttle.js +13 -0
- package/dist/esm/lib/functions/timeout.js +14 -0
- package/dist/esm/lib/hash.js +18 -0
- package/dist/esm/lib/index.js +14 -0
- package/dist/esm/lib/numbers/index.js +11 -0
- package/dist/esm/lib/numbers/math.js +10 -0
- package/dist/esm/lib/objects/camelcase-keys.js +16 -0
- package/dist/esm/lib/objects/empty.js +13 -0
- package/dist/esm/lib/objects/equal.js +11 -0
- package/dist/esm/lib/objects/extend.js +13 -0
- package/dist/esm/lib/objects/flatten.js +17 -0
- package/dist/esm/lib/objects/index.js +13 -0
- package/dist/esm/lib/objects/json.js +10 -0
- package/dist/esm/lib/objects/loop.js +14 -0
- package/dist/esm/lib/objects/mix/mix.js +88 -0
- package/dist/esm/lib/objects/nested-property.js +18 -0
- package/dist/esm/lib/objects/normalize-object.js +9 -0
- package/dist/esm/lib/objects/omit-empty.js +15 -0
- package/dist/esm/lib/objects/size.js +38 -0
- package/dist/esm/lib/objects/split.js +14 -0
- package/dist/esm/lib/promises/index.js +1 -0
- package/dist/esm/lib/promises/reject.js +17 -0
- package/dist/esm/lib/sse.js +50 -0
- package/dist/esm/lib/strings/convert-case/convert-case.js +64 -0
- package/dist/esm/lib/strings/index.js +5 -0
- package/dist/esm/lib/strings/markdown.js +40 -0
- package/dist/esm/lib/strings/name.js +21 -0
- package/dist/esm/lib/strings/pluralize.js +5 -0
- package/dist/esm/lib/strings/query-string.js +16 -0
- package/dist/esm/lib/style/index.js +12 -0
- package/dist/esm/lib/symbols/index.js +1 -0
- package/dist/esm/lib/symbols/symbols.js +12 -0
- package/dist/esm/node/context.js +0 -0
- package/dist/esm/node/dirname.js +13 -0
- package/dist/esm/node/file-cache.js +121 -0
- package/dist/esm/node/file.js +14 -0
- package/dist/esm/node/hash.js +7 -0
- package/dist/esm/node/index.js +7 -0
- package/dist/esm/node/pkce.js +20 -0
- package/dist/esm/node/random-string.js +8 -0
- package/dist/esm/node/sanitize.js +8 -0
- package/dist/esm/node/uuid.js +7 -0
- package/dist/types/dom/accessibility.d.cts +30 -0
- package/dist/types/dom/actions/index.d.cts +3 -0
- package/dist/types/dom/actions/masonry.d.cts +5 -0
- package/dist/types/dom/actions/prefer-horizontal-scroll.d.cts +5 -0
- package/dist/types/dom/actions/sticky.d.cts +5 -0
- package/{src/dom/bounding-box.js → dist/types/dom/bounding-box.d.cts} +8 -49
- package/dist/types/dom/clipboard.d.cts +7 -0
- package/dist/types/dom/cookie.d.cts +7 -0
- package/dist/types/dom/css-vars.d.cts +6 -0
- package/{src/dom/events.js → dist/types/dom/events.d.cts} +52 -31
- package/dist/types/dom/focusable.d.cts +78 -0
- package/dist/types/dom/font-size.d.cts +8 -0
- package/{src/dom/get-element.js → dist/types/dom/get-element.d.cts} +25 -99
- package/dist/types/dom/hash.d.cts +3 -0
- package/dist/types/dom/index.d.cts +31 -0
- package/{src/dom/keyboard.js → dist/types/dom/keyboard.d.cts} +7 -19
- package/dist/types/dom/local-store.d.cts +31 -0
- package/dist/types/dom/media.d.cts +5 -0
- package/dist/types/dom/observers/index.d.cts +4 -0
- package/dist/types/dom/observers/intersection-observer.d.cts +10 -0
- package/dist/types/dom/observers/mutation-observer.d.cts +9 -0
- package/dist/types/dom/observers/observer.d.cts +3 -0
- package/{src/dom/observers/resize-observer.js → dist/types/dom/observers/resize-observer.d.cts} +6 -32
- package/dist/types/dom/observers/scroll-observer.d.cts +40 -0
- package/dist/types/dom/pkce.d.cts +8 -0
- package/dist/types/dom/query-params.d.cts +6 -0
- package/dist/types/dom/random-string.d.cts +9 -0
- package/dist/types/dom/sanitize.d.cts +10 -0
- package/dist/types/dom/session-store.d.cts +7 -0
- package/dist/types/dom/spam-prevention.d.cts +14 -0
- package/dist/types/dom/trap-focus.d.cts +32 -0
- package/dist/types/dom/ui/aria-current.d.cts +7 -0
- package/{src/dom/ui/inconsistent-button-fix.js → dist/types/dom/ui/inconsistent-button-fix.d.cts} +5 -11
- package/dist/types/dom/ui/index.d.cts +4 -0
- package/dist/types/dom/ui/scroll-container.d.cts +3 -0
- package/dist/types/dom/ui/traverse-and-scramble.d.cts +21 -0
- package/dist/types/lib/arrays/index.d.cts +6 -0
- package/{src/lib/arrays/item-position.js → dist/types/lib/arrays/item-position.d.cts} +5 -12
- package/{src/lib/arrays/join.js → dist/types/lib/arrays/join.d.cts} +4 -9
- package/dist/types/lib/arrays/shuffle.d.cts +3 -0
- package/dist/types/lib/arrays/sort.d.cts +32 -0
- package/dist/types/lib/arrays/split-array.d.cts +6 -0
- package/dist/types/lib/arrays/unique.d.cts +3 -0
- package/dist/types/lib/auth/index.d.cts +1 -0
- package/dist/types/lib/auth/route-manager.d.cts +28 -0
- package/dist/types/lib/checks.d.cts +33 -0
- package/dist/types/lib/date/days.d.cts +7 -0
- package/dist/types/lib/date/index.d.cts +3 -0
- package/dist/types/lib/date/months.d.cts +11 -0
- package/dist/types/lib/date/time.d.cts +21 -0
- package/dist/types/lib/form/form-data.d.cts +9 -0
- package/dist/types/lib/form/index.d.cts +2 -0
- package/{src/lib/form/sanitize.js → dist/types/lib/form/sanitize.d.cts} +19 -39
- package/{src/lib/functions/callback.js → dist/types/lib/functions/callback.d.cts} +3 -3
- package/dist/types/lib/functions/debounce.d.cts +3 -0
- package/dist/types/lib/functions/env.d.cts +3 -0
- package/{src/lib/functions/functional.js → dist/types/lib/functions/functional.d.cts} +8 -49
- package/dist/types/lib/functions/index.d.cts +5 -0
- package/dist/types/lib/functions/throttle.d.cts +3 -0
- package/dist/types/lib/functions/timeout.d.cts +5 -0
- package/dist/types/lib/hash.d.cts +3 -0
- package/dist/types/lib/index.d.cts +43 -0
- package/dist/types/lib/numbers/index.d.cts +5 -0
- package/dist/types/lib/numbers/math.d.cts +4 -0
- package/dist/types/lib/objects/camelcase-keys.d.cts +3 -0
- package/dist/types/lib/objects/empty.d.cts +4 -0
- package/dist/types/lib/objects/equal.d.cts +4 -0
- package/dist/types/lib/objects/extend.d.cts +6 -0
- package/dist/types/lib/objects/flatten.d.cts +6 -0
- package/dist/types/lib/objects/index.d.cts +13 -0
- package/dist/types/lib/objects/json.d.cts +3 -0
- package/dist/types/lib/objects/loop.d.cts +4 -0
- package/dist/types/lib/objects/mix/mix.d.cts +44 -0
- package/{src/lib/objects/nested-property.js → dist/types/lib/objects/nested-property.d.cts} +4 -21
- package/dist/types/lib/objects/normalize-object.d.cts +3 -0
- package/dist/types/lib/objects/omit-empty.d.cts +3 -0
- package/dist/types/lib/objects/size.d.cts +3 -0
- package/dist/types/lib/objects/split.d.cts +14 -0
- package/dist/types/lib/promises/index.d.cts +1 -0
- package/dist/types/lib/promises/reject.d.cts +5 -0
- package/dist/types/lib/sse.d.cts +18 -0
- package/dist/types/lib/strings/convert-case/convert-case.d.cts +10 -0
- package/dist/types/lib/strings/index.d.cts +5 -0
- package/dist/types/lib/strings/markdown.d.cts +25 -0
- package/dist/types/lib/strings/name.d.cts +7 -0
- package/dist/types/lib/strings/pluralize.d.cts +3 -0
- package/dist/types/lib/strings/query-string.d.cts +10 -0
- package/dist/types/lib/style/index.d.cts +3 -0
- package/dist/types/lib/symbols/index.d.cts +1 -0
- package/dist/types/lib/symbols/symbols.d.cts +4 -0
- package/dist/types/node/context.d.cts +2 -0
- package/dist/types/node/dirname.d.cts +9 -0
- package/dist/types/node/file-cache.d.cts +56 -0
- package/dist/types/node/file.d.cts +4 -0
- package/dist/types/node/hash.d.cts +3 -0
- package/dist/types/node/index.d.cts +7 -0
- package/dist/types/node/pkce.d.cts +14 -0
- package/dist/types/node/random-string.d.cts +3 -0
- package/{src/node/sanitize.js → dist/types/node/sanitize.d.cts} +3 -6
- package/dist/types/node/uuid.d.cts +3 -0
- package/package.json +18 -15
- package/CHANGELOG.md +0 -237
- package/eslint.config.js +0 -2
- package/src/dom/accessibility.js +0 -58
- package/src/dom/actions/index.js +0 -3
- package/src/dom/actions/masonry.js +0 -43
- package/src/dom/actions/prefer-horizontal-scroll.js +0 -121
- package/src/dom/actions/sticky.js +0 -85
- package/src/dom/clipboard.js +0 -14
- package/src/dom/cookie.js +0 -32
- package/src/dom/css-vars.js +0 -19
- package/src/dom/font-size.js +0 -40
- package/src/dom/hash.js +0 -9
- package/src/dom/index.js +0 -23
- package/src/dom/media.js +0 -30
- package/src/dom/observers/index.js +0 -4
- package/src/dom/observers/intersection-observer.js +0 -43
- package/src/dom/observers/mutation-observer.js +0 -51
- package/src/dom/observers/observer.js +0 -18
- package/src/dom/observers/scroll-observer.js +0 -146
- package/src/dom/pkce.js +0 -34
- package/src/dom/query-params.js +0 -14
- package/src/dom/random-string.js +0 -18
- package/src/dom/random-string.test.js +0 -13
- package/src/dom/sanitize.js +0 -16
- package/src/dom/session-store.js +0 -29
- package/src/dom/spam-prevention.js +0 -40
- package/src/dom/trap-focus.js +0 -70
- package/src/dom/ui/aria-current.js +0 -20
- package/src/dom/ui/index.js +0 -4
- package/src/dom/ui/scroll-container.js +0 -25
- package/src/dom/ui/traverse-and-scramble.js +0 -61
- package/src/lib/arrays/index.js +0 -6
- package/src/lib/arrays/shuffle.js +0 -21
- package/src/lib/arrays/sort.js +0 -88
- package/src/lib/arrays/sort.spec.js +0 -123
- package/src/lib/arrays/split-array.js +0 -15
- package/src/lib/arrays/unique.js +0 -3
- package/src/lib/auth/index.js +0 -1
- package/src/lib/auth/route-manager.js +0 -45
- package/src/lib/checks.js +0 -57
- package/src/lib/date/days.js +0 -9
- package/src/lib/date/index.js +0 -3
- package/src/lib/date/months.js +0 -74
- package/src/lib/date/time.js +0 -83
- package/src/lib/form/form-data.js +0 -73
- package/src/lib/form/index.js +0 -2
- package/src/lib/form/sanitize.spec.js +0 -126
- package/src/lib/functions/debounce.js +0 -18
- package/src/lib/functions/env.js +0 -5
- package/src/lib/functions/functional.test.js +0 -196
- package/src/lib/functions/index.js +0 -5
- package/src/lib/functions/throttle.js +0 -11
- package/src/lib/functions/timeout.js +0 -15
- package/src/lib/hash.js +0 -18
- package/src/lib/hash.spec.js +0 -163
- package/src/lib/index.js +0 -14
- package/src/lib/numbers/index.js +0 -12
- package/src/lib/numbers/math.js +0 -9
- package/src/lib/numbers/split-unit.test.js +0 -45
- package/src/lib/objects/camelcase-keys.js +0 -17
- package/src/lib/objects/camelcase-keys.test.js +0 -72
- package/src/lib/objects/empty.js +0 -10
- package/src/lib/objects/equal.js +0 -9
- package/src/lib/objects/extend.js +0 -16
- package/src/lib/objects/extend.test.js +0 -35
- package/src/lib/objects/flatten.js +0 -19
- package/src/lib/objects/index.js +0 -13
- package/src/lib/objects/json.js +0 -7
- package/src/lib/objects/loop.js +0 -11
- package/src/lib/objects/loop.test.js +0 -31
- package/src/lib/objects/mix/mix.js +0 -191
- package/src/lib/objects/mix/mix.md +0 -78
- package/src/lib/objects/mix/mix.test.js +0 -445
- package/src/lib/objects/normalize-object.js +0 -10
- package/src/lib/objects/omit-empty.js +0 -23
- package/src/lib/objects/omit-empty.test.js +0 -85
- package/src/lib/objects/size.js +0 -41
- package/src/lib/objects/split.js +0 -19
- package/src/lib/promises/index.js +0 -1
- package/src/lib/promises/reject.js +0 -17
- package/src/lib/sse.js +0 -61
- package/src/lib/strings/convert-case/convert-case.js +0 -86
- package/src/lib/strings/convert-case/convert-case.md +0 -44
- package/src/lib/strings/convert-case/convert-case.test.js +0 -50
- package/src/lib/strings/index.js +0 -5
- package/src/lib/strings/markdown.js +0 -71
- package/src/lib/strings/markdown.spec.js +0 -73
- package/src/lib/strings/name.js +0 -24
- package/src/lib/strings/name.test.js +0 -67
- package/src/lib/strings/pluralize.js +0 -2
- package/src/lib/strings/query-string.js +0 -18
- package/src/lib/style/index.js +0 -13
- package/src/lib/symbols/index.js +0 -1
- package/src/lib/symbols/symbols.js +0 -9
- package/src/node/dirname.js +0 -17
- package/src/node/file-cache.js +0 -184
- package/src/node/file.js +0 -13
- package/src/node/hash.js +0 -5
- package/src/node/index.js +0 -7
- package/src/node/pkce.js +0 -33
- package/src/node/random-string.js +0 -10
- package/src/node/random-string.test.js +0 -15
- package/src/node/sanitize.spec.js +0 -142
- package/src/node/uuid.js +0 -5
- package/tsconfig.json +0 -23
- package/tsup.config.js +0 -38
- package/tsup.config.mjs +0 -63
- /package/{src/node/context.js → dist/cjs/node/context.cjs} +0 -0
package/src/lib/checks.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a value is a plain object (not an array or null)
|
|
3
|
-
* @param {unknown} x - The value to check
|
|
4
|
-
* @returns {boolean} True if the value is a plain object
|
|
5
|
-
* @example
|
|
6
|
-
* isObject({}) // true
|
|
7
|
-
* isObject([]) // false
|
|
8
|
-
* isObject(null) // false
|
|
9
|
-
*/
|
|
10
|
-
export function isObject(x) {
|
|
11
|
-
return typeof x === 'object' && !Array.isArray(x) && x !== null
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a value is an array
|
|
16
|
-
* @param {unknown} x - The value to check
|
|
17
|
-
* @returns {boolean} True if the value is an array
|
|
18
|
-
* @example
|
|
19
|
-
* isArray([]) // true
|
|
20
|
-
* isArray({}) // false
|
|
21
|
-
*/
|
|
22
|
-
export function isArray(x) {
|
|
23
|
-
return Array.isArray(x)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Checks if a value is not a plain object
|
|
28
|
-
* @param {unknown} x - The value to check
|
|
29
|
-
* @returns {boolean} True if the value is not a plain object
|
|
30
|
-
* @example
|
|
31
|
-
* notObject([]) // true
|
|
32
|
-
* notObject(null) // true
|
|
33
|
-
* notObject({}) // false
|
|
34
|
-
*/
|
|
35
|
-
export function notObject(x) {
|
|
36
|
-
return !isObject(x)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function getType(x) {
|
|
40
|
-
if (typeof x === 'string') return 'string'
|
|
41
|
-
if (typeof x === 'number') {
|
|
42
|
-
if (Number.isInteger(x)) return 'integer'
|
|
43
|
-
return 'float'
|
|
44
|
-
}
|
|
45
|
-
if (typeof x === 'boolean') return 'boolean'
|
|
46
|
-
if (typeof x === 'function') return 'function'
|
|
47
|
-
if (typeof x === 'undefined') return 'undefined'
|
|
48
|
-
if (typeof x === 'symbol') return 'symbol'
|
|
49
|
-
if (typeof x === 'bigint') return 'bigint'
|
|
50
|
-
if (Array.isArray(x)) return 'array'
|
|
51
|
-
if (typeof x === 'object') return 'object'
|
|
52
|
-
return 'unknown'
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function isFunction(x) {
|
|
56
|
-
return typeof x === 'function'
|
|
57
|
-
}
|
package/src/lib/date/days.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const DAYS = [
|
|
2
|
-
{ short: 'Sun', long: 'Sunday', numeric: 1 },
|
|
3
|
-
{ short: 'Mon', long: 'Monday', numeric: 2 },
|
|
4
|
-
{ short: 'Tue', long: 'Tuesday', numeric: 3 },
|
|
5
|
-
{ short: 'Wed', long: 'Wednesday', numeric: 4 },
|
|
6
|
-
{ short: 'Thu', long: 'Thursday', numeric: 5 },
|
|
7
|
-
{ short: 'Fri', long: 'Friday', numeric: 6 },
|
|
8
|
-
{ short: 'Sat', long: 'Saturday', numeric: 7 },
|
|
9
|
-
]
|
package/src/lib/date/index.js
DELETED
package/src/lib/date/months.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
export const MONTHS = [
|
|
2
|
-
{
|
|
3
|
-
long: 'January',
|
|
4
|
-
short: 'jan',
|
|
5
|
-
numeric: 1,
|
|
6
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
long: 'February',
|
|
10
|
-
short: 'feb',
|
|
11
|
-
numeric: 2,
|
|
12
|
-
lastDay: { default: 28, leapYear: 29 },
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
long: 'March',
|
|
16
|
-
short: 'mar',
|
|
17
|
-
numeric: 3,
|
|
18
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
long: 'April',
|
|
22
|
-
short: 'apr',
|
|
23
|
-
numeric: 4,
|
|
24
|
-
lastDay: { default: 30, leapYear: 30 },
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
long: 'May',
|
|
28
|
-
short: 'may',
|
|
29
|
-
numeric: 5,
|
|
30
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
long: 'June',
|
|
34
|
-
short: 'jun',
|
|
35
|
-
numeric: 6,
|
|
36
|
-
lastDay: { default: 30, leapYear: 30 },
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
long: 'July',
|
|
40
|
-
short: 'jul',
|
|
41
|
-
numeric: 7,
|
|
42
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
long: 'August',
|
|
46
|
-
short: 'aug',
|
|
47
|
-
numeric: 8,
|
|
48
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
long: 'September',
|
|
52
|
-
short: 'sep',
|
|
53
|
-
numeric: 9,
|
|
54
|
-
lastDay: { default: 30, leapYear: 30 },
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
long: 'October',
|
|
58
|
-
short: 'oct',
|
|
59
|
-
numeric: 10,
|
|
60
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
long: 'November',
|
|
64
|
-
short: 'nov',
|
|
65
|
-
numeric: 11,
|
|
66
|
-
lastDay: { default: 30, leapYear: 30 },
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
long: 'December',
|
|
70
|
-
short: 'dec',
|
|
71
|
-
numeric: 12,
|
|
72
|
-
lastDay: { default: 31, leapYear: 31 },
|
|
73
|
-
},
|
|
74
|
-
]
|
package/src/lib/date/time.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { splitUnit } from '../numbers/index.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Convert a time string to milliseconds
|
|
5
|
-
* @param {string} arg - The time string to convert
|
|
6
|
-
* @returns {number}
|
|
7
|
-
*/
|
|
8
|
-
export function ms(arg) {
|
|
9
|
-
const [value, unit] = splitUnit(arg)
|
|
10
|
-
if (unit === 'd') return getTimeInMs(value, 'days')
|
|
11
|
-
if (unit === 'day') return getTimeInMs(value, 'days')
|
|
12
|
-
if (unit === 'days') return getTimeInMs(value, 'days')
|
|
13
|
-
if (unit === 'h') return getTimeInMs(value, 'hours')
|
|
14
|
-
if (unit === 'hr') return getTimeInMs(value, 'hours')
|
|
15
|
-
if (unit === 'hour') return getTimeInMs(value, 'hours')
|
|
16
|
-
if (unit === 'hours') return getTimeInMs(value, 'hours')
|
|
17
|
-
if (unit === 'm') return getTimeInMs(value, 'minutes')
|
|
18
|
-
if (unit === 'min') return getTimeInMs(value, 'minutes')
|
|
19
|
-
if (unit === 'mins') return getTimeInMs(value, 'minutes')
|
|
20
|
-
if (unit === 'minute') return getTimeInMs(value, 'minutes')
|
|
21
|
-
if (unit === 'minutes') return getTimeInMs(value, 'minutes')
|
|
22
|
-
if (unit === 's') return getTimeInMs(value, 'seconds')
|
|
23
|
-
if (unit === 'sec') return getTimeInMs(value, 'seconds')
|
|
24
|
-
if (unit === 'secs') return getTimeInMs(value, 'seconds')
|
|
25
|
-
if (unit === 'second') return getTimeInMs(value, 'seconds')
|
|
26
|
-
if (unit === 'seconds') return getTimeInMs(value, 'seconds')
|
|
27
|
-
|
|
28
|
-
// The rest are for milliseconds
|
|
29
|
-
return value
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getTimeInMs(value, unit = 'ms') {
|
|
33
|
-
switch (unit) {
|
|
34
|
-
case 'ms':
|
|
35
|
-
return value
|
|
36
|
-
case 'seconds':
|
|
37
|
-
return value * 1000
|
|
38
|
-
case 'minutes':
|
|
39
|
-
return value * 1000 * 60
|
|
40
|
-
case 'hours':
|
|
41
|
-
return value * 1000 * 60 * 60
|
|
42
|
-
case 'days':
|
|
43
|
-
return value * 1000 * 60 * 60 * 24
|
|
44
|
-
case 'weeks':
|
|
45
|
-
return value * 1000 * 60 * 60 * 24 * 7
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function toWeeks(ms) {
|
|
50
|
-
return ms / 1000 / 60 / 60 / 24 / 7
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function toDays(ms) {
|
|
54
|
-
return ms / 1000 / 60 / 60 / 24
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function toHours(ms) {
|
|
58
|
-
return ms / 1000 / 60 / 60
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function toMinutes(ms) {
|
|
62
|
-
return ms / 1000 / 60
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function toSeconds(ms) {
|
|
66
|
-
return ms / 1000
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Get the total number of weeks, days, hours, minutes, and seconds
|
|
70
|
-
export function toReadableTime(ms) {
|
|
71
|
-
const weekMs = 1000 * 60 * 60 * 24 * 7
|
|
72
|
-
const dayMs = 1000 * 60 * 60 * 24
|
|
73
|
-
const hourMs = 1000 * 60 * 60
|
|
74
|
-
const minuteMs = 1000 * 60
|
|
75
|
-
|
|
76
|
-
const weeks = Math.floor(ms / weekMs)
|
|
77
|
-
const days = Math.floor((ms % weekMs) / dayMs)
|
|
78
|
-
const hours = Math.floor((ms % dayMs) / hourMs)
|
|
79
|
-
const minutes = Math.floor((ms % hourMs) / minuteMs)
|
|
80
|
-
const seconds = Math.floor((ms % minuteMs) / 1000)
|
|
81
|
-
|
|
82
|
-
return { weeks, days, hours, minutes, seconds }
|
|
83
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts Form Data into an object
|
|
3
|
-
* @param {FormData} formData
|
|
4
|
-
* @returns Object
|
|
5
|
-
*/
|
|
6
|
-
export function formDataToObject(formData) {
|
|
7
|
-
const obj = {}
|
|
8
|
-
for (let [key, value] of formData) {
|
|
9
|
-
if (typeof value === 'string') value = value.trim()
|
|
10
|
-
|
|
11
|
-
if (key.includes('[]')) {
|
|
12
|
-
// Handle array fields
|
|
13
|
-
const arrayKey = key.replace('[]', '')
|
|
14
|
-
if (!obj[arrayKey]) obj[arrayKey] = []
|
|
15
|
-
obj[arrayKey].push(value)
|
|
16
|
-
} else {
|
|
17
|
-
// Handle normal string fields
|
|
18
|
-
obj[key] = value
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return obj
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function flattenArrayFields(inputObject) {
|
|
25
|
-
const result = {}
|
|
26
|
-
|
|
27
|
-
for (const [key, value] of Object.entries(inputObject)) {
|
|
28
|
-
// Regex to match keys that follow pattern: arrayName[index][property]
|
|
29
|
-
const match = key.match(/^(\w+)(?:\[(\d+)\])?(?:\[(\w+)\])?$/)
|
|
30
|
-
if (match) {
|
|
31
|
-
const [, baseKey, index, property] = match
|
|
32
|
-
|
|
33
|
-
if (index !== undefined) {
|
|
34
|
-
// Handle array of objects
|
|
35
|
-
if (!result[baseKey]) result[baseKey] = []
|
|
36
|
-
const arrayIndex = parseInt(index)
|
|
37
|
-
if (!result[baseKey][arrayIndex]) result[baseKey][arrayIndex] = {}
|
|
38
|
-
if (property) {
|
|
39
|
-
result[baseKey][arrayIndex][property] = value
|
|
40
|
-
} else {
|
|
41
|
-
result[baseKey][arrayIndex] = value
|
|
42
|
-
}
|
|
43
|
-
} else if (property) {
|
|
44
|
-
// Handle single object
|
|
45
|
-
if (!result[baseKey]) result[baseKey] = {}
|
|
46
|
-
result[baseKey][property] = value
|
|
47
|
-
} else {
|
|
48
|
-
// Handle simple key-value
|
|
49
|
-
result[key] = value
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
// Copy key-value pair for unmatched keys
|
|
53
|
-
result[key] = value
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Remove empty objects from arrays and convert array-like objects to actual arrays
|
|
58
|
-
for (const key in result) {
|
|
59
|
-
if (typeof result[key] === 'object' && result[key] !== null) {
|
|
60
|
-
if (Object.keys(result[key]).every(k => !isNaN(parseInt(k)))) {
|
|
61
|
-
// Convert to array and filter out empty items
|
|
62
|
-
result[key] = Object.values(result[key]).filter(item => {
|
|
63
|
-
if (typeof item === 'object') {
|
|
64
|
-
return Object.values(item).some(v => v !== '')
|
|
65
|
-
}
|
|
66
|
-
return item !== ''
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return result
|
|
73
|
-
}
|
package/src/lib/form/index.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import sanitizeHtml from 'sanitize-html'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { sanitize } from './sanitize.js'
|
|
4
|
-
|
|
5
|
-
// Real sanitizer using sanitize-html
|
|
6
|
-
function mockSanitizer(value, options = {}) {
|
|
7
|
-
if (typeof value !== 'string') return value
|
|
8
|
-
return sanitizeHtml(value, {
|
|
9
|
-
allowedTags: ['b', 'i', 'em', 'strong', 'a'],
|
|
10
|
-
allowedAttributes: {
|
|
11
|
-
a: ['href'],
|
|
12
|
-
},
|
|
13
|
-
...options,
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('sanitize', () => {
|
|
18
|
-
it('sanitizes HTML in string values', () => {
|
|
19
|
-
const input = {
|
|
20
|
-
name: '<script>alert("xss")</script>John',
|
|
21
|
-
bio: '<p>Hello <b>World</b> <script>alert("xss")</script></p>',
|
|
22
|
-
link: '<a href="javascript:alert(1)">Click me</a>',
|
|
23
|
-
safeLink: '<a href="https://example.com">Safe link</a>',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const expected = {
|
|
27
|
-
name: 'John',
|
|
28
|
-
bio: 'Hello <b>World</b> ',
|
|
29
|
-
link: '<a>Click me</a>',
|
|
30
|
-
safeLink: '<a href="https://example.com">Safe link</a>',
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
expect(sanitize(input, { sanitizer: mockSanitizer })).toEqual(expected)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('sanitizes nested objects with HTML', () => {
|
|
37
|
-
const input = {
|
|
38
|
-
user: {
|
|
39
|
-
name: '<script>alert("xss")</script>John',
|
|
40
|
-
profile: {
|
|
41
|
-
bio: '<p>Hello <b>World</b></p>',
|
|
42
|
-
links: [
|
|
43
|
-
'<a href="javascript:alert(1)">Bad</a>',
|
|
44
|
-
'<a href="https://good.com">Good</a>',
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const expected = {
|
|
51
|
-
user: {
|
|
52
|
-
name: 'John',
|
|
53
|
-
profile: {
|
|
54
|
-
bio: 'Hello <b>World</b>',
|
|
55
|
-
links: ['<a>Bad</a>', '<a href="https://good.com">Good</a>'],
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
expect(sanitize(input, { sanitizer: mockSanitizer })).toEqual(expected)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('preserves non-string values and sanitizes arrays correctly', () => {
|
|
64
|
-
const input = {
|
|
65
|
-
name: '<script>alert("xss")</script>John',
|
|
66
|
-
age: 25,
|
|
67
|
-
active: true,
|
|
68
|
-
email: null,
|
|
69
|
-
role: undefined,
|
|
70
|
-
tags: ['<script>alert(1)</script>admin', 'user'],
|
|
71
|
-
numbers: [1, 2, 3],
|
|
72
|
-
mixed: ['<b>bold</b>', 42, null, '<script>alert(1)</script>text'],
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const expected = {
|
|
76
|
-
name: 'John',
|
|
77
|
-
age: 25,
|
|
78
|
-
active: true,
|
|
79
|
-
email: null,
|
|
80
|
-
role: undefined,
|
|
81
|
-
tags: ['admin', 'user'],
|
|
82
|
-
numbers: [1, 2, 3],
|
|
83
|
-
mixed: ['<b>bold</b>', 42, null, 'text'],
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
expect(sanitize(input, { sanitizer: mockSanitizer })).toEqual(expected)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('throws error when sanitizer is not provided', () => {
|
|
90
|
-
const input = { name: '<script>alert(1)</script>John' }
|
|
91
|
-
expect(() => sanitize(input)).toThrow('sanitizer function is required')
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('allows custom sanitizer options', () => {
|
|
95
|
-
const input = {
|
|
96
|
-
content: '<p>Hello <span>World</span> <script>alert(1)</script></p>',
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const defaultOptions = {
|
|
100
|
-
allowedTags: ['b', 'i', 'em', 'strong', 'a'],
|
|
101
|
-
allowedAttributes: {
|
|
102
|
-
a: ['href'],
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Test with custom allowed tags
|
|
107
|
-
const withSpan = sanitize(input, {
|
|
108
|
-
sanitizer: v =>
|
|
109
|
-
mockSanitizer(v, {
|
|
110
|
-
...defaultOptions,
|
|
111
|
-
allowedTags: [...defaultOptions.allowedTags, 'span'],
|
|
112
|
-
}),
|
|
113
|
-
})
|
|
114
|
-
expect(withSpan.content).toBe('Hello <span>World</span> ')
|
|
115
|
-
|
|
116
|
-
// Test with no allowed tags
|
|
117
|
-
const noTags = sanitize(input, {
|
|
118
|
-
sanitizer: v =>
|
|
119
|
-
mockSanitizer(v, {
|
|
120
|
-
...defaultOptions,
|
|
121
|
-
allowedTags: [],
|
|
122
|
-
}),
|
|
123
|
-
})
|
|
124
|
-
expect(noTags.content).toBe('Hello World ')
|
|
125
|
-
})
|
|
126
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export function debounce(callback, wait, immediate = false) {
|
|
2
|
-
let timeout
|
|
3
|
-
|
|
4
|
-
return function () {
|
|
5
|
-
const context = this
|
|
6
|
-
const args = arguments
|
|
7
|
-
|
|
8
|
-
const callNow = immediate && !timeout
|
|
9
|
-
clearTimeout(timeout)
|
|
10
|
-
timeout = setTimeout(later, wait)
|
|
11
|
-
if (callNow) callback.apply(context, args)
|
|
12
|
-
|
|
13
|
-
function later() {
|
|
14
|
-
timeout = null
|
|
15
|
-
if (!immediate) callback.apply(context, args)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/lib/functions/env.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
compose,
|
|
4
|
-
composeAsync,
|
|
5
|
-
curry,
|
|
6
|
-
pipe,
|
|
7
|
-
pipeAsync,
|
|
8
|
-
times,
|
|
9
|
-
} from './functional.js'
|
|
10
|
-
|
|
11
|
-
describe('functional utilities', () => {
|
|
12
|
-
describe('curry', () => {
|
|
13
|
-
it('should curry a function with multiple arguments', () => {
|
|
14
|
-
const add = (a, b, c) => a + b + c
|
|
15
|
-
const curriedAdd = curry(add)
|
|
16
|
-
|
|
17
|
-
expect(curriedAdd(1)(2)(3)).toBe(6)
|
|
18
|
-
expect(curriedAdd(1, 2)(3)).toBe(6)
|
|
19
|
-
expect(curriedAdd(1)(2, 3)).toBe(6)
|
|
20
|
-
expect(curriedAdd(1, 2, 3)).toBe(6)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe('compose (sync)', () => {
|
|
25
|
-
it('should compose functions from right to left', () => {
|
|
26
|
-
const add1 = x => x + 1
|
|
27
|
-
const multiply2 = x => x * 2
|
|
28
|
-
const composed = compose(add1, multiply2)
|
|
29
|
-
|
|
30
|
-
expect(composed(3)).toBe(7) // (3 * 2) + 1
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should work with single function', () => {
|
|
34
|
-
const add1 = x => x + 1
|
|
35
|
-
const composed = compose(add1)
|
|
36
|
-
|
|
37
|
-
expect(composed(5)).toBe(6)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('should work with multiple functions', () => {
|
|
41
|
-
const add1 = x => x + 1
|
|
42
|
-
const multiply2 = x => x * 2
|
|
43
|
-
const subtract3 = x => x - 3
|
|
44
|
-
const composed = compose(subtract3, add1, multiply2)
|
|
45
|
-
|
|
46
|
-
expect(composed(5)).toBe(8) // ((5 * 2) + 1) - 3 = 8
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
describe('composeAsync', () => {
|
|
51
|
-
it('should compose async functions from right to left', async () => {
|
|
52
|
-
const add1 = x => x + 1
|
|
53
|
-
const multiplyAsync = async x => x * 2
|
|
54
|
-
|
|
55
|
-
const result = await composeAsync(add1, multiplyAsync)(3)
|
|
56
|
-
expect(result).toBe(7) // (3 * 2) + 1
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should work with all sync functions', async () => {
|
|
60
|
-
const add1 = x => x + 1
|
|
61
|
-
const multiply2 = x => x * 2
|
|
62
|
-
|
|
63
|
-
const result = await composeAsync(add1, multiply2)(3)
|
|
64
|
-
expect(result).toBe(7) // (3 * 2) + 1
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should work with all async functions', async () => {
|
|
68
|
-
const add1Async = async x => x + 1
|
|
69
|
-
const multiply2Async = async x => x * 2
|
|
70
|
-
|
|
71
|
-
const result = await composeAsync(add1Async, multiply2Async)(3)
|
|
72
|
-
expect(result).toBe(7) // (3 * 2) + 1
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should work with mixed sync and async functions', async () => {
|
|
76
|
-
const add1 = x => x + 1
|
|
77
|
-
const multiply2Async = async x => x * 2
|
|
78
|
-
const subtract3 = x => x - 3
|
|
79
|
-
|
|
80
|
-
const result = await composeAsync(subtract3, add1, multiply2Async)(5)
|
|
81
|
-
expect(result).toBe(8) // ((5 * 2) + 1) - 3 = 8
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
describe('pipe (sync)', () => {
|
|
86
|
-
it('should pipe functions from left to right', () => {
|
|
87
|
-
const add1 = x => x + 1
|
|
88
|
-
const multiply2 = x => x * 2
|
|
89
|
-
const piped = pipe(add1, multiply2)
|
|
90
|
-
|
|
91
|
-
expect(piped(3)).toBe(8) // (3 + 1) * 2
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should work with single function', () => {
|
|
95
|
-
const add1 = x => x + 1
|
|
96
|
-
const piped = pipe(add1)
|
|
97
|
-
|
|
98
|
-
expect(piped(5)).toBe(6)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('should work with multiple functions', () => {
|
|
102
|
-
const add1 = x => x + 1
|
|
103
|
-
const multiply2 = x => x * 2
|
|
104
|
-
const subtract3 = x => x - 3
|
|
105
|
-
const piped = pipe(add1, multiply2, subtract3)
|
|
106
|
-
|
|
107
|
-
expect(piped(5)).toBe(9) // ((5 + 1) * 2) - 3 = 9
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
describe('pipeAsync', () => {
|
|
112
|
-
it('should pipe async functions from left to right', async () => {
|
|
113
|
-
const add1 = x => x + 1
|
|
114
|
-
const multiplyAsync = async x => x * 2
|
|
115
|
-
|
|
116
|
-
const result = await pipeAsync(add1, multiplyAsync)(3)
|
|
117
|
-
expect(result).toBe(8) // (3 + 1) * 2
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('should work with all sync functions', async () => {
|
|
121
|
-
const add1 = x => x + 1
|
|
122
|
-
const multiply2 = x => x * 2
|
|
123
|
-
|
|
124
|
-
const result = await pipeAsync(add1, multiply2)(3)
|
|
125
|
-
expect(result).toBe(8) // (3 + 1) * 2
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('should work with all async functions', async () => {
|
|
129
|
-
const add1Async = async x => x + 1
|
|
130
|
-
const multiply2Async = async x => x * 2
|
|
131
|
-
|
|
132
|
-
const result = await pipeAsync(add1Async, multiply2Async)(3)
|
|
133
|
-
expect(result).toBe(8) // (3 + 1) * 2
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('should work with mixed sync and async functions', async () => {
|
|
137
|
-
const add1 = x => x + 1
|
|
138
|
-
const multiply2Async = async x => x * 2
|
|
139
|
-
const subtract3 = x => x - 3
|
|
140
|
-
|
|
141
|
-
const result = await pipeAsync(add1, multiply2Async, subtract3)(5)
|
|
142
|
-
expect(result).toBe(9) // ((5 + 1) * 2) - 3 = 9
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('should handle promises in the pipeline', async () => {
|
|
146
|
-
const asyncAdd = async x => {
|
|
147
|
-
await new Promise(resolve => setTimeout(resolve, 1))
|
|
148
|
-
return x + 1
|
|
149
|
-
}
|
|
150
|
-
const multiply2 = x => x * 2
|
|
151
|
-
|
|
152
|
-
const result = await pipeAsync(asyncAdd, multiply2)(3)
|
|
153
|
-
expect(result).toBe(8) // (3 + 1) * 2
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
describe('times', () => {
|
|
158
|
-
it('should call function n times with index', () => {
|
|
159
|
-
const result = times(i => i * 2, 3)
|
|
160
|
-
expect(result).toEqual([0, 2, 4])
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('should work with zero iterations', () => {
|
|
164
|
-
const result = times(i => i, 0)
|
|
165
|
-
expect(result).toEqual([])
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('should work with functions that ignore index', () => {
|
|
169
|
-
const result = times(() => 'hello', 2)
|
|
170
|
-
expect(result).toEqual(['hello', 'hello'])
|
|
171
|
-
})
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
// Edge cases and error handling
|
|
175
|
-
describe('edge cases', () => {
|
|
176
|
-
it('should handle empty function arrays in compose', () => {
|
|
177
|
-
const composed = compose()
|
|
178
|
-
expect(composed(5)).toBe(5)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('should handle empty function arrays in pipe', () => {
|
|
182
|
-
const piped = pipe()
|
|
183
|
-
expect(piped(5)).toBe(5)
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('should handle empty function arrays in composeAsync', async () => {
|
|
187
|
-
const result = await composeAsync()(5)
|
|
188
|
-
expect(result).toBe(5)
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
it('should handle empty function arrays in pipeAsync', async () => {
|
|
192
|
-
const result = await pipeAsync()(5)
|
|
193
|
-
expect(result).toBe(5)
|
|
194
|
-
})
|
|
195
|
-
})
|
|
196
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// setTimeout for task ticking
|
|
2
|
-
// reverses wait and callback functions of timeouts because it makes more sense when reading the code
|
|
3
|
-
export function timeout(wait, callback) {
|
|
4
|
-
setTimeout(callback, wait)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// Promise based timeouts for microtask ticking
|
|
8
|
-
export function delay(ms) {
|
|
9
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Alias of delay
|
|
13
|
-
export function wait(ms) {
|
|
14
|
-
return delay(ms)
|
|
15
|
-
}
|