@splendidlabz/utils 1.11.2 → 1.11.4

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.
Files changed (228) hide show
  1. package/dist/cjs/dom/accessibility.cjs +2 -0
  2. package/dist/cjs/dom/actions/index.cjs +392 -7
  3. package/dist/cjs/dom/actions/masonry.cjs +97 -6
  4. package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +58 -14
  5. package/dist/cjs/dom/actions/sticky.cjs +126 -6
  6. package/dist/cjs/dom/bounding-box.cjs +2 -0
  7. package/dist/cjs/dom/clipboard.cjs +2 -0
  8. package/dist/cjs/dom/cookie.cjs +3 -1
  9. package/dist/cjs/dom/css-vars.cjs +13 -3
  10. package/dist/cjs/dom/events.cjs +2 -0
  11. package/dist/cjs/dom/focusable.cjs +2 -0
  12. package/dist/cjs/dom/font-size.cjs +15 -3
  13. package/dist/cjs/dom/get-element.cjs +3 -1
  14. package/dist/cjs/dom/hash.cjs +2 -0
  15. package/dist/cjs/dom/index.cjs +1249 -47
  16. package/dist/cjs/dom/keyboard.cjs +2 -0
  17. package/dist/cjs/dom/local-store.cjs +3 -1
  18. package/dist/cjs/dom/media.cjs +2 -0
  19. package/dist/cjs/dom/observers/index.cjs +235 -9
  20. package/dist/cjs/dom/observers/intersection-observer.cjs +38 -6
  21. package/dist/cjs/dom/observers/mutation-observer.cjs +38 -6
  22. package/dist/cjs/dom/observers/observer.cjs +12 -2
  23. package/dist/cjs/dom/observers/resize-observer.cjs +38 -6
  24. package/dist/cjs/dom/observers/scroll-observer.cjs +62 -3
  25. package/dist/cjs/dom/pkce.cjs +13 -3
  26. package/dist/cjs/dom/query-params.cjs +3 -1
  27. package/dist/cjs/dom/random-string.cjs +2 -0
  28. package/dist/cjs/dom/sanitize.cjs +27 -3
  29. package/dist/cjs/dom/session-store.cjs +3 -1
  30. package/dist/cjs/dom/spam-prevention.cjs +2 -0
  31. package/dist/cjs/dom/trap-focus.cjs +131 -9
  32. package/dist/cjs/dom/ui/aria-current.cjs +2 -0
  33. package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +2 -0
  34. package/dist/cjs/dom/ui/index.cjs +87 -9
  35. package/dist/cjs/dom/ui/scroll-container.cjs +2 -0
  36. package/dist/cjs/dom/ui/traverse-and-scramble.cjs +2 -0
  37. package/dist/cjs/lib/arrays/index.cjs +121 -13
  38. package/dist/cjs/lib/arrays/item-position.cjs +2 -0
  39. package/dist/cjs/lib/arrays/join.cjs +10 -2
  40. package/dist/cjs/lib/arrays/shuffle.cjs +2 -0
  41. package/dist/cjs/lib/arrays/sort.cjs +11 -3
  42. package/dist/cjs/lib/arrays/split-array.cjs +2 -0
  43. package/dist/cjs/lib/arrays/unique.cjs +2 -0
  44. package/dist/cjs/lib/auth/index.cjs +35 -3
  45. package/dist/cjs/lib/auth/route-manager.cjs +2 -0
  46. package/dist/cjs/lib/checks.cjs +2 -0
  47. package/dist/cjs/lib/date/days.cjs +3 -1
  48. package/dist/cjs/lib/date/index.cjs +190 -7
  49. package/dist/cjs/lib/date/months.cjs +3 -1
  50. package/dist/cjs/lib/date/time.cjs +14 -2
  51. package/dist/cjs/lib/form/form-data.cjs +2 -0
  52. package/dist/cjs/lib/form/index.cjs +104 -5
  53. package/dist/cjs/lib/form/sanitize.cjs +2 -0
  54. package/dist/cjs/lib/functions/callback.cjs +2 -0
  55. package/dist/cjs/lib/functions/debounce.cjs +2 -0
  56. package/dist/cjs/lib/functions/env.cjs +2 -0
  57. package/dist/cjs/lib/functions/functional.cjs +2 -0
  58. package/dist/cjs/lib/functions/index.cjs +124 -11
  59. package/dist/cjs/lib/functions/throttle.cjs +2 -0
  60. package/dist/cjs/lib/functions/timeout.cjs +2 -0
  61. package/dist/cjs/lib/hash.cjs +2 -0
  62. package/dist/cjs/lib/index.cjs +1160 -29
  63. package/dist/cjs/lib/numbers/index.cjs +17 -4
  64. package/dist/cjs/lib/numbers/math.cjs +2 -0
  65. package/dist/cjs/lib/objects/camelcase-keys.cjs +45 -4
  66. package/dist/cjs/lib/objects/empty.cjs +2 -0
  67. package/dist/cjs/lib/objects/equal.cjs +2 -0
  68. package/dist/cjs/lib/objects/extend.cjs +117 -6
  69. package/dist/cjs/lib/objects/flatten.cjs +11 -3
  70. package/dist/cjs/lib/objects/index.cjs +360 -27
  71. package/dist/cjs/lib/objects/json.cjs +2 -0
  72. package/dist/cjs/lib/objects/loop.cjs +2 -0
  73. package/dist/cjs/lib/objects/mix/mix.cjs +5 -3
  74. package/dist/cjs/lib/objects/nested-property.cjs +2 -0
  75. package/dist/cjs/lib/objects/normalize-object.cjs +78 -4
  76. package/dist/cjs/lib/objects/omit-empty.cjs +2 -0
  77. package/dist/cjs/lib/objects/size.cjs +2 -0
  78. package/dist/cjs/lib/objects/split.cjs +2 -0
  79. package/dist/cjs/lib/promises/index.cjs +51 -3
  80. package/dist/cjs/lib/promises/reject.cjs +19 -2
  81. package/dist/cjs/lib/sse.cjs +29 -4
  82. package/dist/cjs/lib/strings/convert-case/convert-case.cjs +2 -0
  83. package/dist/cjs/lib/strings/index.cjs +179 -11
  84. package/dist/cjs/lib/strings/markdown.cjs +3 -1
  85. package/dist/cjs/lib/strings/name.cjs +2 -0
  86. package/dist/cjs/lib/strings/pluralize.cjs +3 -1
  87. package/dist/cjs/lib/strings/query-string.cjs +2 -0
  88. package/dist/cjs/lib/style/index.cjs +31 -2
  89. package/dist/cjs/lib/symbols/index.cjs +22 -3
  90. package/dist/cjs/lib/symbols/symbols.cjs +2 -0
  91. package/dist/cjs/node/context.cjs +0 -0
  92. package/dist/cjs/node/dirname.cjs +4 -2
  93. package/dist/cjs/node/file-cache.cjs +45 -3
  94. package/dist/cjs/node/file.cjs +4 -2
  95. package/dist/cjs/node/hash.cjs +3 -1
  96. package/dist/cjs/node/index.cjs +278 -15
  97. package/dist/cjs/node/pkce.cjs +20 -8
  98. package/dist/cjs/node/random-string.cjs +3 -1
  99. package/dist/cjs/node/sanitize.cjs +27 -3
  100. package/dist/cjs/node/uuid.cjs +2 -0
  101. package/dist/esm/node/context.js +0 -0
  102. package/dist/esm/node/file-cache.js +1 -1
  103. package/dist/esm/node/pkce.js +3 -2
  104. package/dist/types/node/context.d.cts +2 -0
  105. package/dist/types/node/index.d.cts +1 -1
  106. package/dist/types/node/pkce.d.cts +7 -1
  107. package/package.json +5 -2
  108. package/CHANGELOG.md +0 -231
  109. package/eslint.config.js +0 -2
  110. package/src/dom/accessibility.js +0 -58
  111. package/src/dom/actions/index.js +0 -3
  112. package/src/dom/actions/masonry.js +0 -43
  113. package/src/dom/actions/prefer-horizontal-scroll.js +0 -121
  114. package/src/dom/actions/sticky.js +0 -85
  115. package/src/dom/bounding-box.js +0 -82
  116. package/src/dom/clipboard.js +0 -14
  117. package/src/dom/cookie.js +0 -32
  118. package/src/dom/css-vars.js +0 -19
  119. package/src/dom/events.js +0 -71
  120. package/src/dom/focusable.js +0 -165
  121. package/src/dom/font-size.js +0 -40
  122. package/src/dom/get-element.js +0 -176
  123. package/src/dom/hash.js +0 -9
  124. package/src/dom/index.js +0 -23
  125. package/src/dom/keyboard.js +0 -44
  126. package/src/dom/local-store.js +0 -66
  127. package/src/dom/media.js +0 -30
  128. package/src/dom/observers/index.js +0 -4
  129. package/src/dom/observers/intersection-observer.js +0 -43
  130. package/src/dom/observers/mutation-observer.js +0 -51
  131. package/src/dom/observers/observer.js +0 -18
  132. package/src/dom/observers/resize-observer.js +0 -66
  133. package/src/dom/observers/scroll-observer.js +0 -146
  134. package/src/dom/pkce.js +0 -34
  135. package/src/dom/query-params.js +0 -14
  136. package/src/dom/random-string.js +0 -18
  137. package/src/dom/random-string.test.js +0 -13
  138. package/src/dom/sanitize.js +0 -16
  139. package/src/dom/session-store.js +0 -29
  140. package/src/dom/spam-prevention.js +0 -40
  141. package/src/dom/trap-focus.js +0 -70
  142. package/src/dom/ui/aria-current.js +0 -20
  143. package/src/dom/ui/inconsistent-button-fix.js +0 -20
  144. package/src/dom/ui/index.js +0 -4
  145. package/src/dom/ui/scroll-container.js +0 -25
  146. package/src/dom/ui/traverse-and-scramble.js +0 -61
  147. package/src/lib/arrays/index.js +0 -6
  148. package/src/lib/arrays/item-position.js +0 -23
  149. package/src/lib/arrays/join.js +0 -20
  150. package/src/lib/arrays/shuffle.js +0 -21
  151. package/src/lib/arrays/sort.js +0 -88
  152. package/src/lib/arrays/sort.spec.js +0 -123
  153. package/src/lib/arrays/split-array.js +0 -15
  154. package/src/lib/arrays/unique.js +0 -3
  155. package/src/lib/auth/index.js +0 -1
  156. package/src/lib/auth/route-manager.js +0 -45
  157. package/src/lib/checks.js +0 -57
  158. package/src/lib/date/days.js +0 -9
  159. package/src/lib/date/index.js +0 -3
  160. package/src/lib/date/months.js +0 -74
  161. package/src/lib/date/time.js +0 -83
  162. package/src/lib/form/form-data.js +0 -73
  163. package/src/lib/form/index.js +0 -2
  164. package/src/lib/form/sanitize.js +0 -80
  165. package/src/lib/form/sanitize.spec.js +0 -126
  166. package/src/lib/functions/callback.js +0 -8
  167. package/src/lib/functions/debounce.js +0 -18
  168. package/src/lib/functions/env.js +0 -5
  169. package/src/lib/functions/functional.js +0 -113
  170. package/src/lib/functions/functional.test.js +0 -196
  171. package/src/lib/functions/index.js +0 -5
  172. package/src/lib/functions/throttle.js +0 -11
  173. package/src/lib/functions/timeout.js +0 -15
  174. package/src/lib/hash.js +0 -18
  175. package/src/lib/hash.spec.js +0 -163
  176. package/src/lib/index.js +0 -14
  177. package/src/lib/numbers/index.js +0 -12
  178. package/src/lib/numbers/math.js +0 -9
  179. package/src/lib/numbers/split-unit.test.js +0 -45
  180. package/src/lib/objects/camelcase-keys.js +0 -17
  181. package/src/lib/objects/camelcase-keys.test.js +0 -72
  182. package/src/lib/objects/empty.js +0 -10
  183. package/src/lib/objects/equal.js +0 -9
  184. package/src/lib/objects/extend.js +0 -16
  185. package/src/lib/objects/extend.test.js +0 -35
  186. package/src/lib/objects/flatten.js +0 -19
  187. package/src/lib/objects/index.js +0 -13
  188. package/src/lib/objects/json.js +0 -7
  189. package/src/lib/objects/loop.js +0 -11
  190. package/src/lib/objects/loop.test.js +0 -31
  191. package/src/lib/objects/mix/mix.js +0 -191
  192. package/src/lib/objects/mix/mix.md +0 -78
  193. package/src/lib/objects/mix/mix.test.js +0 -445
  194. package/src/lib/objects/nested-property.js +0 -41
  195. package/src/lib/objects/normalize-object.js +0 -10
  196. package/src/lib/objects/omit-empty.js +0 -23
  197. package/src/lib/objects/omit-empty.test.js +0 -85
  198. package/src/lib/objects/size.js +0 -41
  199. package/src/lib/objects/split.js +0 -19
  200. package/src/lib/promises/index.js +0 -1
  201. package/src/lib/promises/reject.js +0 -17
  202. package/src/lib/sse.js +0 -61
  203. package/src/lib/strings/convert-case/convert-case.js +0 -86
  204. package/src/lib/strings/convert-case/convert-case.md +0 -44
  205. package/src/lib/strings/convert-case/convert-case.test.js +0 -50
  206. package/src/lib/strings/index.js +0 -5
  207. package/src/lib/strings/markdown.js +0 -71
  208. package/src/lib/strings/name.js +0 -24
  209. package/src/lib/strings/name.test.js +0 -67
  210. package/src/lib/strings/pluralize.js +0 -2
  211. package/src/lib/strings/query-string.js +0 -18
  212. package/src/lib/style/index.js +0 -13
  213. package/src/lib/symbols/index.js +0 -1
  214. package/src/lib/symbols/symbols.js +0 -9
  215. package/src/node/dirname.js +0 -17
  216. package/src/node/file-cache.js +0 -184
  217. package/src/node/file.js +0 -13
  218. package/src/node/hash.js +0 -5
  219. package/src/node/index.js +0 -7
  220. package/src/node/pkce.js +0 -33
  221. package/src/node/random-string.js +0 -10
  222. package/src/node/random-string.test.js +0 -15
  223. package/src/node/sanitize.js +0 -13
  224. package/src/node/sanitize.spec.js +0 -142
  225. package/src/node/uuid.js +0 -5
  226. package/tsconfig.json +0 -23
  227. package/tsup.config.js +0 -38
  228. package/tsup.config.mjs +0 -45
@@ -1,163 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { isHashedValue } from './hash.js'
3
-
4
- describe('isHashedValue', () => {
5
- describe('SHA256 hashes', () => {
6
- it('returns true for valid SHA256 hash', () => {
7
- const validSha256 =
8
- 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3'
9
- expect(isHashedValue(validSha256, 'sha256')).toBe(true)
10
- expect(isHashedValue(validSha256)).toBe(true) // default type
11
- })
12
-
13
- it('returns true for valid SHA256 hash with uppercase letters', () => {
14
- const validSha256 =
15
- 'A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3'
16
- expect(isHashedValue(validSha256, 'sha256')).toBe(true)
17
- })
18
-
19
- it('returns true for valid SHA256 hash with mixed case', () => {
20
- const validSha256 =
21
- 'A665a45920422F9d417E4867efdc4FB8a04a1F3fff1FA07e998E86f7f7A27ae3'
22
- expect(isHashedValue(validSha256, 'sha256')).toBe(true)
23
- })
24
-
25
- it('returns false for SHA256 hash with wrong length', () => {
26
- const shortHash =
27
- 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae'
28
- const longHash =
29
- 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae33'
30
- expect(isHashedValue(shortHash, 'sha256')).toBe(false)
31
- expect(isHashedValue(longHash, 'sha256')).toBe(false)
32
- })
33
-
34
- it('returns false for SHA256 hash with invalid characters', () => {
35
- const invalidHash =
36
- 'g665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3'
37
- expect(isHashedValue(invalidHash, 'sha256')).toBe(false)
38
- })
39
- })
40
-
41
- describe('SHA1 hashes', () => {
42
- it('returns true for valid SHA1 hash', () => {
43
- const validSha1 = '356a192b7913b04c54574d18c28d46e6395428ab'
44
- expect(isHashedValue(validSha1, 'sha1')).toBe(true)
45
- })
46
-
47
- it('returns true for valid SHA1 hash with uppercase letters', () => {
48
- const validSha1 = '356A192B7913B04C54574D18C28D46E6395428AB'
49
- expect(isHashedValue(validSha1, 'sha1')).toBe(true)
50
- })
51
-
52
- it('returns false for SHA1 hash with wrong length', () => {
53
- const shortHash = '356a192b7913b04c54574d18c28d46e6395428a'
54
- const longHash = '356a192b7913b04c54574d18c28d46e6395428abb'
55
- expect(isHashedValue(shortHash, 'sha1')).toBe(false)
56
- expect(isHashedValue(longHash, 'sha1')).toBe(false)
57
- })
58
-
59
- it('returns false for SHA1 hash with invalid characters', () => {
60
- const invalidHash = '356g192b7913b04c54574d18c28d46e6395428ab'
61
- expect(isHashedValue(invalidHash, 'sha1')).toBe(false)
62
- })
63
- })
64
-
65
- describe('MD5 hashes', () => {
66
- it('returns true for valid MD5 hash', () => {
67
- const validMd5 = '5d41402abc4b2a76b9719d911017c592'
68
- expect(isHashedValue(validMd5, 'md5')).toBe(true)
69
- })
70
-
71
- it('returns true for valid MD5 hash with uppercase letters', () => {
72
- const validMd5 = '5D41402ABC4B2A76B9719D911017C592'
73
- expect(isHashedValue(validMd5, 'md5')).toBe(true)
74
- })
75
-
76
- it('returns false for MD5 hash with wrong length', () => {
77
- const shortHash = '5d41402abc4b2a76b9719d911017c59'
78
- const longHash = '5d41402abc4b2a76b9719d911017c5922'
79
- expect(isHashedValue(shortHash, 'md5')).toBe(false)
80
- expect(isHashedValue(longHash, 'md5')).toBe(false)
81
- })
82
-
83
- it('returns false for MD5 hash with invalid characters', () => {
84
- const invalidHash = '5g41402abc4b2a76b9719d911017c592'
85
- expect(isHashedValue(invalidHash, 'md5')).toBe(false)
86
- })
87
- })
88
-
89
- describe('Type parameter handling', () => {
90
- it('handles case insensitive type parameter', () => {
91
- const validSha256 =
92
- 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3'
93
- expect(isHashedValue(validSha256, 'SHA256')).toBe(true)
94
- expect(isHashedValue(validSha256, 'Sha256')).toBe(true)
95
- expect(isHashedValue(validSha256, 'sHa256')).toBe(true)
96
- })
97
-
98
- it('returns null for unsupported hash type', () => {
99
- const validSha256 =
100
- 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3'
101
- expect(isHashedValue(validSha256, 'sha512')).toBe(null)
102
- expect(isHashedValue(validSha256, 'blake2b')).toBe(null)
103
- expect(isHashedValue(validSha256, 'unknown')).toBe(null)
104
- })
105
- })
106
-
107
- describe('Input validation', () => {
108
- it('returns null for non-string inputs', () => {
109
- expect(isHashedValue(null)).toBe(null)
110
- expect(isHashedValue(undefined)).toBe(null)
111
- expect(isHashedValue(123)).toBe(null)
112
- expect(isHashedValue([])).toBe(null)
113
- expect(isHashedValue({})).toBe(null)
114
- expect(isHashedValue(true)).toBe(null)
115
- })
116
-
117
- it('handles empty string', () => {
118
- expect(isHashedValue('')).toBe(false)
119
- expect(isHashedValue('', 'sha1')).toBe(false)
120
- expect(isHashedValue('', 'md5')).toBe(false)
121
- })
122
-
123
- it('trims whitespace from input', () => {
124
- const validSha256 =
125
- ' a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3 '
126
- expect(isHashedValue(validSha256, 'sha256')).toBe(true)
127
- })
128
-
129
- it('returns false for strings with only whitespace', () => {
130
- expect(isHashedValue(' ')).toBe(false)
131
- expect(isHashedValue('\t\n')).toBe(false)
132
- })
133
- })
134
-
135
- describe('Edge cases', () => {
136
- it('returns false for strings that are all zeros but correct length', () => {
137
- const zeroSha256 =
138
- '0000000000000000000000000000000000000000000000000000000000000000'
139
- const zeroSha1 = '0000000000000000000000000000000000000000'
140
- const zeroMd5 = '00000000000000000000000000000000'
141
-
142
- expect(isHashedValue(zeroSha256, 'sha256')).toBe(true)
143
- expect(isHashedValue(zeroSha1, 'sha1')).toBe(true)
144
- expect(isHashedValue(zeroMd5, 'md5')).toBe(true)
145
- })
146
-
147
- it('returns false for correct length but non-hex characters', () => {
148
- const nonHexSha256 =
149
- 'g665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3'
150
- const nonHexSha1 = '356g192b7913b04c54574d18c28d46e6395428ab'
151
- const nonHexMd5 = '5g41402abc4b2a76b9719d911017c592'
152
-
153
- expect(isHashedValue(nonHexSha256, 'sha256')).toBe(false)
154
- expect(isHashedValue(nonHexSha1, 'sha1')).toBe(false)
155
- expect(isHashedValue(nonHexMd5, 'md5')).toBe(false)
156
- })
157
-
158
- it('handles special characters correctly', () => {
159
- const specialChars = '!@#$%^&*()_+-=[]{}|;:,.<>?/~`'
160
- expect(isHashedValue(specialChars, 'sha256')).toBe(false)
161
- })
162
- })
163
- })
package/src/lib/index.js DELETED
@@ -1,14 +0,0 @@
1
- export * from './arrays/index.js'
2
- export * from './auth/index.js'
3
- export * from './checks.js'
4
- export * from './date/index.js'
5
- export * from './form/index.js'
6
- export * from './functions/index.js'
7
- export * from './hash.js'
8
- export * from './numbers/index.js'
9
- export * from './objects/index.js'
10
- export * from './promises/index.js'
11
- export * from './sse.js'
12
- export * from './strings/index.js'
13
- export * from './style/index.js'
14
- export * from './symbols/index.js'
@@ -1,12 +0,0 @@
1
- export * from './math.js'
2
-
3
- export function splitUnit(string) {
4
- // If there are no units, return the number straight.
5
- if (typeof string === 'number') return [string, null]
6
-
7
- const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i
8
- const match = string.match(regex)
9
-
10
- if (match) return [parseFloat(match[1]), match[2]]
11
- return [parseFloat(string), null] // sometimes unitless numbers make it here if was typed into a string. This catches and returns it.
12
- }
@@ -1,9 +0,0 @@
1
- // Convert radians to degrees
2
- export function toDegrees(angle) {
3
- return angle * (180 / Math.PI)
4
- }
5
-
6
- // Convert degrees to radians
7
- export function toRadians(angle) {
8
- return angle * (Math.PI / 180)
9
- }
@@ -1,45 +0,0 @@
1
- import { describe, expect, test } from 'vitest'
2
- import { splitUnit } from './index.js'
3
-
4
- describe('splitUnit', () => {
5
- test('handles number input', () => {
6
- const result = splitUnit(42)
7
- expect(result).toEqual([42, null])
8
- })
9
-
10
- test('handles unitless string numbers', () => {
11
- const result = splitUnit('100')
12
- expect(result).toEqual([100, null])
13
- })
14
-
15
- test('handles "3hours" without space', () => {
16
- const result = splitUnit('3hours')
17
- expect(result).toEqual([3, 'hours'])
18
- })
19
-
20
- test('handles "2rem" CSS unit', () => {
21
- const result = splitUnit('2rem')
22
- expect(result).toEqual([2, 'rem'])
23
- })
24
-
25
- test('handles decimal values', () => {
26
- const result = splitUnit('1.5em')
27
- expect(result).toEqual([1.5, 'em'])
28
- })
29
-
30
- test('handles negative values', () => {
31
- const result = splitUnit('-10px')
32
- expect(result).toEqual([-10, 'px'])
33
- })
34
-
35
- // Tests with spaces
36
- test('handles values with spaces', () => {
37
- const result = splitUnit('30 days')
38
- expect(result).toEqual([30, 'days'])
39
- })
40
-
41
- test('handles values with many spaces between number and unit', () => {
42
- const result = splitUnit('10 em')
43
- expect(result).toEqual([10, 'em'])
44
- })
45
- })
@@ -1,17 +0,0 @@
1
- import { objectForEach } from './loop.js'
2
- import { toCamel } from '../strings/convert-case/convert-case.js'
3
-
4
- export function camelCaseKeys(obj) {
5
- if (typeof obj !== 'object' || obj === null) {
6
- return obj
7
- }
8
-
9
- const result = {}
10
-
11
- objectForEach(obj, ({ key, value }) => {
12
- const camelCaseKey = toCamel(key)
13
- result[camelCaseKey] = camelCaseKeys(value)
14
- })
15
-
16
- return result
17
- }
@@ -1,72 +0,0 @@
1
- import { expect, it } from 'vitest'
2
-
3
- import { camelCaseKeys } from './camelcase-keys.js'
4
-
5
- it('Camelcase Basic', ctx => {
6
- const object = {
7
- lowercase: 1,
8
- 'Title Case': 2,
9
- 'kebab-case': 3,
10
- PascalCase: 4,
11
- }
12
-
13
- const expected = {
14
- lowercase: 1,
15
- titleCase: 2,
16
- kebabCase: 3,
17
- pascalCase: 4,
18
- }
19
-
20
- const result = camelCaseKeys(object)
21
- expect(result).toEqual(expected)
22
- })
23
-
24
- it('Camelcase Nested', ctx => {
25
- const object = {
26
- one: {
27
- lowercase: 1,
28
- 'Title Case': 2,
29
- 'kebab-case': 3,
30
- PascalCase: 4,
31
- },
32
- }
33
-
34
- const expected = {
35
- one: {
36
- lowercase: 1,
37
- titleCase: 2,
38
- kebabCase: 3,
39
- pascalCase: 4,
40
- },
41
- }
42
-
43
- const result = camelCaseKeys(object)
44
- expect(result).toEqual(expected)
45
- })
46
-
47
- it('Camelcase Deeply Nested', ctx => {
48
- const object = {
49
- one: {
50
- two: {
51
- lowercase: 1,
52
- 'Title Case': 2,
53
- 'kebab-case': 3,
54
- PascalCase: 4,
55
- },
56
- },
57
- }
58
-
59
- const expected = {
60
- one: {
61
- two: {
62
- lowercase: 1,
63
- titleCase: 2,
64
- kebabCase: 3,
65
- pascalCase: 4,
66
- },
67
- },
68
- }
69
-
70
- const result = camelCaseKeys(object)
71
- expect(result).toEqual(expected)
72
- })
@@ -1,10 +0,0 @@
1
- export function isEmpty(obj) {
2
- if (typeof obj === 'undefined') return true
3
- if (obj === null) return true
4
- if (Array.isArray(obj)) return obj.length === 0
5
- return Object.keys(obj).length === 0
6
- }
7
-
8
- export function notEmpty(obj) {
9
- return !isEmpty(obj)
10
- }
@@ -1,9 +0,0 @@
1
- import deepEqual from 'deep-eql'
2
-
3
- export function isEqual(a, b) {
4
- return deepEqual(a, b)
5
- }
6
-
7
- export function notEqual(a, b) {
8
- return !isEqual(a, b)
9
- }
@@ -1,16 +0,0 @@
1
- import { objectForEach, objectMap } from './loop.js'
2
-
3
- import { curry } from '../functions/functional.js'
4
- import { mix } from './mix/mix.js'
5
-
6
- // Need to manually curry these functions.
7
-
8
- export function extendObject(object) {
9
- const orig = object
10
- const extended = mix({}, object)
11
-
12
- extended.forEach = curry(objectForEach)(orig)
13
- extended.map = curry(objectMap)(orig)
14
-
15
- return { orig, extended }
16
- }
@@ -1,35 +0,0 @@
1
- import { beforeEach, expect, it } from 'vitest'
2
-
3
- import { extendObject } from '.'
4
-
5
- beforeEach(ctx => {
6
- ctx.object = {
7
- one: 1,
8
- two: 2,
9
- }
10
- })
11
-
12
- it('Object Extension', ctx => {
13
- const { object } = ctx
14
- const { extended, orig } = extendObject(object)
15
-
16
- // Orig should be untouched
17
- // Object should also be untouched
18
- expect(object).toEqual(orig)
19
- expect(object.forEach).toBeUndefined()
20
- expect(object.map).toBeUndefined()
21
-
22
- // Extended should be extended
23
- expect(extended.one).toBe(1)
24
- expect(extended.two).toBe(2)
25
- expect(extended.forEach).toBeDefined()
26
- expect(extended.map).toBeDefined()
27
- })
28
-
29
- it('Curried methods', ctx => {
30
- const { extended } = extendObject(ctx.object)
31
-
32
- // Extended methods should not be part of the object when looping
33
- const test = extended.map(({ key, value }) => value)
34
- expect(test).toEqual([1, 2])
35
- })
@@ -1,19 +0,0 @@
1
- import { isObject } from '../checks.js'
2
-
3
- export function flattenObject(obj, { separator, prefix = '' }) {
4
- return Object.entries(obj).reduce((acc, [key, value]) => {
5
- const newKey = prefix ? `${prefix}${separator}${key}` : key
6
-
7
- const isAnObject = isObject(value)
8
- const hasNestedObject = isAnObject && Object.values(value).some(isObject)
9
-
10
- if (hasNestedObject) {
11
- // If the value is an object, recursively flatten it.
12
- Object.assign(acc, flattenObject(value, { separator, prefix: newKey }))
13
- } else {
14
- // Directly assign terminal values to the new key in the accumulator.
15
- acc[newKey] = value
16
- }
17
- return acc
18
- }, {})
19
- }
@@ -1,13 +0,0 @@
1
- export * from './camelcase-keys.js'
2
- export * from './empty.js'
3
- export * from './equal.js'
4
- export * from './extend.js'
5
- export * from './flatten.js'
6
- export * from './json.js'
7
- export * from './loop.js'
8
- export * from './mix/mix.js'
9
- export * from './nested-property.js'
10
- export * from './normalize-object.js'
11
- export * from './omit-empty.js'
12
- export * from './size.js'
13
- export * from './split.js'
@@ -1,7 +0,0 @@
1
- export function parseJSON(value, defaultValue = {}) {
2
- try {
3
- return JSON.parse(value)
4
- } catch (e) {
5
- return defaultValue
6
- }
7
- }
@@ -1,11 +0,0 @@
1
- export function objectForEach(object, callback) {
2
- Object.entries(object).forEach(([key, value]) => {
3
- callback({ key, value })
4
- })
5
- }
6
-
7
- export function objectMap(object, callback) {
8
- return Object.entries(object).map(([key, value]) => {
9
- return callback({ key, value })
10
- })
11
- }
@@ -1,31 +0,0 @@
1
- import { beforeEach, expect, it } from 'vitest'
2
- import { objectForEach, objectMap } from './loop.js'
3
-
4
- beforeEach(ctx => {
5
- ctx.obj = {
6
- one: 1,
7
- two: 2,
8
- }
9
- })
10
-
11
- it('Object For Each', ctx => {
12
- const { obj } = ctx
13
- const newObject = {}
14
- function callback({ key, value }) {
15
- newObject[key] = value
16
- }
17
-
18
- objectForEach(obj, callback)
19
- expect(newObject).toEqual(obj)
20
- })
21
-
22
- it('Object Map', ctx => {
23
- const { obj } = ctx
24
-
25
- function callback({ key, value }) {
26
- return value
27
- }
28
-
29
- const res = objectMap(obj, callback)
30
- expect(res).toEqual([1, 2])
31
- })