@splendidlabz/utils 1.10.1 → 1.10.3

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 (201) hide show
  1. package/CHANGELOG.md +12 -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/common.cjs +0 -2
  93. package/dist/cjs/node/dirname.cjs +2 -4
  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 +15 -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/esm/dom/accessibility.js +0 -1
  102. package/dist/esm/dom/actions/index.js +3 -381
  103. package/dist/esm/dom/actions/masonry.js +3 -91
  104. package/dist/esm/dom/actions/prefer-horizontal-scroll.js +4 -45
  105. package/dist/esm/dom/actions/sticky.js +3 -120
  106. package/dist/esm/dom/bounding-box.js +0 -1
  107. package/dist/esm/dom/clipboard.js +0 -1
  108. package/dist/esm/dom/cookie.js +1 -2
  109. package/dist/esm/dom/css-vars.js +1 -8
  110. package/dist/esm/dom/events.js +0 -1
  111. package/dist/esm/dom/focusable.js +0 -1
  112. package/dist/esm/dom/font-size.js +1 -10
  113. package/dist/esm/dom/get-element.js +1 -2
  114. package/dist/esm/dom/hash.js +0 -1
  115. package/dist/esm/dom/index.js +23 -1168
  116. package/dist/esm/dom/keyboard.js +0 -1
  117. package/dist/esm/dom/local-store.js +1 -2
  118. package/dist/esm/dom/media.js +0 -1
  119. package/dist/esm/dom/observers/index.js +4 -224
  120. package/dist/esm/dom/observers/intersection-observer.js +2 -31
  121. package/dist/esm/dom/observers/mutation-observer.js +3 -32
  122. package/dist/esm/dom/observers/observer.js +1 -8
  123. package/dist/esm/dom/observers/resize-observer.js +2 -31
  124. package/dist/esm/dom/observers/scroll-observer.js +2 -58
  125. package/dist/esm/dom/pkce.js +1 -8
  126. package/dist/esm/dom/query-params.js +1 -2
  127. package/dist/esm/dom/random-string.js +0 -1
  128. package/dist/esm/dom/sanitize.js +3 -26
  129. package/dist/esm/dom/session-store.js +1 -2
  130. package/dist/esm/dom/spam-prevention.js +0 -1
  131. package/dist/esm/dom/trap-focus.js +2 -121
  132. package/dist/esm/dom/ui/aria-current.js +0 -1
  133. package/dist/esm/dom/ui/inconsistent-button-fix.js +0 -1
  134. package/dist/esm/dom/ui/index.js +4 -75
  135. package/dist/esm/dom/ui/scroll-container.js +0 -1
  136. package/dist/esm/dom/ui/traverse-and-scramble.js +0 -1
  137. package/dist/esm/lib/arrays/index.js +6 -106
  138. package/dist/esm/lib/arrays/item-position.js +0 -1
  139. package/dist/esm/lib/arrays/join.js +1 -6
  140. package/dist/esm/lib/arrays/shuffle.js +0 -1
  141. package/dist/esm/lib/arrays/sort.js +1 -6
  142. package/dist/esm/lib/arrays/split-array.js +0 -1
  143. package/dist/esm/lib/arrays/unique.js +0 -1
  144. package/dist/esm/lib/auth/index.js +1 -26
  145. package/dist/esm/lib/auth/route-manager.js +0 -1
  146. package/dist/esm/lib/checks.js +0 -1
  147. package/dist/esm/lib/date/days.js +1 -2
  148. package/dist/esm/lib/date/index.js +3 -173
  149. package/dist/esm/lib/date/months.js +1 -2
  150. package/dist/esm/lib/date/time.js +1 -10
  151. package/dist/esm/lib/form/form-data.js +0 -1
  152. package/dist/esm/lib/form/index.js +2 -92
  153. package/dist/esm/lib/form/sanitize.js +0 -1
  154. package/dist/esm/lib/functions/callback.js +0 -1
  155. package/dist/esm/lib/functions/debounce.js +0 -1
  156. package/dist/esm/lib/functions/env.js +0 -1
  157. package/dist/esm/lib/functions/functional.js +0 -1
  158. package/dist/esm/lib/functions/index.js +5 -105
  159. package/dist/esm/lib/functions/throttle.js +0 -1
  160. package/dist/esm/lib/functions/timeout.js +0 -1
  161. package/dist/esm/lib/hash.js +0 -1
  162. package/dist/esm/lib/index.js +14 -1052
  163. package/dist/esm/lib/numbers/index.js +2 -12
  164. package/dist/esm/lib/numbers/math.js +0 -1
  165. package/dist/esm/lib/objects/camelcase-keys.js +2 -40
  166. package/dist/esm/lib/objects/empty.js +0 -1
  167. package/dist/esm/lib/objects/equal.js +0 -1
  168. package/dist/esm/lib/objects/extend.js +3 -111
  169. package/dist/esm/lib/objects/flatten.js +1 -6
  170. package/dist/esm/lib/objects/index.js +13 -323
  171. package/dist/esm/lib/objects/json.js +0 -1
  172. package/dist/esm/lib/objects/loop.js +0 -1
  173. package/dist/esm/lib/objects/mix/mix.js +3 -4
  174. package/dist/esm/lib/objects/nested-property.js +0 -1
  175. package/dist/esm/lib/objects/normalize-object.js +3 -74
  176. package/dist/esm/lib/objects/omit-empty.js +0 -1
  177. package/dist/esm/lib/objects/size.js +0 -1
  178. package/dist/esm/lib/objects/split.js +0 -1
  179. package/dist/esm/lib/promises/index.js +1 -33
  180. package/dist/esm/lib/promises/reject.js +1 -17
  181. package/dist/esm/lib/sse.js +2 -24
  182. package/dist/esm/lib/strings/convert-case/convert-case.js +0 -1
  183. package/dist/esm/lib/strings/index.js +5 -147
  184. package/dist/esm/lib/strings/markdown.js +1 -2
  185. package/dist/esm/lib/strings/name.js +0 -1
  186. package/dist/esm/lib/strings/pluralize.js +1 -2
  187. package/dist/esm/lib/strings/query-string.js +0 -1
  188. package/dist/esm/lib/style/index.js +1 -27
  189. package/dist/esm/lib/symbols/index.js +1 -13
  190. package/dist/esm/lib/symbols/symbols.js +0 -1
  191. package/dist/esm/node/common.js +0 -1
  192. package/dist/esm/node/dirname.js +2 -3
  193. package/dist/esm/node/file-cache.js +2 -43
  194. package/dist/esm/node/file.js +2 -3
  195. package/dist/esm/node/hash.js +1 -2
  196. package/dist/esm/node/index.js +7 -243
  197. package/dist/esm/node/pkce.js +3 -12
  198. package/dist/esm/node/random-string.js +1 -2
  199. package/dist/esm/node/sanitize.js +3 -26
  200. package/package.json +1 -1
  201. package/tsup.config.mjs +2 -0
@@ -1,33 +1 @@
1
- // src/lib/promises/reject.js
2
- import statuses from "statuses";
3
-
4
- // src/lib/objects/omit-empty.js
5
- function omitEmpty(obj, shallow = false) {
6
- if (typeof obj !== "object" || obj === null) return obj;
7
- if (obj instanceof Date) return obj;
8
- const result = Array.isArray(obj) ? [] : {};
9
- for (const [key, value] of Object.entries(obj)) {
10
- if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
11
- continue;
12
- }
13
- result[key] = shallow ? value : omitEmpty(value);
14
- }
15
- return result;
16
- }
17
-
18
- // src/lib/promises/reject.js
19
- function reject(props, { includeStack = true } = {}) {
20
- const { status, statusText, body, message } = props;
21
- const e = new Error();
22
- const err = {
23
- status,
24
- statusText: statusText || status && statuses(status),
25
- body,
26
- message,
27
- stack: includeStack && e.stack
28
- };
29
- return Promise.reject(omitEmpty(err));
30
- }
31
- export {
32
- reject
33
- };
1
+ export * from "./reject.js";
@@ -1,21 +1,5 @@
1
- // src/lib/promises/reject.js
2
1
  import statuses from "statuses";
3
-
4
- // src/lib/objects/omit-empty.js
5
- function omitEmpty(obj, shallow = false) {
6
- if (typeof obj !== "object" || obj === null) return obj;
7
- if (obj instanceof Date) return obj;
8
- const result = Array.isArray(obj) ? [] : {};
9
- for (const [key, value] of Object.entries(obj)) {
10
- if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
11
- continue;
12
- }
13
- result[key] = shallow ? value : omitEmpty(value);
14
- }
15
- return result;
16
- }
17
-
18
- // src/lib/promises/reject.js
2
+ import { omitEmpty } from "../objects/omit-empty.js";
19
3
  function reject(props, { includeStack = true } = {}) {
20
4
  const { status, statusText, body, message } = props;
21
5
  const e = new Error();
@@ -1,27 +1,5 @@
1
- // src/lib/objects/json.js
2
- function parseJSON(value, defaultValue = {}) {
3
- try {
4
- return JSON.parse(value);
5
- } catch (e) {
6
- return defaultValue;
7
- }
8
- }
9
-
10
- // src/lib/objects/omit-empty.js
11
- function omitEmpty(obj, shallow = false) {
12
- if (typeof obj !== "object" || obj === null) return obj;
13
- if (obj instanceof Date) return obj;
14
- const result = Array.isArray(obj) ? [] : {};
15
- for (const [key, value] of Object.entries(obj)) {
16
- if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
17
- continue;
18
- }
19
- result[key] = shallow ? value : omitEmpty(value);
20
- }
21
- return result;
22
- }
23
-
24
- // src/lib/sse.js
1
+ import { parseJSON } from "./objects/json.js";
2
+ import { omitEmpty } from "./objects/omit-empty.js";
25
3
  function createSSE({ event, data, id, retry }) {
26
4
  const eventString = event ? `event: ${event}
27
5
  ` : "";
@@ -1,4 +1,3 @@
1
- // src/lib/strings/convert-case/convert-case.js
2
1
  function toKebab(string) {
3
2
  if (!string) return "";
4
3
  return string.split("").map((letter, index) => {
@@ -1,147 +1,5 @@
1
- // src/lib/strings/convert-case/convert-case.js
2
- function toKebab(string) {
3
- if (!string) return "";
4
- return string.split("").map((letter, index) => {
5
- const previousLetter = string[index - 1] || "";
6
- const currentLetter = letter;
7
- if (isDigit(currentLetter) && !isDigit(previousLetter)) {
8
- return `-${currentLetter}`;
9
- }
10
- if (!isCaps(currentLetter)) return currentLetter;
11
- if (previousLetter === "") {
12
- return `${currentLetter.toLowerCase()}`;
13
- }
14
- if (isCaps(previousLetter)) {
15
- return `${currentLetter.toLowerCase()}`;
16
- }
17
- return `-${currentLetter.toLowerCase()}`;
18
- }).join("").trim().replace(/[-_\s]+/g, "-");
19
- }
20
- function toCamel(string) {
21
- return toKebab(string).split("-").map((word, index) => {
22
- if (index === 0) return word;
23
- return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
24
- }).join("");
25
- }
26
- function toPascal(string) {
27
- const camel = toCamel(string);
28
- return camel.slice(0, 1).toUpperCase() + camel.slice(1);
29
- }
30
- function toTitle(string) {
31
- return toKebab(string).split("-").map((word) => {
32
- return word.slice(0, 1).toUpperCase() + word.slice(1);
33
- }).join(" ");
34
- }
35
- function toSlug(string) {
36
- return toKebab(string);
37
- }
38
- function toSentence(string) {
39
- const interim = toKebab(string).replace(/-/g, " ");
40
- return interim.slice(0, 1).toUpperCase() + interim.slice(1);
41
- }
42
- function toUpper(string) {
43
- const interim = toKebab(string).replace(/-/g, " ");
44
- return interim.toUpperCase();
45
- }
46
- function toLower(string) {
47
- const interim = toKebab(string).replace(/-/g, " ");
48
- return interim.toLowerCase();
49
- }
50
- function isCaps(char) {
51
- return /\p{Lu}/u.test(char);
52
- }
53
- function isDigit(char) {
54
- return /[0-9]/.test(char);
55
- }
56
-
57
- // src/lib/strings/markdown.js
58
- import markdownit from "markdown-it";
59
- import anchor from "markdown-it-anchor";
60
- var md = markdownit({
61
- html: true,
62
- linkify: true,
63
- typographer: true
64
- });
65
- md.use(anchor, {
66
- permalink: false,
67
- slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
68
- });
69
- function markdown(content, options = {}) {
70
- const defaultOptions = { inline: false };
71
- const opts = { ...defaultOptions, ...options };
72
- const { content: treated } = treatMarkdownWhitespace(content, opts);
73
- if (opts.inline) return md.renderInline(treated);
74
- return md.render(treated);
75
- }
76
- function treatMarkdownWhitespace(content, { inline } = {}) {
77
- if (!content) return { content: "", inline };
78
- const lines = content.split("\n");
79
- if (lines[0] !== "" && inline) return { content, inline: true };
80
- const firstLineWithLeadingSpacesIndex = lines.findIndex(
81
- (line) => line.match(/^\s+/)
82
- );
83
- const firstLineWithLeadingSpaces = lines[firstLineWithLeadingSpacesIndex];
84
- const indentation = firstLineWithLeadingSpaces?.match(/^\s+/)?.[0]?.length ?? 0;
85
- const retContent = lines.map((line, index) => {
86
- if (index < firstLineWithLeadingSpacesIndex) return line + "\n";
87
- return line.slice(indentation) + "\n";
88
- }).join("");
89
- return {
90
- content: retContent,
91
- inline
92
- };
93
- }
94
-
95
- // src/lib/strings/name.js
96
- function parseFullName(name) {
97
- const parts = name.trim().split(/\s+/);
98
- if (parts.length === 1) {
99
- return { firstName: parts[0], middleName: "", lastName: "" };
100
- }
101
- if (parts.length === 2) {
102
- return { firstName: parts[0], middleName: "", lastName: parts[1] };
103
- }
104
- if (parts.length === 3) {
105
- const firstName2 = parts.slice(0, 2).join(" ");
106
- const lastName2 = parts[2];
107
- return { firstName: firstName2, middleName: "", lastName: lastName2 };
108
- }
109
- const firstName = parts.slice(0, 2).join(" ");
110
- const lastName = parts[parts.length - 1];
111
- const middleName = parts.slice(2, -1).join(" ");
112
- return { firstName, middleName, lastName };
113
- }
114
-
115
- // src/lib/strings/pluralize.js
116
- import pluralizeLib from "pluralize";
117
- var pluralize = pluralizeLib;
118
-
119
- // src/lib/strings/query-string.js
120
- function toQueryString(object) {
121
- const searchParams = new URLSearchParams(object);
122
- return searchParams.toString();
123
- }
124
- function plural(count, noun, suffix = "s") {
125
- console.warn("plural is deprecated. Use pluralize instead");
126
- return `${count} ${noun}${count !== 1 ? suffix : ""}`;
127
- }
128
- function stripNumbers(string) {
129
- return string.replace(/\d*/, "");
130
- }
131
- export {
132
- markdown,
133
- parseFullName,
134
- plural,
135
- pluralize,
136
- stripNumbers,
137
- toCamel,
138
- toKebab,
139
- toLower,
140
- toPascal,
141
- toQueryString,
142
- toSentence,
143
- toSlug,
144
- toTitle,
145
- toUpper,
146
- treatMarkdownWhitespace
147
- };
1
+ export * from "./convert-case/convert-case.js";
2
+ export * from "./markdown.js";
3
+ export * from "./name.js";
4
+ export * from "./pluralize.js";
5
+ export * from "./query-string.js";
@@ -1,7 +1,6 @@
1
- // src/lib/strings/markdown.js
2
1
  import markdownit from "markdown-it";
3
2
  import anchor from "markdown-it-anchor";
4
- var md = markdownit({
3
+ const md = markdownit({
5
4
  html: true,
6
5
  linkify: true,
7
6
  typographer: true
@@ -1,4 +1,3 @@
1
- // src/lib/strings/name.js
2
1
  function parseFullName(name) {
3
2
  const parts = name.trim().split(/\s+/);
4
3
  if (parts.length === 1) {
@@ -1,6 +1,5 @@
1
- // src/lib/strings/pluralize.js
2
1
  import pluralizeLib from "pluralize";
3
- var pluralize = pluralizeLib;
2
+ const pluralize = pluralizeLib;
4
3
  export {
5
4
  pluralize
6
5
  };
@@ -1,4 +1,3 @@
1
- // src/lib/strings/query-string.js
2
1
  function toQueryString(object) {
3
2
  const searchParams = new URLSearchParams(object);
4
3
  return searchParams.toString();
@@ -1,30 +1,4 @@
1
- // src/lib/strings/convert-case/convert-case.js
2
- function toKebab(string) {
3
- if (!string) return "";
4
- return string.split("").map((letter, index) => {
5
- const previousLetter = string[index - 1] || "";
6
- const currentLetter = letter;
7
- if (isDigit(currentLetter) && !isDigit(previousLetter)) {
8
- return `-${currentLetter}`;
9
- }
10
- if (!isCaps(currentLetter)) return currentLetter;
11
- if (previousLetter === "") {
12
- return `${currentLetter.toLowerCase()}`;
13
- }
14
- if (isCaps(previousLetter)) {
15
- return `${currentLetter.toLowerCase()}`;
16
- }
17
- return `-${currentLetter.toLowerCase()}`;
18
- }).join("").trim().replace(/[-_\s]+/g, "-");
19
- }
20
- function isCaps(char) {
21
- return /\p{Lu}/u.test(char);
22
- }
23
- function isDigit(char) {
24
- return /[0-9]/.test(char);
25
- }
26
-
27
- // src/lib/style/index.js
1
+ import { toKebab } from "../strings/convert-case/convert-case.js";
28
2
  function toStyleString(style) {
29
3
  if (!style) return null;
30
4
  if (typeof style === "string") return style;
@@ -1,13 +1 @@
1
- // src/lib/symbols/symbols.js
2
- function getSymbol(object, description) {
3
- return Object.getOwnPropertySymbols(object).find(
4
- (s) => s.description === description
5
- );
6
- }
7
- function getSymbolValue(object, description) {
8
- return object[getSymbol(object, description)];
9
- }
10
- export {
11
- getSymbol,
12
- getSymbolValue
13
- };
1
+ export * from "./symbols.js";
@@ -1,4 +1,3 @@
1
- // src/lib/symbols/symbols.js
2
1
  function getSymbol(object, description) {
3
2
  return Object.getOwnPropertySymbols(object).find(
4
3
  (s) => s.description === description
@@ -1,4 +1,3 @@
1
- // src/node/common.js
2
1
  import crypto from "crypto";
3
2
  function uuid() {
4
3
  return crypto.randomUUID();
@@ -1,6 +1,5 @@
1
- // src/node/dirname.js
2
- import path from "path";
3
- import { fileURLToPath } from "url";
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
4
3
  function __dirname(url) {
5
4
  if (!url) throw Error("Please provide 'import.meta.url' to dirname");
6
5
  return path.dirname(fileURLToPath(url));
@@ -1,48 +1,7 @@
1
- // src/node/file-cache.js
2
1
  import fs from "fs/promises";
3
2
  import { glob } from "glob";
4
- import path from "path";
5
-
6
- // src/lib/objects/nested-property.js
7
- function getNestedValue(object, path2) {
8
- return path2.split(".").reduce((acc, part) => acc?.[part], object);
9
- }
10
-
11
- // src/lib/arrays/sort.js
12
- function sort(array, { props = null, reverse = false } = {}) {
13
- const clone = array.slice();
14
- if (props === null) {
15
- return clone.sort((a, b) => {
16
- const comparison = compareValues(a, b);
17
- return reverse ? -comparison : comparison;
18
- });
19
- }
20
- const properties = Array.isArray(props) ? props : [props];
21
- return clone.sort((a, b) => {
22
- for (const property of properties) {
23
- const aValue = getNestedValue(a, property);
24
- const bValue = getNestedValue(b, property);
25
- if (aValue === bValue) continue;
26
- if (aValue == null) return 1;
27
- if (bValue == null) return -1;
28
- const comparison = compareValues(aValue, bValue);
29
- return reverse ? -comparison : comparison;
30
- }
31
- return 0;
32
- });
33
- }
34
- function compareValues(a, b) {
35
- if (typeof a === "number" && typeof b === "number") return a - b;
36
- if (typeof a === "string" && typeof b === "string") return a.localeCompare(b);
37
- const aDate = new Date(a);
38
- const bDate = new Date(b);
39
- const aTime = aDate.getTime();
40
- const bTime = bDate.getTime();
41
- if (!isNaN(aTime) && !isNaN(bTime)) return aTime - bTime;
42
- return String(a).localeCompare(String(b));
43
- }
44
-
45
- // src/node/file-cache.js
3
+ import path from "node:path";
4
+ import { sort } from "../lib/arrays/index.js";
46
5
  async function createCache(dir) {
47
6
  const absDirpath = path.join(process.cwd(), dir);
48
7
  await fs.mkdir(absDirpath, { recursive: true });
@@ -1,6 +1,5 @@
1
- // src/node/file.js
2
- import fs from "fs/promises";
3
- import path from "path";
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
4
3
  async function mkdir(path2) {
5
4
  return fs.mkdir(path2, { recursive: true });
6
5
  }
@@ -1,5 +1,4 @@
1
- // src/node/hash.js
2
- import crypto from "crypto";
1
+ import crypto from "node:crypto";
3
2
  function sha256Hash(string) {
4
3
  return crypto.createHash("sha256").update(string).digest("hex");
5
4
  }
@@ -1,243 +1,7 @@
1
- // src/node/common.js
2
- import crypto from "crypto";
3
- function uuid() {
4
- return crypto.randomUUID();
5
- }
6
-
7
- // src/node/dirname.js
8
- import path from "path";
9
- import { fileURLToPath } from "url";
10
- function __dirname(url) {
11
- if (!url) throw Error("Please provide 'import.meta.url' to dirname");
12
- return path.dirname(fileURLToPath(url));
13
- }
14
- function dirname(url) {
15
- return __dirname(url);
16
- }
17
-
18
- // src/node/file-cache.js
19
- import fs from "fs/promises";
20
- import { glob } from "glob";
21
- import path2 from "path";
22
-
23
- // src/lib/objects/nested-property.js
24
- function getNestedValue(object, path3) {
25
- return path3.split(".").reduce((acc, part) => acc?.[part], object);
26
- }
27
-
28
- // src/lib/arrays/sort.js
29
- function sort(array, { props = null, reverse = false } = {}) {
30
- const clone = array.slice();
31
- if (props === null) {
32
- return clone.sort((a, b) => {
33
- const comparison = compareValues(a, b);
34
- return reverse ? -comparison : comparison;
35
- });
36
- }
37
- const properties = Array.isArray(props) ? props : [props];
38
- return clone.sort((a, b) => {
39
- for (const property of properties) {
40
- const aValue = getNestedValue(a, property);
41
- const bValue = getNestedValue(b, property);
42
- if (aValue === bValue) continue;
43
- if (aValue == null) return 1;
44
- if (bValue == null) return -1;
45
- const comparison = compareValues(aValue, bValue);
46
- return reverse ? -comparison : comparison;
47
- }
48
- return 0;
49
- });
50
- }
51
- function compareValues(a, b) {
52
- if (typeof a === "number" && typeof b === "number") return a - b;
53
- if (typeof a === "string" && typeof b === "string") return a.localeCompare(b);
54
- const aDate = new Date(a);
55
- const bDate = new Date(b);
56
- const aTime = aDate.getTime();
57
- const bTime = bDate.getTime();
58
- if (!isNaN(aTime) && !isNaN(bTime)) return aTime - bTime;
59
- return String(a).localeCompare(String(b));
60
- }
61
-
62
- // src/node/file-cache.js
63
- async function createCache(dir) {
64
- const absDirpath = path2.join(process.cwd(), dir);
65
- await fs.mkdir(absDirpath, { recursive: true });
66
- return {
67
- async cacheAt(file) {
68
- if (file) {
69
- const absFilepath = path2.join(absDirpath, file);
70
- try {
71
- const stat = await fs.stat(absFilepath);
72
- return stat.mtimeMs;
73
- } catch (error) {
74
- return 0;
75
- }
76
- } else {
77
- return getLastModifiedTime(dir + "/**/*");
78
- }
79
- },
80
- getAbsPath(file) {
81
- return path2.join(absDirpath, file);
82
- },
83
- async hasFile(file) {
84
- const absFilepath = path2.join(absDirpath, file);
85
- try {
86
- await fs.stat(absFilepath);
87
- return true;
88
- } catch (e) {
89
- return false;
90
- }
91
- },
92
- async loadFile(file) {
93
- try {
94
- const absFilepath = path2.join(absDirpath, file);
95
- return fs.readFile(absFilepath);
96
- } catch (error) {
97
- console.warn(`File not found: ${file}`);
98
- }
99
- },
100
- async saveFile(file, data) {
101
- const absfilepath = path2.join(absDirpath, file);
102
- await fs.writeFile(absfilepath, data);
103
- },
104
- async loadJSON(file) {
105
- const data = await this.loadFile(file);
106
- try {
107
- return JSON.parse(data.toString());
108
- } catch (err) {
109
- console.warn(`Error parsing JSON: ${file}`);
110
- return {};
111
- }
112
- },
113
- async saveJSON(file, data) {
114
- await this.saveFile(file, JSON.stringify(data));
115
- }
116
- };
117
- }
118
- async function fileCache({ dir, file }) {
119
- await fs.mkdir(path2.join(process.cwd(), dir), { recursive: true });
120
- const cachePath = path2.join(process.cwd(), dir, `${file}`);
121
- let modifiedAt = 0;
122
- try {
123
- const stat = await fs.stat(cachePath);
124
- modifiedAt = stat.mtimeMs;
125
- } catch (error) {
126
- }
127
- return {
128
- modifiedAt,
129
- async load() {
130
- return fs.readFile(cachePath);
131
- },
132
- async save(data) {
133
- await fs.writeFile(cachePath, data);
134
- },
135
- async loadJSON() {
136
- const data = await fs.readFile(cachePath);
137
- return JSON.parse(data.toString());
138
- },
139
- async saveJSON(data) {
140
- await fs.writeFile(cachePath, JSON.stringify(data));
141
- }
142
- };
143
- }
144
- async function getLastModifiedTime(globPath) {
145
- let files;
146
- if (typeof globPath === "string") {
147
- files = await glob(removeFirstSlash(globPath));
148
- }
149
- if (Array.isArray(globPath)) {
150
- const a = await Promise.all(
151
- globPath.map((path3) => glob(removeFirstSlash(path3)))
152
- );
153
- files = a.flat();
154
- }
155
- const stats = await Promise.all(files.map((file) => fs.stat(file)));
156
- const timestamps = stats.map((stat) => Number(stat.mtimeMs));
157
- const sorted = sort(timestamps, { props: "mtimeMs", reverse: true });
158
- return sorted[0] || 0;
159
- }
160
- async function getLatestModifiedTime(globPath) {
161
- console.warn(
162
- "`getLatestModifiedTime` has been renamed to `getLastModifiedTime` and will be deprecated in future versions. Please use `getLastModifiedTime` instead."
163
- );
164
- return getLastModifiedTime(globPath);
165
- }
166
- function removeFirstSlash(x) {
167
- return x.startsWith("/") ? x.slice(1) : x;
168
- }
169
-
170
- // src/node/hash.js
171
- import crypto2 from "crypto";
172
- function sha256Hash(string) {
173
- return crypto2.createHash("sha256").update(string).digest("hex");
174
- }
175
-
176
- // src/node/pkce.js
177
- import crypto4 from "crypto";
178
-
179
- // src/node/random-string.js
180
- import crypto3 from "crypto";
181
- function randomString(length = 32) {
182
- const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
183
- return crypto3.randomBytes(bytesNeeded).toString("base64").slice(0, length);
184
- }
185
-
186
- // src/node/pkce.js
187
- async function PKCE() {
188
- const codeVerifier = await randomString();
189
- const codeChallenge = await getCodeChallenge(codeVerifier);
190
- return {
191
- state: await randomString(),
192
- code_verifier: codeVerifier,
193
- code_challenge: codeChallenge,
194
- code_challenge_method: "S256"
195
- };
196
- }
197
- async function getCodeChallenge(verifier) {
198
- const hash = crypto4.createHash("sha256").update(verifier).digest();
199
- return hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
200
- }
201
-
202
- // src/node/sanitize.js
203
- import sanitizeHtml from "sanitize-html";
204
-
205
- // src/lib/form/sanitize.js
206
- function sanitize(value, options = {}) {
207
- const { sanitizer, ...rest } = options;
208
- if (!sanitizer) throw new Error("sanitizer function is required");
209
- if (typeof value === "string") return sanitizer(value, rest);
210
- if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
211
- if (value && typeof value === "object") {
212
- return Object.fromEntries(
213
- Object.entries(value).map(([key, val]) => [
214
- key,
215
- sanitize(val, { sanitizer, ...rest })
216
- ])
217
- );
218
- }
219
- return value;
220
- }
221
- function sanitizeArray(arr, { sanitizer, ...rest }) {
222
- if (!sanitizer) throw new Error("sanitizer function is required");
223
- return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
224
- }
225
-
226
- // src/node/sanitize.js
227
- function sanitize2(value, options = {}) {
228
- return sanitize(value, { sanitizer: sanitizeHtml, ...options });
229
- }
230
- export {
231
- PKCE,
232
- __dirname,
233
- createCache,
234
- dirname,
235
- fileCache,
236
- getLastModifiedTime,
237
- getLatestModifiedTime,
238
- randomString,
239
- removeFirstSlash,
240
- sanitize2 as sanitize,
241
- sha256Hash,
242
- uuid
243
- };
1
+ export * from "./common.js";
2
+ export * from "./dirname.js";
3
+ export * from "./file-cache.js";
4
+ export * from "./hash.js";
5
+ export * from "./pkce.js";
6
+ export * from "./random-string.js";
7
+ export * from "./sanitize.js";