@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,7 +1,13 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
5
11
  var __copyProps = (to, from, except, desc) => {
6
12
  if (from && typeof from === "object" || typeof from === "function") {
7
13
  for (let key of __getOwnPropNames(from))
@@ -10,24 +16,281 @@ var __copyProps = (to, from, except, desc) => {
10
16
  }
11
17
  return to;
12
18
  };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
14
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/node/index.js
15
30
  var node_exports = {};
31
+ __export(node_exports, {
32
+ PKCE: () => PKCE,
33
+ __dirname: () => __dirname,
34
+ createCache: () => createCache,
35
+ dirname: () => dirname,
36
+ fileCache: () => fileCache,
37
+ getCodeChallenge: () => getCodeChallenge,
38
+ getLastModifiedTime: () => getLastModifiedTime,
39
+ getLatestModifiedTime: () => getLatestModifiedTime,
40
+ randomString: () => randomString,
41
+ removeFirstSlash: () => removeFirstSlash,
42
+ sanitize: () => sanitize2,
43
+ sha256Hash: () => sha256Hash,
44
+ uuid: () => uuid
45
+ });
16
46
  module.exports = __toCommonJS(node_exports);
17
- __reExport(node_exports, require("./dirname.js"), module.exports);
18
- __reExport(node_exports, require("./file-cache.js"), module.exports);
19
- __reExport(node_exports, require("./hash.js"), module.exports);
20
- __reExport(node_exports, require("./pkce.js"), module.exports);
21
- __reExport(node_exports, require("./random-string.js"), module.exports);
22
- __reExport(node_exports, require("./sanitize.js"), module.exports);
23
- __reExport(node_exports, require("./uuid.js"), module.exports);
47
+
48
+ // src/node/dirname.js
49
+ var import_node_path = __toESM(require("path"), 1);
50
+ var import_node_url = require("url");
51
+ function __dirname(url) {
52
+ if (!url) throw Error("Please provide 'import.meta.url' to dirname");
53
+ return import_node_path.default.dirname((0, import_node_url.fileURLToPath)(url));
54
+ }
55
+ function dirname(url) {
56
+ return __dirname(url);
57
+ }
58
+
59
+ // src/node/file-cache.js
60
+ var import_promises = __toESM(require("fs/promises"), 1);
61
+ var import_glob = require("glob");
62
+ var import_node_path2 = __toESM(require("path"), 1);
63
+
64
+ // src/lib/objects/nested-property.js
65
+ function getNestedValue(object, path3) {
66
+ return path3.split(".").reduce((acc, part) => acc?.[part], object);
67
+ }
68
+
69
+ // src/lib/arrays/sort.js
70
+ function sort(array, { props = null, reverse = false } = {}) {
71
+ const clone = array.slice();
72
+ if (props === null) {
73
+ return clone.sort((a, b) => {
74
+ const comparison = compareValues(a, b);
75
+ return reverse ? -comparison : comparison;
76
+ });
77
+ }
78
+ const properties = Array.isArray(props) ? props : [props];
79
+ return clone.sort((a, b) => {
80
+ for (const property of properties) {
81
+ const aValue = getNestedValue(a, property);
82
+ const bValue = getNestedValue(b, property);
83
+ if (aValue === bValue) continue;
84
+ if (aValue == null) return 1;
85
+ if (bValue == null) return -1;
86
+ const comparison = compareValues(aValue, bValue);
87
+ return reverse ? -comparison : comparison;
88
+ }
89
+ return 0;
90
+ });
91
+ }
92
+ function compareValues(a, b) {
93
+ if (typeof a === "number" && typeof b === "number") return a - b;
94
+ if (typeof a === "string" && typeof b === "string") return a.localeCompare(b);
95
+ const aDate = new Date(a);
96
+ const bDate = new Date(b);
97
+ const aTime = aDate.getTime();
98
+ const bTime = bDate.getTime();
99
+ if (!isNaN(aTime) && !isNaN(bTime)) return aTime - bTime;
100
+ return String(a).localeCompare(String(b));
101
+ }
102
+
103
+ // src/node/file-cache.js
104
+ function resolveDirPath(dirPath) {
105
+ return import_node_path2.default.isAbsolute(dirPath) ? dirPath : import_node_path2.default.join(process.cwd(), dirPath);
106
+ }
107
+ async function createCache(dir) {
108
+ const absDirpath = resolveDirPath(dir);
109
+ await import_promises.default.mkdir(absDirpath, { recursive: true });
110
+ return {
111
+ async cacheAt(file) {
112
+ if (file) {
113
+ const absFilepath = import_node_path2.default.join(absDirpath, file);
114
+ try {
115
+ const stat = await import_promises.default.stat(absFilepath);
116
+ return stat.mtimeMs;
117
+ } catch (error) {
118
+ return 0;
119
+ }
120
+ } else {
121
+ return getLastModifiedTime(absDirpath + "/**/*");
122
+ }
123
+ },
124
+ getAbsPath(file) {
125
+ return import_node_path2.default.join(absDirpath, file);
126
+ },
127
+ async hasFile(file) {
128
+ const absFilepath = import_node_path2.default.join(absDirpath, file);
129
+ try {
130
+ await import_promises.default.stat(absFilepath);
131
+ return true;
132
+ } catch (e) {
133
+ return false;
134
+ }
135
+ },
136
+ async loadFile(file) {
137
+ try {
138
+ const absFilepath = import_node_path2.default.join(absDirpath, file);
139
+ return import_promises.default.readFile(absFilepath);
140
+ } catch (error) {
141
+ console.warn(`File not found: ${file}`);
142
+ }
143
+ },
144
+ async saveFile(file, data) {
145
+ const absfilepath = import_node_path2.default.join(absDirpath, file);
146
+ await import_promises.default.writeFile(absfilepath, data);
147
+ },
148
+ async loadJSON(file) {
149
+ const data = await this.loadFile(file);
150
+ try {
151
+ return JSON.parse(data.toString());
152
+ } catch (err) {
153
+ console.warn(`Error parsing JSON: ${file}`);
154
+ return {};
155
+ }
156
+ },
157
+ async saveJSON(file, data) {
158
+ await this.saveFile(file, JSON.stringify(data));
159
+ }
160
+ };
161
+ }
162
+ async function fileCache({ dir, file }) {
163
+ const absDirpath = resolveDirPath(dir);
164
+ await import_promises.default.mkdir(absDirpath, { recursive: true });
165
+ const cachePath = import_node_path2.default.join(absDirpath, `${file}`);
166
+ let modifiedAt = 0;
167
+ try {
168
+ const stat = await import_promises.default.stat(cachePath);
169
+ modifiedAt = stat.mtimeMs;
170
+ } catch (error) {
171
+ }
172
+ return {
173
+ modifiedAt,
174
+ async load() {
175
+ return import_promises.default.readFile(cachePath);
176
+ },
177
+ async save(data) {
178
+ await import_promises.default.writeFile(cachePath, data);
179
+ },
180
+ async loadJSON() {
181
+ const data = await import_promises.default.readFile(cachePath);
182
+ return JSON.parse(data.toString());
183
+ },
184
+ async saveJSON(data) {
185
+ await import_promises.default.writeFile(cachePath, JSON.stringify(data));
186
+ }
187
+ };
188
+ }
189
+ async function getLastModifiedTime(globPath) {
190
+ let files;
191
+ if (typeof globPath === "string") {
192
+ files = await (0, import_glob.glob)(removeFirstSlash(globPath));
193
+ }
194
+ if (Array.isArray(globPath)) {
195
+ const a = await Promise.all(
196
+ globPath.map((path3) => (0, import_glob.glob)(removeFirstSlash(path3)))
197
+ );
198
+ files = a.flat();
199
+ }
200
+ const stats = await Promise.all(files.map((file) => import_promises.default.stat(file)));
201
+ const timestamps = stats.map((stat) => Number(stat.mtimeMs));
202
+ const sorted = sort(timestamps, { props: "mtimeMs", reverse: true });
203
+ return sorted[0] || 0;
204
+ }
205
+ async function getLatestModifiedTime(globPath) {
206
+ console.warn(
207
+ "`getLatestModifiedTime` has been renamed to `getLastModifiedTime` and will be deprecated in future versions. Please use `getLastModifiedTime` instead."
208
+ );
209
+ return getLastModifiedTime(globPath);
210
+ }
211
+ function removeFirstSlash(x) {
212
+ return x.startsWith("/") ? x.slice(1) : x;
213
+ }
214
+
215
+ // src/node/hash.js
216
+ var import_node_crypto = __toESM(require("crypto"), 1);
217
+ function sha256Hash(string) {
218
+ return import_node_crypto.default.createHash("sha256").update(string).digest("hex");
219
+ }
220
+
221
+ // src/node/pkce.js
222
+ var import_node_crypto3 = __toESM(require("crypto"), 1);
223
+
224
+ // src/node/random-string.js
225
+ var import_node_crypto2 = __toESM(require("crypto"), 1);
226
+ function randomString(length = 32) {
227
+ const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
228
+ return import_node_crypto2.default.randomBytes(bytesNeeded).toString("base64").slice(0, length);
229
+ }
230
+
231
+ // src/node/pkce.js
232
+ async function PKCE() {
233
+ const codeVerifier = await randomString();
234
+ const codeChallenge = await getCodeChallenge(codeVerifier);
235
+ return {
236
+ state: await randomString(),
237
+ code_verifier: codeVerifier,
238
+ code_challenge: codeChallenge,
239
+ code_challenge_method: "S256"
240
+ };
241
+ }
242
+ function getCodeChallenge(verifier) {
243
+ const hash = import_node_crypto3.default.createHash("sha256").update(verifier).digest();
244
+ return hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
245
+ }
246
+
247
+ // src/node/sanitize.js
248
+ var import_sanitize_html = __toESM(require("sanitize-html"), 1);
249
+
250
+ // src/lib/form/sanitize.js
251
+ function sanitize(value, options = {}) {
252
+ const { sanitizer, ...rest } = options;
253
+ if (!sanitizer) throw new Error("sanitizer function is required");
254
+ if (typeof value === "string") return sanitizer(value, rest);
255
+ if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
256
+ if (value && typeof value === "object") {
257
+ return Object.fromEntries(
258
+ Object.entries(value).map(([key, val]) => [
259
+ key,
260
+ sanitize(val, { sanitizer, ...rest })
261
+ ])
262
+ );
263
+ }
264
+ return value;
265
+ }
266
+ function sanitizeArray(arr, { sanitizer, ...rest }) {
267
+ if (!sanitizer) throw new Error("sanitizer function is required");
268
+ return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
269
+ }
270
+
271
+ // src/node/sanitize.js
272
+ function sanitize2(value, options = {}) {
273
+ return sanitize(value, { sanitizer: import_sanitize_html.default, ...options });
274
+ }
275
+
276
+ // src/node/uuid.js
277
+ var import_crypto = __toESM(require("crypto"), 1);
278
+ function uuid() {
279
+ return import_crypto.default.randomUUID();
280
+ }
24
281
  // Annotate the CommonJS export names for ESM import in node:
25
282
  0 && (module.exports = {
26
- ...require("./dirname.js"),
27
- ...require("./file-cache.js"),
28
- ...require("./hash.js"),
29
- ...require("./pkce.js"),
30
- ...require("./random-string.js"),
31
- ...require("./sanitize.js"),
32
- ...require("./uuid.js")
283
+ PKCE,
284
+ __dirname,
285
+ createCache,
286
+ dirname,
287
+ fileCache,
288
+ getCodeChallenge,
289
+ getLastModifiedTime,
290
+ getLatestModifiedTime,
291
+ randomString,
292
+ removeFirstSlash,
293
+ sanitize,
294
+ sha256Hash,
295
+ uuid
33
296
  });
@@ -25,28 +25,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  mod
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/node/pkce.js
28
30
  var pkce_exports = {};
29
31
  __export(pkce_exports, {
30
- PKCE: () => PKCE
32
+ PKCE: () => PKCE,
33
+ getCodeChallenge: () => getCodeChallenge
31
34
  });
32
35
  module.exports = __toCommonJS(pkce_exports);
33
- var import_node_crypto = __toESM(require("node:crypto"), 1);
34
- var import_random_string = require("./random-string.js");
36
+ var import_node_crypto2 = __toESM(require("crypto"), 1);
37
+
38
+ // src/node/random-string.js
39
+ var import_node_crypto = __toESM(require("crypto"), 1);
40
+ function randomString(length = 32) {
41
+ const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
42
+ return import_node_crypto.default.randomBytes(bytesNeeded).toString("base64").slice(0, length);
43
+ }
44
+
45
+ // src/node/pkce.js
35
46
  async function PKCE() {
36
- const codeVerifier = await (0, import_random_string.randomString)();
47
+ const codeVerifier = await randomString();
37
48
  const codeChallenge = await getCodeChallenge(codeVerifier);
38
49
  return {
39
- state: await (0, import_random_string.randomString)(),
50
+ state: await randomString(),
40
51
  code_verifier: codeVerifier,
41
52
  code_challenge: codeChallenge,
42
53
  code_challenge_method: "S256"
43
54
  };
44
55
  }
45
- async function getCodeChallenge(verifier) {
46
- const hash = import_node_crypto.default.createHash("sha256").update(verifier).digest();
56
+ function getCodeChallenge(verifier) {
57
+ const hash = import_node_crypto2.default.createHash("sha256").update(verifier).digest();
47
58
  return hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
48
59
  }
49
60
  // Annotate the CommonJS export names for ESM import in node:
50
61
  0 && (module.exports = {
51
- PKCE
62
+ PKCE,
63
+ getCodeChallenge
52
64
  });
@@ -25,12 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  mod
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/node/random-string.js
28
30
  var random_string_exports = {};
29
31
  __export(random_string_exports, {
30
32
  randomString: () => randomString
31
33
  });
32
34
  module.exports = __toCommonJS(random_string_exports);
33
- var import_node_crypto = __toESM(require("node:crypto"), 1);
35
+ var import_node_crypto = __toESM(require("crypto"), 1);
34
36
  function randomString(length = 32) {
35
37
  const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
36
38
  return import_node_crypto.default.randomBytes(bytesNeeded).toString("base64").slice(0, length);
@@ -25,15 +25,39 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  mod
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/node/sanitize.js
28
30
  var sanitize_exports = {};
29
31
  __export(sanitize_exports, {
30
- sanitize: () => sanitize
32
+ sanitize: () => sanitize2
31
33
  });
32
34
  module.exports = __toCommonJS(sanitize_exports);
33
35
  var import_sanitize_html = __toESM(require("sanitize-html"), 1);
34
- var import_sanitize = require("../lib/form/sanitize.js");
36
+
37
+ // src/lib/form/sanitize.js
35
38
  function sanitize(value, options = {}) {
36
- return (0, import_sanitize.sanitize)(value, { sanitizer: import_sanitize_html.default, ...options });
39
+ const { sanitizer, ...rest } = options;
40
+ if (!sanitizer) throw new Error("sanitizer function is required");
41
+ if (typeof value === "string") return sanitizer(value, rest);
42
+ if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
43
+ if (value && typeof value === "object") {
44
+ return Object.fromEntries(
45
+ Object.entries(value).map(([key, val]) => [
46
+ key,
47
+ sanitize(val, { sanitizer, ...rest })
48
+ ])
49
+ );
50
+ }
51
+ return value;
52
+ }
53
+ function sanitizeArray(arr, { sanitizer, ...rest }) {
54
+ if (!sanitizer) throw new Error("sanitizer function is required");
55
+ return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
56
+ }
57
+
58
+ // src/node/sanitize.js
59
+ function sanitize2(value, options = {}) {
60
+ return sanitize(value, { sanitizer: import_sanitize_html.default, ...options });
37
61
  }
38
62
  // Annotate the CommonJS export names for ESM import in node:
39
63
  0 && (module.exports = {
@@ -25,6 +25,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  mod
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/node/uuid.js
28
30
  var uuid_exports = {};
29
31
  __export(uuid_exports, {
30
32
  uuid: () => uuid
File without changes
@@ -1,7 +1,7 @@
1
1
  import fs from "fs/promises";
2
2
  import { glob } from "glob";
3
3
  import path from "node:path";
4
- import { sort } from "../lib/arrays/index.js";
4
+ import { sort } from "../lib/arrays/sort.js";
5
5
  function resolveDirPath(dirPath) {
6
6
  return path.isAbsolute(dirPath) ? dirPath : path.join(process.cwd(), dirPath);
7
7
  }
@@ -10,10 +10,11 @@ async function PKCE() {
10
10
  code_challenge_method: "S256"
11
11
  };
12
12
  }
13
- async function getCodeChallenge(verifier) {
13
+ function getCodeChallenge(verifier) {
14
14
  const hash = crypto.createHash("sha256").update(verifier).digest();
15
15
  return hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
16
16
  }
17
17
  export {
18
- PKCE
18
+ PKCE,
19
+ getCodeChallenge
19
20
  };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -1,7 +1,7 @@
1
1
  export { __dirname, dirname } from './dirname.cjs';
2
2
  export { createCache, fileCache, getLastModifiedTime, getLatestModifiedTime, removeFirstSlash } from './file-cache.cjs';
3
3
  export { sha256Hash } from './hash.cjs';
4
- export { PKCE } from './pkce.cjs';
4
+ export { PKCE, getCodeChallenge } from './pkce.cjs';
5
5
  export { randomString } from './random-string.cjs';
6
6
  export { sanitize } from './sanitize.cjs';
7
7
  export { uuid } from './uuid.cjs';
@@ -4,5 +4,11 @@ declare function PKCE(): Promise<{
4
4
  code_challenge: string;
5
5
  code_challenge_method: string;
6
6
  }>;
7
+ /**
8
+ * Generates code challenge in node
9
+ * @param {string} verifier
10
+ * @returns string
11
+ */
12
+ declare function getCodeChallenge(verifier: string): string;
7
13
 
8
- export { PKCE };
14
+ export { PKCE, getCodeChallenge };
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@splendidlabz/utils",
3
- "version": "1.11.2",
3
+ "version": "1.11.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "homepage": "https://splendidlabz.com/docs/utils",
7
7
  "sideEffects": false,
8
+ "files": [
9
+ "dist"
10
+ ],
8
11
  "main": "./dist/cjs/lib/index.cjs",
9
12
  "module": "./dist/esm/lib/index.js",
10
13
  "types": "./dist/types/lib/index.d.cts",
@@ -66,7 +69,7 @@
66
69
  "statuses": "^2.0.1"
67
70
  },
68
71
  "devDependencies": {
69
- "@splendidlabz/eslint-config": "2.1.0",
72
+ "@splendidlabz/eslint-config": "2.1.3",
70
73
  "jsdom": "^26.0.0",
71
74
  "np": "^10.2.0",
72
75
  "tsup": "^8.0.0",