@splendidlabz/utils 1.10.2 → 1.10.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 (209) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/dom/accessibility.cjs +0 -2
  3. package/dist/cjs/dom/actions/index.cjs +7 -391
  4. package/dist/cjs/dom/actions/masonry.cjs +6 -97
  5. package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +14 -58
  6. package/dist/cjs/dom/actions/sticky.cjs +6 -126
  7. package/dist/cjs/dom/bounding-box.cjs +0 -2
  8. package/dist/cjs/dom/clipboard.cjs +0 -2
  9. package/dist/cjs/dom/cookie.cjs +1 -3
  10. package/dist/cjs/dom/css-vars.cjs +3 -13
  11. package/dist/cjs/dom/events.cjs +0 -2
  12. package/dist/cjs/dom/focusable.cjs +0 -2
  13. package/dist/cjs/dom/font-size.cjs +3 -15
  14. package/dist/cjs/dom/get-element.cjs +1 -3
  15. package/dist/cjs/dom/hash.cjs +0 -2
  16. package/dist/cjs/dom/index.cjs +47 -1248
  17. package/dist/cjs/dom/keyboard.cjs +0 -2
  18. package/dist/cjs/dom/local-store.cjs +1 -3
  19. package/dist/cjs/dom/media.cjs +0 -2
  20. package/dist/cjs/dom/observers/index.cjs +9 -235
  21. package/dist/cjs/dom/observers/intersection-observer.cjs +6 -38
  22. package/dist/cjs/dom/observers/mutation-observer.cjs +6 -38
  23. package/dist/cjs/dom/observers/observer.cjs +2 -12
  24. package/dist/cjs/dom/observers/resize-observer.cjs +6 -38
  25. package/dist/cjs/dom/observers/scroll-observer.cjs +3 -62
  26. package/dist/cjs/dom/pkce.cjs +3 -13
  27. package/dist/cjs/dom/query-params.cjs +1 -3
  28. package/dist/cjs/dom/random-string.cjs +0 -2
  29. package/dist/cjs/dom/sanitize.cjs +3 -27
  30. package/dist/cjs/dom/session-store.cjs +1 -3
  31. package/dist/cjs/dom/spam-prevention.cjs +0 -2
  32. package/dist/cjs/dom/trap-focus.cjs +9 -131
  33. package/dist/cjs/dom/ui/aria-current.cjs +0 -2
  34. package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +0 -2
  35. package/dist/cjs/dom/ui/index.cjs +9 -87
  36. package/dist/cjs/dom/ui/scroll-container.cjs +0 -2
  37. package/dist/cjs/dom/ui/traverse-and-scramble.cjs +0 -2
  38. package/dist/cjs/lib/arrays/index.cjs +13 -121
  39. package/dist/cjs/lib/arrays/item-position.cjs +0 -2
  40. package/dist/cjs/lib/arrays/join.cjs +2 -10
  41. package/dist/cjs/lib/arrays/shuffle.cjs +0 -2
  42. package/dist/cjs/lib/arrays/sort.cjs +3 -11
  43. package/dist/cjs/lib/arrays/split-array.cjs +0 -2
  44. package/dist/cjs/lib/arrays/unique.cjs +0 -2
  45. package/dist/cjs/lib/auth/index.cjs +3 -35
  46. package/dist/cjs/lib/auth/route-manager.cjs +0 -2
  47. package/dist/cjs/lib/checks.cjs +0 -2
  48. package/dist/cjs/lib/date/days.cjs +1 -3
  49. package/dist/cjs/lib/date/index.cjs +7 -190
  50. package/dist/cjs/lib/date/months.cjs +1 -3
  51. package/dist/cjs/lib/date/time.cjs +2 -14
  52. package/dist/cjs/lib/form/form-data.cjs +0 -2
  53. package/dist/cjs/lib/form/index.cjs +5 -104
  54. package/dist/cjs/lib/form/sanitize.cjs +0 -2
  55. package/dist/cjs/lib/functions/callback.cjs +0 -2
  56. package/dist/cjs/lib/functions/debounce.cjs +0 -2
  57. package/dist/cjs/lib/functions/env.cjs +0 -2
  58. package/dist/cjs/lib/functions/functional.cjs +0 -2
  59. package/dist/cjs/lib/functions/index.cjs +11 -124
  60. package/dist/cjs/lib/functions/throttle.cjs +0 -2
  61. package/dist/cjs/lib/functions/timeout.cjs +0 -2
  62. package/dist/cjs/lib/hash.cjs +0 -2
  63. package/dist/cjs/lib/index.cjs +29 -1155
  64. package/dist/cjs/lib/numbers/index.cjs +4 -17
  65. package/dist/cjs/lib/numbers/math.cjs +0 -2
  66. package/dist/cjs/lib/objects/camelcase-keys.cjs +4 -45
  67. package/dist/cjs/lib/objects/empty.cjs +0 -2
  68. package/dist/cjs/lib/objects/equal.cjs +0 -2
  69. package/dist/cjs/lib/objects/extend.cjs +6 -117
  70. package/dist/cjs/lib/objects/flatten.cjs +3 -11
  71. package/dist/cjs/lib/objects/index.cjs +27 -360
  72. package/dist/cjs/lib/objects/json.cjs +0 -2
  73. package/dist/cjs/lib/objects/loop.cjs +0 -2
  74. package/dist/cjs/lib/objects/mix/mix.cjs +3 -5
  75. package/dist/cjs/lib/objects/nested-property.cjs +0 -2
  76. package/dist/cjs/lib/objects/normalize-object.cjs +4 -78
  77. package/dist/cjs/lib/objects/omit-empty.cjs +0 -2
  78. package/dist/cjs/lib/objects/size.cjs +0 -2
  79. package/dist/cjs/lib/objects/split.cjs +0 -2
  80. package/dist/cjs/lib/promises/index.cjs +3 -51
  81. package/dist/cjs/lib/promises/reject.cjs +2 -19
  82. package/dist/cjs/lib/sse.cjs +4 -29
  83. package/dist/cjs/lib/strings/convert-case/convert-case.cjs +0 -2
  84. package/dist/cjs/lib/strings/index.cjs +11 -179
  85. package/dist/cjs/lib/strings/markdown.cjs +1 -3
  86. package/dist/cjs/lib/strings/name.cjs +0 -2
  87. package/dist/cjs/lib/strings/pluralize.cjs +1 -3
  88. package/dist/cjs/lib/strings/query-string.cjs +0 -2
  89. package/dist/cjs/lib/style/index.cjs +2 -31
  90. package/dist/cjs/lib/symbols/index.cjs +3 -22
  91. package/dist/cjs/lib/symbols/symbols.cjs +0 -2
  92. package/dist/cjs/node/dirname.cjs +2 -4
  93. package/dist/cjs/node/env.cjs +30 -0
  94. package/dist/cjs/node/file-cache.cjs +3 -45
  95. package/dist/cjs/node/file.cjs +2 -4
  96. package/dist/cjs/node/hash.cjs +1 -3
  97. package/dist/cjs/node/index.cjs +17 -272
  98. package/dist/cjs/node/pkce.cjs +5 -15
  99. package/dist/cjs/node/random-string.cjs +1 -3
  100. package/dist/cjs/node/sanitize.cjs +3 -27
  101. package/dist/cjs/node/{common.cjs → uuid.cjs} +3 -5
  102. package/dist/esm/dom/accessibility.js +0 -1
  103. package/dist/esm/dom/actions/index.js +3 -381
  104. package/dist/esm/dom/actions/masonry.js +3 -91
  105. package/dist/esm/dom/actions/prefer-horizontal-scroll.js +4 -45
  106. package/dist/esm/dom/actions/sticky.js +3 -120
  107. package/dist/esm/dom/bounding-box.js +0 -1
  108. package/dist/esm/dom/clipboard.js +0 -1
  109. package/dist/esm/dom/cookie.js +1 -2
  110. package/dist/esm/dom/css-vars.js +1 -8
  111. package/dist/esm/dom/events.js +0 -1
  112. package/dist/esm/dom/focusable.js +0 -1
  113. package/dist/esm/dom/font-size.js +1 -10
  114. package/dist/esm/dom/get-element.js +1 -2
  115. package/dist/esm/dom/hash.js +0 -1
  116. package/dist/esm/dom/index.js +23 -1168
  117. package/dist/esm/dom/keyboard.js +0 -1
  118. package/dist/esm/dom/local-store.js +1 -2
  119. package/dist/esm/dom/media.js +0 -1
  120. package/dist/esm/dom/observers/index.js +4 -224
  121. package/dist/esm/dom/observers/intersection-observer.js +2 -31
  122. package/dist/esm/dom/observers/mutation-observer.js +3 -32
  123. package/dist/esm/dom/observers/observer.js +1 -8
  124. package/dist/esm/dom/observers/resize-observer.js +2 -31
  125. package/dist/esm/dom/observers/scroll-observer.js +2 -58
  126. package/dist/esm/dom/pkce.js +1 -8
  127. package/dist/esm/dom/query-params.js +1 -2
  128. package/dist/esm/dom/random-string.js +0 -1
  129. package/dist/esm/dom/sanitize.js +3 -26
  130. package/dist/esm/dom/session-store.js +1 -2
  131. package/dist/esm/dom/spam-prevention.js +0 -1
  132. package/dist/esm/dom/trap-focus.js +2 -121
  133. package/dist/esm/dom/ui/aria-current.js +0 -1
  134. package/dist/esm/dom/ui/inconsistent-button-fix.js +0 -1
  135. package/dist/esm/dom/ui/index.js +4 -75
  136. package/dist/esm/dom/ui/scroll-container.js +0 -1
  137. package/dist/esm/dom/ui/traverse-and-scramble.js +0 -1
  138. package/dist/esm/lib/arrays/index.js +6 -106
  139. package/dist/esm/lib/arrays/item-position.js +0 -1
  140. package/dist/esm/lib/arrays/join.js +1 -6
  141. package/dist/esm/lib/arrays/shuffle.js +0 -1
  142. package/dist/esm/lib/arrays/sort.js +1 -6
  143. package/dist/esm/lib/arrays/split-array.js +0 -1
  144. package/dist/esm/lib/arrays/unique.js +0 -1
  145. package/dist/esm/lib/auth/index.js +1 -26
  146. package/dist/esm/lib/auth/route-manager.js +0 -1
  147. package/dist/esm/lib/checks.js +0 -1
  148. package/dist/esm/lib/date/days.js +1 -2
  149. package/dist/esm/lib/date/index.js +3 -173
  150. package/dist/esm/lib/date/months.js +1 -2
  151. package/dist/esm/lib/date/time.js +1 -10
  152. package/dist/esm/lib/form/form-data.js +0 -1
  153. package/dist/esm/lib/form/index.js +2 -92
  154. package/dist/esm/lib/form/sanitize.js +0 -1
  155. package/dist/esm/lib/functions/callback.js +0 -1
  156. package/dist/esm/lib/functions/debounce.js +0 -1
  157. package/dist/esm/lib/functions/env.js +0 -1
  158. package/dist/esm/lib/functions/functional.js +0 -1
  159. package/dist/esm/lib/functions/index.js +5 -105
  160. package/dist/esm/lib/functions/throttle.js +0 -1
  161. package/dist/esm/lib/functions/timeout.js +0 -1
  162. package/dist/esm/lib/hash.js +0 -1
  163. package/dist/esm/lib/index.js +14 -1052
  164. package/dist/esm/lib/numbers/index.js +2 -12
  165. package/dist/esm/lib/numbers/math.js +0 -1
  166. package/dist/esm/lib/objects/camelcase-keys.js +2 -40
  167. package/dist/esm/lib/objects/empty.js +0 -1
  168. package/dist/esm/lib/objects/equal.js +0 -1
  169. package/dist/esm/lib/objects/extend.js +3 -111
  170. package/dist/esm/lib/objects/flatten.js +1 -6
  171. package/dist/esm/lib/objects/index.js +13 -323
  172. package/dist/esm/lib/objects/json.js +0 -1
  173. package/dist/esm/lib/objects/loop.js +0 -1
  174. package/dist/esm/lib/objects/mix/mix.js +3 -4
  175. package/dist/esm/lib/objects/nested-property.js +0 -1
  176. package/dist/esm/lib/objects/normalize-object.js +3 -74
  177. package/dist/esm/lib/objects/omit-empty.js +0 -1
  178. package/dist/esm/lib/objects/size.js +0 -1
  179. package/dist/esm/lib/objects/split.js +0 -1
  180. package/dist/esm/lib/promises/index.js +1 -33
  181. package/dist/esm/lib/promises/reject.js +1 -17
  182. package/dist/esm/lib/sse.js +2 -24
  183. package/dist/esm/lib/strings/convert-case/convert-case.js +0 -1
  184. package/dist/esm/lib/strings/index.js +5 -147
  185. package/dist/esm/lib/strings/markdown.js +1 -2
  186. package/dist/esm/lib/strings/name.js +0 -1
  187. package/dist/esm/lib/strings/pluralize.js +1 -2
  188. package/dist/esm/lib/strings/query-string.js +0 -1
  189. package/dist/esm/lib/style/index.js +1 -27
  190. package/dist/esm/lib/symbols/index.js +1 -13
  191. package/dist/esm/lib/symbols/symbols.js +0 -1
  192. package/dist/esm/node/dirname.js +2 -3
  193. package/dist/esm/node/env.js +6 -0
  194. package/dist/esm/node/file-cache.js +2 -43
  195. package/dist/esm/node/file.js +2 -3
  196. package/dist/esm/node/hash.js +1 -2
  197. package/dist/esm/node/index.js +8 -243
  198. package/dist/esm/node/pkce.js +3 -12
  199. package/dist/esm/node/random-string.js +1 -2
  200. package/dist/esm/node/sanitize.js +3 -26
  201. package/dist/esm/node/{common.js → uuid.js} +0 -1
  202. package/dist/types/node/env.d.cts +3 -0
  203. package/dist/types/node/index.d.cts +2 -1
  204. package/package.json +2 -1
  205. package/src/node/env.js +3 -0
  206. package/src/node/index.js +2 -1
  207. package/tsup.config.mjs +2 -0
  208. /package/dist/types/node/{common.d.cts → uuid.d.cts} +0 -0
  209. /package/src/node/{common.js → uuid.js} +0 -0
@@ -1,75 +1,4 @@
1
- // src/dom/ui/aria-current.js
2
- function markActiveAnchorIn(container, anchorType = "page") {
3
- if (!container) return;
4
- const { pathname } = window.location;
5
- const element = container.querySelector(`[href="${pathname}"]`);
6
- if (!element) return;
7
- element.setAttribute("aria-current", "page");
8
- return element;
9
- }
10
- function scrollToElement(element, { scrollBehaviour = "instant", scrollMargin = "3rem" } = {}) {
11
- if (!element) return;
12
- element.style.scrollMarginTop = scrollMargin;
13
- element.scrollIntoView({ behavior: scrollBehaviour });
14
- }
15
-
16
- // src/dom/ui/inconsistent-button-fix.js
17
- function inconsistentButtonFix() {
18
- document.addEventListener("click", (event) => {
19
- if (event.target instanceof HTMLButtonElement) {
20
- event.target.focus();
21
- }
22
- });
23
- }
24
-
25
- // src/dom/ui/scroll-container.js
26
- function findScrollContainer(element, direction = "both") {
27
- if (!element) return;
28
- let parent = element.parentElement;
29
- while (parent) {
30
- const { overflow, overflowX, overflowY } = getComputedStyle(parent);
31
- if (direction === "both") {
32
- if (overflow.includes("auto") || overflow.includes("scroll"))
33
- return parent;
34
- }
35
- if (direction === "horizontal") {
36
- if (overflowX === "auto" || overflowX === "scroll") return parent;
37
- }
38
- if (direction === "vertical") {
39
- if (overflowY === "auto" || overflowY === "scroll") return parent;
40
- }
41
- parent = parent.parentElement;
42
- }
43
- return document.documentElement;
44
- }
45
-
46
- // src/dom/ui/traverse-and-scramble.js
47
- function traverseAndScramble(node, { excludes = [] } = {}) {
48
- if (node instanceof Element && excludes.some((selector) => node.matches(selector))) {
49
- return;
50
- }
51
- node.childNodes.forEach((child) => {
52
- if (child.nodeType === 3) {
53
- child.nodeValue = scrambleText(child.nodeValue);
54
- } else if (child.nodeType === 1 && child instanceof Element) {
55
- traverseAndScramble(child, { excludes });
56
- }
57
- });
58
- }
59
- function scrambleText(text) {
60
- return text.split("").map((char) => {
61
- if (/^[A-Za-z0-9]$/.test(char)) {
62
- const randomCharCode = Math.random() < 26 / 36 ? Math.floor(Math.random() * 26) + (char === char.toUpperCase() ? 65 : 97) : Math.floor(Math.random() * 10) + 48;
63
- return String.fromCharCode(randomCharCode);
64
- } else {
65
- return char;
66
- }
67
- }).join("");
68
- }
69
- export {
70
- findScrollContainer,
71
- inconsistentButtonFix,
72
- markActiveAnchorIn,
73
- scrollToElement,
74
- traverseAndScramble
75
- };
1
+ export * from "./aria-current.js";
2
+ export * from "./inconsistent-button-fix.js";
3
+ export * from "./scroll-container.js";
4
+ export * from "./traverse-and-scramble.js";
@@ -1,4 +1,3 @@
1
- // src/dom/ui/scroll-container.js
2
1
  function findScrollContainer(element, direction = "both") {
3
2
  if (!element) return;
4
3
  let parent = element.parentElement;
@@ -1,4 +1,3 @@
1
- // src/dom/ui/traverse-and-scramble.js
2
1
  function traverseAndScramble(node, { excludes = [] } = {}) {
3
2
  if (node instanceof Element && excludes.some((selector) => node.matches(selector))) {
4
3
  return;
@@ -1,106 +1,6 @@
1
- // src/lib/arrays/item-position.js
2
- function last(array, index) {
3
- console.warn("last is deprecated. Use isLastItem instead.");
4
- return index === array.length - 1;
5
- }
6
- function isLastItem(array, index) {
7
- return index === array.length - 1;
8
- }
9
- function lastArrayItem(array) {
10
- return array[array.length - 1];
11
- }
12
-
13
- // src/lib/arrays/join.js
14
- function joinWithConjunction(array, { conjunction = "and" } = {}) {
15
- if (!array?.length) return "";
16
- if (array.length === 1) return array[0];
17
- if (array.length === 2) return `${array[0]} ${conjunction} ${array[1]}`;
18
- const lastItem = lastArrayItem(array);
19
- const rest = array.slice(0, -1);
20
- return `${rest.join(", ")} ${conjunction} ${lastItem}`;
21
- }
22
-
23
- // src/lib/arrays/shuffle.js
24
- function shuffle(array) {
25
- const clone = array.slice();
26
- let currentIndex = array.length;
27
- let temporaryValue;
28
- let randomIndex;
29
- while (currentIndex !== 0) {
30
- randomIndex = Math.floor(Math.random() * currentIndex);
31
- currentIndex -= 1;
32
- temporaryValue = clone[currentIndex];
33
- clone[currentIndex] = clone[randomIndex];
34
- clone[randomIndex] = temporaryValue;
35
- }
36
- return clone;
37
- }
38
-
39
- // src/lib/objects/nested-property.js
40
- function getNestedValue(object, path) {
41
- return path.split(".").reduce((acc, part) => acc?.[part], object);
42
- }
43
-
44
- // src/lib/arrays/sort.js
45
- function sort(array, { props = null, reverse = false } = {}) {
46
- const clone = array.slice();
47
- if (props === null) {
48
- return clone.sort((a, b) => {
49
- const comparison = compareValues(a, b);
50
- return reverse ? -comparison : comparison;
51
- });
52
- }
53
- const properties = Array.isArray(props) ? props : [props];
54
- return clone.sort((a, b) => {
55
- for (const property of properties) {
56
- const aValue = getNestedValue(a, property);
57
- const bValue = getNestedValue(b, property);
58
- if (aValue === bValue) continue;
59
- if (aValue == null) return 1;
60
- if (bValue == null) return -1;
61
- const comparison = compareValues(aValue, bValue);
62
- return reverse ? -comparison : comparison;
63
- }
64
- return 0;
65
- });
66
- }
67
- function compareValues(a, b) {
68
- if (typeof a === "number" && typeof b === "number") return a - b;
69
- if (typeof a === "string" && typeof b === "string") return a.localeCompare(b);
70
- const aDate = new Date(a);
71
- const bDate = new Date(b);
72
- const aTime = aDate.getTime();
73
- const bTime = bDate.getTime();
74
- if (!isNaN(aTime) && !isNaN(bTime)) return aTime - bTime;
75
- return String(a).localeCompare(String(b));
76
- }
77
-
78
- // src/lib/arrays/split-array.js
79
- function splitArray(array, predicate) {
80
- const ret = {
81
- picked: [],
82
- omitted: []
83
- };
84
- array.forEach((item, index, arr) => {
85
- if (predicate(item, index, arr)) ret.picked.push(item);
86
- else ret.omitted.push(item);
87
- });
88
- ret.p = ret.picked;
89
- ret.o = ret.omitted;
90
- return ret;
91
- }
92
-
93
- // src/lib/arrays/unique.js
94
- function uniqueArray(array) {
95
- return Array.from(new Set(array));
96
- }
97
- export {
98
- isLastItem,
99
- joinWithConjunction,
100
- last,
101
- lastArrayItem,
102
- shuffle,
103
- sort,
104
- splitArray,
105
- uniqueArray
106
- };
1
+ export * from "./item-position.js";
2
+ export * from "./join.js";
3
+ export * from "./shuffle.js";
4
+ export * from "./sort.js";
5
+ export * from "./split-array.js";
6
+ export * from "./unique.js";
@@ -1,4 +1,3 @@
1
- // src/lib/arrays/item-position.js
2
1
  function last(array, index) {
3
2
  console.warn("last is deprecated. Use isLastItem instead.");
4
3
  return index === array.length - 1;
@@ -1,9 +1,4 @@
1
- // src/lib/arrays/item-position.js
2
- function lastArrayItem(array) {
3
- return array[array.length - 1];
4
- }
5
-
6
- // src/lib/arrays/join.js
1
+ import { lastArrayItem } from "./item-position.js";
7
2
  function joinWithConjunction(array, { conjunction = "and" } = {}) {
8
3
  if (!array?.length) return "";
9
4
  if (array.length === 1) return array[0];
@@ -1,4 +1,3 @@
1
- // src/lib/arrays/shuffle.js
2
1
  function shuffle(array) {
3
2
  const clone = array.slice();
4
3
  let currentIndex = array.length;
@@ -1,9 +1,4 @@
1
- // src/lib/objects/nested-property.js
2
- function getNestedValue(object, path) {
3
- return path.split(".").reduce((acc, part) => acc?.[part], object);
4
- }
5
-
6
- // src/lib/arrays/sort.js
1
+ import { getNestedValue } from "../objects/nested-property.js";
7
2
  function sort(array, { props = null, reverse = false } = {}) {
8
3
  const clone = array.slice();
9
4
  if (props === null) {
@@ -1,4 +1,3 @@
1
- // src/lib/arrays/split-array.js
2
1
  function splitArray(array, predicate) {
3
2
  const ret = {
4
3
  picked: [],
@@ -1,4 +1,3 @@
1
- // src/lib/arrays/unique.js
2
1
  function uniqueArray(array) {
3
2
  return Array.from(new Set(array));
4
3
  }
@@ -1,26 +1 @@
1
- // src/lib/auth/route-manager.js
2
- function RouteManager(config) {
3
- const { protectedRoutes, bypassRoutes } = config;
4
- return {
5
- isProtectedRoute(pathname) {
6
- return isMatch(protectedRoutes, pathname);
7
- },
8
- isBypassRoute(pathname) {
9
- return isMatch(bypassRoutes, pathname);
10
- }
11
- };
12
- }
13
- function AuthManager(config) {
14
- return RouteManager(config);
15
- }
16
- function isMatch(routeConfig, pathname) {
17
- const { is, startsWith, includes } = routeConfig;
18
- const isExactMatch = is && is.some((u) => pathname === u);
19
- const startsWithMatch = startsWith && startsWith.some((u) => pathname.startsWith(u));
20
- const includesMatch = includes && includes.some((u) => pathname.includes(u));
21
- return isExactMatch || startsWithMatch || includesMatch;
22
- }
23
- export {
24
- AuthManager,
25
- RouteManager
26
- };
1
+ export * from "./route-manager.js";
@@ -1,4 +1,3 @@
1
- // src/lib/auth/route-manager.js
2
1
  function RouteManager(config) {
3
2
  const { protectedRoutes, bypassRoutes } = config;
4
3
  return {
@@ -1,4 +1,3 @@
1
- // src/lib/checks.js
2
1
  function isObject(x) {
3
2
  return typeof x === "object" && !Array.isArray(x) && x !== null;
4
3
  }
@@ -1,5 +1,4 @@
1
- // src/lib/date/days.js
2
- var DAYS = [
1
+ const DAYS = [
3
2
  { short: "Sun", long: "Sunday", numeric: 1 },
4
3
  { short: "Mon", long: "Monday", numeric: 2 },
5
4
  { short: "Tue", long: "Tuesday", numeric: 3 },
@@ -1,173 +1,3 @@
1
- // src/lib/date/days.js
2
- var DAYS = [
3
- { short: "Sun", long: "Sunday", numeric: 1 },
4
- { short: "Mon", long: "Monday", numeric: 2 },
5
- { short: "Tue", long: "Tuesday", numeric: 3 },
6
- { short: "Wed", long: "Wednesday", numeric: 4 },
7
- { short: "Thu", long: "Thursday", numeric: 5 },
8
- { short: "Fri", long: "Friday", numeric: 6 },
9
- { short: "Sat", long: "Saturday", numeric: 7 }
10
- ];
11
-
12
- // src/lib/date/months.js
13
- var MONTHS = [
14
- {
15
- long: "January",
16
- short: "jan",
17
- numeric: 1,
18
- lastDay: { default: 31, leapYear: 31 }
19
- },
20
- {
21
- long: "February",
22
- short: "feb",
23
- numeric: 2,
24
- lastDay: { default: 28, leapYear: 29 }
25
- },
26
- {
27
- long: "March",
28
- short: "mar",
29
- numeric: 3,
30
- lastDay: { default: 31, leapYear: 31 }
31
- },
32
- {
33
- long: "April",
34
- short: "apr",
35
- numeric: 4,
36
- lastDay: { default: 30, leapYear: 30 }
37
- },
38
- {
39
- long: "May",
40
- short: "may",
41
- numeric: 5,
42
- lastDay: { default: 31, leapYear: 31 }
43
- },
44
- {
45
- long: "June",
46
- short: "jun",
47
- numeric: 6,
48
- lastDay: { default: 30, leapYear: 30 }
49
- },
50
- {
51
- long: "July",
52
- short: "jul",
53
- numeric: 7,
54
- lastDay: { default: 31, leapYear: 31 }
55
- },
56
- {
57
- long: "August",
58
- short: "aug",
59
- numeric: 8,
60
- lastDay: { default: 31, leapYear: 31 }
61
- },
62
- {
63
- long: "September",
64
- short: "sep",
65
- numeric: 9,
66
- lastDay: { default: 30, leapYear: 30 }
67
- },
68
- {
69
- long: "October",
70
- short: "oct",
71
- numeric: 10,
72
- lastDay: { default: 31, leapYear: 31 }
73
- },
74
- {
75
- long: "November",
76
- short: "nov",
77
- numeric: 11,
78
- lastDay: { default: 30, leapYear: 30 }
79
- },
80
- {
81
- long: "December",
82
- short: "dec",
83
- numeric: 12,
84
- lastDay: { default: 31, leapYear: 31 }
85
- }
86
- ];
87
-
88
- // src/lib/numbers/index.js
89
- function splitUnit(string) {
90
- if (typeof string === "number") return [string, null];
91
- const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
92
- const match = string.match(regex);
93
- if (match) return [parseFloat(match[1]), match[2]];
94
- return [parseFloat(string), null];
95
- }
96
-
97
- // src/lib/date/time.js
98
- function ms(arg) {
99
- const [value, unit] = splitUnit(arg);
100
- if (unit === "d") return getTimeInMs(value, "days");
101
- if (unit === "day") return getTimeInMs(value, "days");
102
- if (unit === "days") return getTimeInMs(value, "days");
103
- if (unit === "h") return getTimeInMs(value, "hours");
104
- if (unit === "hr") return getTimeInMs(value, "hours");
105
- if (unit === "hour") return getTimeInMs(value, "hours");
106
- if (unit === "hours") return getTimeInMs(value, "hours");
107
- if (unit === "m") return getTimeInMs(value, "minutes");
108
- if (unit === "min") return getTimeInMs(value, "minutes");
109
- if (unit === "mins") return getTimeInMs(value, "minutes");
110
- if (unit === "minute") return getTimeInMs(value, "minutes");
111
- if (unit === "minutes") return getTimeInMs(value, "minutes");
112
- if (unit === "s") return getTimeInMs(value, "seconds");
113
- if (unit === "sec") return getTimeInMs(value, "seconds");
114
- if (unit === "secs") return getTimeInMs(value, "seconds");
115
- if (unit === "second") return getTimeInMs(value, "seconds");
116
- if (unit === "seconds") return getTimeInMs(value, "seconds");
117
- return value;
118
- }
119
- function getTimeInMs(value, unit = "ms") {
120
- switch (unit) {
121
- case "ms":
122
- return value;
123
- case "seconds":
124
- return value * 1e3;
125
- case "minutes":
126
- return value * 1e3 * 60;
127
- case "hours":
128
- return value * 1e3 * 60 * 60;
129
- case "days":
130
- return value * 1e3 * 60 * 60 * 24;
131
- case "weeks":
132
- return value * 1e3 * 60 * 60 * 24 * 7;
133
- }
134
- }
135
- function toWeeks(ms2) {
136
- return ms2 / 1e3 / 60 / 60 / 24 / 7;
137
- }
138
- function toDays(ms2) {
139
- return ms2 / 1e3 / 60 / 60 / 24;
140
- }
141
- function toHours(ms2) {
142
- return ms2 / 1e3 / 60 / 60;
143
- }
144
- function toMinutes(ms2) {
145
- return ms2 / 1e3 / 60;
146
- }
147
- function toSeconds(ms2) {
148
- return ms2 / 1e3;
149
- }
150
- function toReadableTime(ms2) {
151
- const weekMs = 1e3 * 60 * 60 * 24 * 7;
152
- const dayMs = 1e3 * 60 * 60 * 24;
153
- const hourMs = 1e3 * 60 * 60;
154
- const minuteMs = 1e3 * 60;
155
- const weeks = Math.floor(ms2 / weekMs);
156
- const days = Math.floor(ms2 % weekMs / dayMs);
157
- const hours = Math.floor(ms2 % dayMs / hourMs);
158
- const minutes = Math.floor(ms2 % hourMs / minuteMs);
159
- const seconds = Math.floor(ms2 % minuteMs / 1e3);
160
- return { weeks, days, hours, minutes, seconds };
161
- }
162
- export {
163
- DAYS,
164
- MONTHS,
165
- getTimeInMs,
166
- ms,
167
- toDays,
168
- toHours,
169
- toMinutes,
170
- toReadableTime,
171
- toSeconds,
172
- toWeeks
173
- };
1
+ export * from "./days.js";
2
+ export * from "./months.js";
3
+ export * from "./time.js";
@@ -1,5 +1,4 @@
1
- // src/lib/date/months.js
2
- var MONTHS = [
1
+ const MONTHS = [
3
2
  {
4
3
  long: "January",
5
4
  short: "jan",
@@ -1,13 +1,4 @@
1
- // src/lib/numbers/index.js
2
- function splitUnit(string) {
3
- if (typeof string === "number") return [string, null];
4
- const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
5
- const match = string.match(regex);
6
- if (match) return [parseFloat(match[1]), match[2]];
7
- return [parseFloat(string), null];
8
- }
9
-
10
- // src/lib/date/time.js
1
+ import { splitUnit } from "../numbers/index.js";
11
2
  function ms(arg) {
12
3
  const [value, unit] = splitUnit(arg);
13
4
  if (unit === "d") return getTimeInMs(value, "days");
@@ -1,4 +1,3 @@
1
- // src/lib/form/form-data.js
2
1
  function formDataToObject(formData) {
3
2
  const obj = {};
4
3
  for (let [key, value] of formData) {
@@ -1,92 +1,2 @@
1
- // src/lib/form/form-data.js
2
- function formDataToObject(formData) {
3
- const obj = {};
4
- for (let [key, value] of formData) {
5
- if (typeof value === "string") value = value.trim();
6
- if (key.includes("[]")) {
7
- const arrayKey = key.replace("[]", "");
8
- if (!obj[arrayKey]) obj[arrayKey] = [];
9
- obj[arrayKey].push(value);
10
- } else {
11
- obj[key] = value;
12
- }
13
- }
14
- return obj;
15
- }
16
- function flattenArrayFields(inputObject) {
17
- const result = {};
18
- for (const [key, value] of Object.entries(inputObject)) {
19
- const match = key.match(/^(\w+)(?:\[(\d+)\])?(?:\[(\w+)\])?$/);
20
- if (match) {
21
- const [, baseKey, index, property] = match;
22
- if (index !== void 0) {
23
- if (!result[baseKey]) result[baseKey] = [];
24
- const arrayIndex = parseInt(index);
25
- if (!result[baseKey][arrayIndex]) result[baseKey][arrayIndex] = {};
26
- if (property) {
27
- result[baseKey][arrayIndex][property] = value;
28
- } else {
29
- result[baseKey][arrayIndex] = value;
30
- }
31
- } else if (property) {
32
- if (!result[baseKey]) result[baseKey] = {};
33
- result[baseKey][property] = value;
34
- } else {
35
- result[key] = value;
36
- }
37
- } else {
38
- result[key] = value;
39
- }
40
- }
41
- for (const key in result) {
42
- if (typeof result[key] === "object" && result[key] !== null) {
43
- if (Object.keys(result[key]).every((k) => !isNaN(parseInt(k)))) {
44
- result[key] = Object.values(result[key]).filter((item) => {
45
- if (typeof item === "object") {
46
- return Object.values(item).some((v) => v !== "");
47
- }
48
- return item !== "";
49
- });
50
- }
51
- }
52
- }
53
- return result;
54
- }
55
-
56
- // src/lib/form/sanitize.js
57
- function sanitize(value, options = {}) {
58
- const { sanitizer, ...rest } = options;
59
- if (!sanitizer) throw new Error("sanitizer function is required");
60
- if (typeof value === "string") return sanitizer(value, rest);
61
- if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
62
- if (value && typeof value === "object") {
63
- return Object.fromEntries(
64
- Object.entries(value).map(([key, val]) => [
65
- key,
66
- sanitize(val, { sanitizer, ...rest })
67
- ])
68
- );
69
- }
70
- return value;
71
- }
72
- function sanitizeArray(arr, { sanitizer, ...rest }) {
73
- if (!sanitizer) throw new Error("sanitizer function is required");
74
- return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
75
- }
76
- function sanitizeObject(obj, { sanitizer, ...options } = {}) {
77
- if (!sanitizer) throw new Error("sanitizer function is required");
78
- if (Array.isArray(obj)) return sanitizeArray(obj, { sanitizer, ...options });
79
- return Object.fromEntries(
80
- Object.entries(obj).map(([key, value]) => [
81
- key,
82
- sanitize(value, { sanitizer, ...options })
83
- ])
84
- );
85
- }
86
- export {
87
- flattenArrayFields,
88
- formDataToObject,
89
- sanitize,
90
- sanitizeArray,
91
- sanitizeObject
92
- };
1
+ export * from "./form-data.js";
2
+ export * from "./sanitize.js";
@@ -1,4 +1,3 @@
1
- // src/lib/form/sanitize.js
2
1
  function sanitize(value, options = {}) {
3
2
  const { sanitizer, ...rest } = options;
4
3
  if (!sanitizer) throw new Error("sanitizer function is required");
@@ -1,4 +1,3 @@
1
- // src/lib/functions/callback.js
2
1
  function runCallback(fn, ...data) {
3
2
  if (typeof fn === "function") fn(data);
4
3
  }
@@ -1,4 +1,3 @@
1
- // src/lib/functions/debounce.js
2
1
  function debounce(callback, wait, immediate = false) {
3
2
  let timeout;
4
3
  return function() {
@@ -1,4 +1,3 @@
1
- // src/lib/functions/env.js
2
1
  function getEnv() {
3
2
  if (typeof window === "object") return "browser";
4
3
  if (typeof global === "object") return "node";
@@ -1,4 +1,3 @@
1
- // src/lib/functions/functional.js
2
1
  function curry(fn) {
3
2
  return function curried(...args) {
4
3
  if (args.length >= fn.length) {