@baseplate-dev/utils 0.1.1

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 (195) hide show
  1. package/LICENSE +390 -0
  2. package/README.md +3 -0
  3. package/dist/crypto/hash.d.ts +2 -0
  4. package/dist/crypto/hash.d.ts.map +1 -0
  5. package/dist/crypto/hash.js +14 -0
  6. package/dist/crypto/hash.js.map +1 -0
  7. package/dist/crypto/index.d.ts +2 -0
  8. package/dist/crypto/index.d.ts.map +1 -0
  9. package/dist/crypto/index.js +2 -0
  10. package/dist/crypto/index.js.map +1 -0
  11. package/dist/errors/enhance-error-with-context.d.ts +9 -0
  12. package/dist/errors/enhance-error-with-context.d.ts.map +1 -0
  13. package/dist/errors/enhance-error-with-context.js +19 -0
  14. package/dist/errors/enhance-error-with-context.js.map +1 -0
  15. package/dist/errors/index.d.ts +2 -0
  16. package/dist/errors/index.d.ts.map +1 -0
  17. package/dist/errors/index.js +2 -0
  18. package/dist/errors/index.js.map +1 -0
  19. package/dist/events/index.d.ts +2 -0
  20. package/dist/events/index.d.ts.map +1 -0
  21. package/dist/events/index.js +2 -0
  22. package/dist/events/index.js.map +1 -0
  23. package/dist/events/typed-event-emitter.d.ts +64 -0
  24. package/dist/events/typed-event-emitter.d.ts.map +1 -0
  25. package/dist/events/typed-event-emitter.js +128 -0
  26. package/dist/events/typed-event-emitter.js.map +1 -0
  27. package/dist/field-map/field-map.d.ts +118 -0
  28. package/dist/field-map/field-map.d.ts.map +1 -0
  29. package/dist/field-map/field-map.js +287 -0
  30. package/dist/field-map/field-map.js.map +1 -0
  31. package/dist/field-map/index.d.ts +2 -0
  32. package/dist/field-map/index.d.ts.map +1 -0
  33. package/dist/field-map/index.js +2 -0
  34. package/dist/field-map/index.js.map +1 -0
  35. package/dist/fs/dir-exists.d.ts +7 -0
  36. package/dist/fs/dir-exists.d.ts.map +1 -0
  37. package/dist/fs/dir-exists.js +12 -0
  38. package/dist/fs/dir-exists.js.map +1 -0
  39. package/dist/fs/ensure-dir.d.ts +6 -0
  40. package/dist/fs/ensure-dir.d.ts.map +1 -0
  41. package/dist/fs/ensure-dir.js +9 -0
  42. package/dist/fs/ensure-dir.js.map +1 -0
  43. package/dist/fs/file-exists.d.ts +7 -0
  44. package/dist/fs/file-exists.d.ts.map +1 -0
  45. package/dist/fs/file-exists.js +12 -0
  46. package/dist/fs/file-exists.js.map +1 -0
  47. package/dist/fs/find-nearest-package-json.d.ts +22 -0
  48. package/dist/fs/find-nearest-package-json.d.ts.map +1 -0
  49. package/dist/fs/find-nearest-package-json.js +34 -0
  50. package/dist/fs/find-nearest-package-json.js.map +1 -0
  51. package/dist/fs/handle-not-found-error.d.ts +9 -0
  52. package/dist/fs/handle-not-found-error.d.ts.map +1 -0
  53. package/dist/fs/handle-not-found-error.js +15 -0
  54. package/dist/fs/handle-not-found-error.js.map +1 -0
  55. package/dist/fs/index.d.ts +9 -0
  56. package/dist/fs/index.d.ts.map +1 -0
  57. package/dist/fs/index.js +9 -0
  58. package/dist/fs/index.js.map +1 -0
  59. package/dist/fs/read-json-with-schema.d.ts +10 -0
  60. package/dist/fs/read-json-with-schema.d.ts.map +1 -0
  61. package/dist/fs/read-json-with-schema.js +29 -0
  62. package/dist/fs/read-json-with-schema.js.map +1 -0
  63. package/dist/fs/write-json.d.ts +7 -0
  64. package/dist/fs/write-json.d.ts.map +1 -0
  65. package/dist/fs/write-json.js +10 -0
  66. package/dist/fs/write-json.js.map +1 -0
  67. package/dist/fs/write-stable-pretty-json.d.ts +10 -0
  68. package/dist/fs/write-stable-pretty-json.d.ts.map +1 -0
  69. package/dist/fs/write-stable-pretty-json.js +15 -0
  70. package/dist/fs/write-stable-pretty-json.js.map +1 -0
  71. package/dist/index.d.ts +13 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +13 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/json/index.d.ts +3 -0
  76. package/dist/json/index.d.ts.map +1 -0
  77. package/dist/json/index.js +3 -0
  78. package/dist/json/index.js.map +1 -0
  79. package/dist/json/stringify-pretty-compact.d.ts +11 -0
  80. package/dist/json/stringify-pretty-compact.d.ts.map +1 -0
  81. package/dist/json/stringify-pretty-compact.js +127 -0
  82. package/dist/json/stringify-pretty-compact.js.map +1 -0
  83. package/dist/json/stringify-pretty-stable.d.ts +10 -0
  84. package/dist/json/stringify-pretty-stable.d.ts.map +1 -0
  85. package/dist/json/stringify-pretty-stable.js +17 -0
  86. package/dist/json/stringify-pretty-stable.js.map +1 -0
  87. package/dist/maps/group-by.d.ts +13 -0
  88. package/dist/maps/group-by.d.ts.map +1 -0
  89. package/dist/maps/group-by.js +26 -0
  90. package/dist/maps/group-by.js.map +1 -0
  91. package/dist/maps/index.d.ts +5 -0
  92. package/dist/maps/index.d.ts.map +1 -0
  93. package/dist/maps/index.js +5 -0
  94. package/dist/maps/index.js.map +1 -0
  95. package/dist/maps/key-by.d.ts +14 -0
  96. package/dist/maps/key-by.d.ts.map +1 -0
  97. package/dist/maps/key-by.js +21 -0
  98. package/dist/maps/key-by.js.map +1 -0
  99. package/dist/maps/map-values-of-map.d.ts +12 -0
  100. package/dist/maps/map-values-of-map.d.ts.map +1 -0
  101. package/dist/maps/map-values-of-map.js +18 -0
  102. package/dist/maps/map-values-of-map.js.map +1 -0
  103. package/dist/maps/safe-merge-map.d.ts +33 -0
  104. package/dist/maps/safe-merge-map.d.ts.map +1 -0
  105. package/dist/maps/safe-merge-map.js +45 -0
  106. package/dist/maps/safe-merge-map.js.map +1 -0
  107. package/dist/node.d.ts +3 -0
  108. package/dist/node.d.ts.map +1 -0
  109. package/dist/node.js +4 -0
  110. package/dist/node.js.map +1 -0
  111. package/dist/objects/index.d.ts +3 -0
  112. package/dist/objects/index.d.ts.map +1 -0
  113. package/dist/objects/index.js +3 -0
  114. package/dist/objects/index.js.map +1 -0
  115. package/dist/objects/safe-merge.d.ts +32 -0
  116. package/dist/objects/safe-merge.d.ts.map +1 -0
  117. package/dist/objects/safe-merge.js +46 -0
  118. package/dist/objects/safe-merge.js.map +1 -0
  119. package/dist/objects/sort-object-keys.d.ts +8 -0
  120. package/dist/objects/sort-object-keys.d.ts.map +1 -0
  121. package/dist/objects/sort-object-keys.js +10 -0
  122. package/dist/objects/sort-object-keys.js.map +1 -0
  123. package/dist/paths/get-common-path-prefix.d.ts +10 -0
  124. package/dist/paths/get-common-path-prefix.d.ts.map +1 -0
  125. package/dist/paths/get-common-path-prefix.js +34 -0
  126. package/dist/paths/get-common-path-prefix.js.map +1 -0
  127. package/dist/paths/index.d.ts +3 -0
  128. package/dist/paths/index.d.ts.map +1 -0
  129. package/dist/paths/index.js +3 -0
  130. package/dist/paths/index.js.map +1 -0
  131. package/dist/paths/posix-join.d.ts +9 -0
  132. package/dist/paths/posix-join.d.ts.map +1 -0
  133. package/dist/paths/posix-join.js +12 -0
  134. package/dist/paths/posix-join.js.map +1 -0
  135. package/dist/sets/difference.d.ts +9 -0
  136. package/dist/sets/difference.d.ts.map +1 -0
  137. package/dist/sets/difference.js +17 -0
  138. package/dist/sets/difference.js.map +1 -0
  139. package/dist/sets/index.d.ts +2 -0
  140. package/dist/sets/index.d.ts.map +1 -0
  141. package/dist/sets/index.js +2 -0
  142. package/dist/sets/index.js.map +1 -0
  143. package/dist/string/index.d.ts +3 -0
  144. package/dist/string/index.d.ts.map +1 -0
  145. package/dist/string/index.js +3 -0
  146. package/dist/string/index.js.map +1 -0
  147. package/dist/string/quot.d.ts +13 -0
  148. package/dist/string/quot.d.ts.map +1 -0
  149. package/dist/string/quot.js +17 -0
  150. package/dist/string/quot.js.map +1 -0
  151. package/dist/string/random-uid.d.ts +6 -0
  152. package/dist/string/random-uid.d.ts.map +1 -0
  153. package/dist/string/random-uid.js +16 -0
  154. package/dist/string/random-uid.js.map +1 -0
  155. package/dist/toposort/errors.d.ts +9 -0
  156. package/dist/toposort/errors.d.ts.map +1 -0
  157. package/dist/toposort/errors.js +17 -0
  158. package/dist/toposort/errors.js.map +1 -0
  159. package/dist/toposort/index.d.ts +4 -0
  160. package/dist/toposort/index.d.ts.map +1 -0
  161. package/dist/toposort/index.js +4 -0
  162. package/dist/toposort/index.js.map +1 -0
  163. package/dist/toposort/toposort-local.d.ts +25 -0
  164. package/dist/toposort/toposort-local.d.ts.map +1 -0
  165. package/dist/toposort/toposort-local.js +152 -0
  166. package/dist/toposort/toposort-local.js.map +1 -0
  167. package/dist/toposort/toposort.d.ts +30 -0
  168. package/dist/toposort/toposort.d.ts.map +1 -0
  169. package/dist/toposort/toposort.js +156 -0
  170. package/dist/toposort/toposort.js.map +1 -0
  171. package/dist/type-guards/index.d.ts +2 -0
  172. package/dist/type-guards/index.d.ts.map +1 -0
  173. package/dist/type-guards/index.js +2 -0
  174. package/dist/type-guards/index.js.map +1 -0
  175. package/dist/type-guards/not-empty.d.ts +5 -0
  176. package/dist/type-guards/not-empty.d.ts.map +1 -0
  177. package/dist/type-guards/not-empty.js +7 -0
  178. package/dist/type-guards/not-empty.js.map +1 -0
  179. package/dist/validators/case-validators.d.ts +36 -0
  180. package/dist/validators/case-validators.d.ts.map +1 -0
  181. package/dist/validators/case-validators.js +36 -0
  182. package/dist/validators/case-validators.js.map +1 -0
  183. package/dist/validators/index.d.ts +4 -0
  184. package/dist/validators/index.d.ts.map +1 -0
  185. package/dist/validators/index.js +4 -0
  186. package/dist/validators/index.js.map +1 -0
  187. package/dist/validators/number-validators.d.ts +8 -0
  188. package/dist/validators/number-validators.d.ts.map +1 -0
  189. package/dist/validators/number-validators.js +12 -0
  190. package/dist/validators/number-validators.js.map +1 -0
  191. package/dist/validators/transform-with-dynamic-schema.d.ts +10 -0
  192. package/dist/validators/transform-with-dynamic-schema.d.ts.map +1 -0
  193. package/dist/validators/transform-with-dynamic-schema.js +33 -0
  194. package/dist/validators/transform-with-dynamic-schema.js.map +1 -0
  195. package/package.json +64 -0
@@ -0,0 +1,12 @@
1
+ import { stat } from 'node:fs/promises';
2
+ /**
3
+ * Checks if a file exists and is a file
4
+ * @param filePath - The path to the file
5
+ * @returns True if the file exists and is a file, false otherwise
6
+ */
7
+ export async function fileExists(filePath) {
8
+ return stat(filePath)
9
+ .then((file) => file.isFile())
10
+ .catch(() => false);
11
+ }
12
+ //# sourceMappingURL=file-exists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-exists.js","sourceRoot":"","sources":["../../src/fs/file-exists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC;SAClB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;SAC7B,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Options for the findNearestPackageJson function
3
+ */
4
+ interface FindNearestPackageJsonOptions {
5
+ /**
6
+ * Starting directory
7
+ */
8
+ cwd?: string;
9
+ /**
10
+ * Stop search if node_modules is found
11
+ */
12
+ stopAtNodeModules?: boolean;
13
+ }
14
+ /**
15
+ * Find the nearest package.json file
16
+ *
17
+ * @param options - Options for the search
18
+ * @returns The path to the nearest package.json file, or undefined if not found
19
+ */
20
+ export declare function findNearestPackageJson(options?: FindNearestPackageJsonOptions): Promise<string | undefined>;
21
+ export {};
22
+ //# sourceMappingURL=find-nearest-package-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-nearest-package-json.d.ts","sourceRoot":"","sources":["../../src/fs/find-nearest-package-json.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,UAAU,6BAA6B;IACrC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA2B7B"}
@@ -0,0 +1,34 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ /**
4
+ * Find the nearest package.json file
5
+ *
6
+ * @param options - Options for the search
7
+ * @returns The path to the nearest package.json file, or undefined if not found
8
+ */
9
+ export async function findNearestPackageJson(options = {}) {
10
+ const { cwd = process.cwd(), stopAtNodeModules = false } = options;
11
+ const { root } = path.parse(cwd);
12
+ let currentDir = path.resolve(cwd);
13
+ for (;;) {
14
+ try {
15
+ // Check for package.json
16
+ const packageJsonPath = path.join(currentDir, 'package.json');
17
+ const stat = await fs.stat(packageJsonPath);
18
+ if (stat.isFile()) {
19
+ return packageJsonPath;
20
+ }
21
+ }
22
+ catch {
23
+ // Ignore errors and continue searching
24
+ }
25
+ if (currentDir === root) {
26
+ return undefined;
27
+ }
28
+ if (stopAtNodeModules && path.basename(currentDir) === 'node_modules') {
29
+ return undefined;
30
+ }
31
+ currentDir = path.dirname(currentDir); // Move up one directory
32
+ }
33
+ }
34
+ //# sourceMappingURL=find-nearest-package-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-nearest-package-json.js","sourceRoot":"","sources":["../../src/fs/find-nearest-package-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAgB7B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAAyC,EAAE;IAE3C,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACnE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEnC,SAAS,CAAC;QACR,IAAI,CAAC;YACH,yBAAyB;YACzB,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;YAC9D,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC5C,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBAClB,OAAO,eAAe,CAAC;YACzB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;QAED,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,iBAAiB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,cAAc,EAAE,CAAC;YACtE,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,wBAAwB;IACjE,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Handles an error and checks if it's an ENOENT (file not found) error.
3
+ * If it is, returns undefined. Otherwise, rethrows the error.
4
+ *
5
+ * @param error - The error to handle.
6
+ * @returns undefined if the error is ENOENT, otherwise throws the error.
7
+ */
8
+ export declare function handleFileNotFoundError(error: unknown): undefined;
9
+ //# sourceMappingURL=handle-not-found-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-not-found-error.d.ts","sourceRoot":"","sources":["../../src/fs/handle-not-found-error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAQjE"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Handles an error and checks if it's an ENOENT (file not found) error.
3
+ * If it is, returns undefined. Otherwise, rethrows the error.
4
+ *
5
+ * @param error - The error to handle.
6
+ * @returns undefined if the error is ENOENT, otherwise throws the error.
7
+ */
8
+ export function handleFileNotFoundError(error) {
9
+ if (error instanceof Error &&
10
+ error.code === 'ENOENT') {
11
+ return undefined;
12
+ }
13
+ throw error;
14
+ }
15
+ //# sourceMappingURL=handle-not-found-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-not-found-error.js","sourceRoot":"","sources":["../../src/fs/handle-not-found-error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,IACE,KAAK,YAAY,KAAK;QACrB,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAClD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './dir-exists.js';
2
+ export * from './ensure-dir.js';
3
+ export * from './file-exists.js';
4
+ export * from './find-nearest-package-json.js';
5
+ export * from './handle-not-found-error.js';
6
+ export * from './read-json-with-schema.js';
7
+ export * from './write-json.js';
8
+ export * from './write-stable-pretty-json.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './dir-exists.js';
2
+ export * from './ensure-dir.js';
3
+ export * from './file-exists.js';
4
+ export * from './find-nearest-package-json.js';
5
+ export * from './handle-not-found-error.js';
6
+ export * from './read-json-with-schema.js';
7
+ export * from './write-json.js';
8
+ export * from './write-stable-pretty-json.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type z } from 'zod';
2
+ /**
3
+ * Reads a file, parses its content as JSON, and validates it against a Zod schema.
4
+ * @param filePath - The path to the file.
5
+ * @param schema - The Zod schema to validate against.
6
+ * @returns The validated data.
7
+ * @throws If the file does not exist, contains invalid JSON, or fails schema validation.
8
+ */
9
+ export declare function readJsonWithSchema<T extends z.ZodType>(filePath: string, schema: T): Promise<z.output<T>>;
10
+ //# sourceMappingURL=read-json-with-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-json-with-schema.d.ts","sourceRoot":"","sources":["../../src/fs/read-json-with-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,CAAC,EAAY,MAAM,KAAK,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC1D,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAoBtB"}
@@ -0,0 +1,29 @@
1
+ import fs from 'node:fs/promises';
2
+ import { ZodError } from 'zod';
3
+ /**
4
+ * Reads a file, parses its content as JSON, and validates it against a Zod schema.
5
+ * @param filePath - The path to the file.
6
+ * @param schema - The Zod schema to validate against.
7
+ * @returns The validated data.
8
+ * @throws If the file does not exist, contains invalid JSON, or fails schema validation.
9
+ */
10
+ export async function readJsonWithSchema(filePath, schema) {
11
+ try {
12
+ const fileContent = await fs.readFile(filePath, 'utf8');
13
+ const parsedData = JSON.parse(fileContent);
14
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- z.output<T> is generic
15
+ return await schema.parseAsync(parsedData);
16
+ }
17
+ catch (error) {
18
+ if (error instanceof ZodError) {
19
+ throw new TypeError(`Validation failed for ${filePath}: ${error.message}`, { cause: error });
20
+ }
21
+ if (error instanceof SyntaxError) {
22
+ throw new TypeError(`Invalid JSON in file: ${filePath}`, {
23
+ cause: error,
24
+ });
25
+ }
26
+ throw error;
27
+ }
28
+ }
29
+ //# sourceMappingURL=read-json-with-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-json-with-schema.js","sourceRoot":"","sources":["../../src/fs/read-json-with-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAU,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAgB,EAChB,MAAS;IAET,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAY,CAAC;QACtD,yFAAyF;QACzF,OAAO,MAAO,MAAM,CAAC,UAAU,CAAC,UAAU,CAA0B,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,SAAS,CACjB,yBAAyB,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,EACrD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,yBAAyB,QAAQ,EAAE,EAAE;gBACvD,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Writes a JSON file with 2 spaces indentation.
3
+ * @param filePath - The path to the file.
4
+ * @param data - The data to write to the file.
5
+ */
6
+ export declare function writeJson(filePath: string, data: unknown): Promise<void>;
7
+ //# sourceMappingURL=write-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-json.d.ts","sourceRoot":"","sources":["../../src/fs/write-json.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -0,0 +1,10 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ /**
3
+ * Writes a JSON file with 2 spaces indentation.
4
+ * @param filePath - The path to the file.
5
+ * @param data - The data to write to the file.
6
+ */
7
+ export async function writeJson(filePath, data) {
8
+ await writeFile(filePath, `${JSON.stringify(data, null, 2)}\n`);
9
+ }
10
+ //# sourceMappingURL=write-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-json.js","sourceRoot":"","sources":["../../src/fs/write-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAgB,EAChB,IAAa;IAEb,MAAM,SAAS,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Writes a JSON file with stable pretty printing.
3
+ *
4
+ * That means the keys are sorted and the value is pretty printed.
5
+ *
6
+ * @param filePath - The path to the file.
7
+ * @param data - The data to write to the file.
8
+ */
9
+ export declare function writeStablePrettyJson(filePath: string, data: Record<string, unknown>): Promise<void>;
10
+ //# sourceMappingURL=write-stable-pretty-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-stable-pretty-json.d.ts","sourceRoot":"","sources":["../../src/fs/write-stable-pretty-json.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -0,0 +1,15 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import { stringifyPrettyStable } from '#src/json/stringify-pretty-stable.js';
3
+ /**
4
+ * Writes a JSON file with stable pretty printing.
5
+ *
6
+ * That means the keys are sorted and the value is pretty printed.
7
+ *
8
+ * @param filePath - The path to the file.
9
+ * @param data - The data to write to the file.
10
+ */
11
+ export async function writeStablePrettyJson(filePath, data) {
12
+ const json = stringifyPrettyStable(data);
13
+ await writeFile(filePath, json, { encoding: 'utf8' });
14
+ }
15
+ //# sourceMappingURL=write-stable-pretty-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-stable-pretty-json.js","sourceRoot":"","sources":["../../src/fs/write-stable-pretty-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,QAAgB,EAChB,IAA6B;IAE7B,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,13 @@
1
+ export * from './crypto/index.js';
2
+ export * from './errors/index.js';
3
+ export * from './events/index.js';
4
+ export * from './field-map/index.js';
5
+ export * from './json/index.js';
6
+ export * from './maps/index.js';
7
+ export * from './objects/index.js';
8
+ export * from './sets/index.js';
9
+ export * from './string/index.js';
10
+ export * from './toposort/index.js';
11
+ export * from './type-guards/index.js';
12
+ export * from './validators/index.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from './crypto/index.js';
2
+ export * from './errors/index.js';
3
+ export * from './events/index.js';
4
+ export * from './field-map/index.js';
5
+ export * from './json/index.js';
6
+ export * from './maps/index.js';
7
+ export * from './objects/index.js';
8
+ export * from './sets/index.js';
9
+ export * from './string/index.js';
10
+ export * from './toposort/index.js';
11
+ export * from './type-guards/index.js';
12
+ export * from './validators/index.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './stringify-pretty-compact.js';
2
+ export * from './stringify-pretty-stable.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './stringify-pretty-compact.js';
2
+ export * from './stringify-pretty-stable.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,11 @@
1
+ interface StringifyOptions {
2
+ indent?: number | string;
3
+ maxLength?: number;
4
+ maxNesting?: number;
5
+ margins?: boolean;
6
+ arrayMargins?: boolean;
7
+ objectMargins?: boolean;
8
+ }
9
+ export declare function stringifyPrettyCompact(rootObj: unknown, options?: StringifyOptions): string;
10
+ export {};
11
+ //# sourceMappingURL=stringify-pretty-compact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify-pretty-compact.d.ts","sourceRoot":"","sources":["../../src/json/stringify-pretty-compact.ts"],"names":[],"mappings":"AAyCA,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAsDD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAwFR"}
@@ -0,0 +1,127 @@
1
+ // adapted from https://github.com/AitoDotAI/json-stringify-pretty-compact
2
+ // allows { } to be presented as {} to better mirror prettier formatting
3
+ function isObject(obj) {
4
+ return typeof obj === 'object' && obj !== null;
5
+ }
6
+ function forEach(obj, cb) {
7
+ if (Array.isArray(obj)) {
8
+ // eslint-disable-next-line unicorn/no-array-for-each
9
+ obj.forEach(cb);
10
+ }
11
+ else if (isObject(obj)) {
12
+ for (const key of Object.keys(obj)) {
13
+ const val = obj[key];
14
+ cb(val, key);
15
+ }
16
+ }
17
+ }
18
+ function getTreeDepth(obj) {
19
+ let depth = 0;
20
+ if (Array.isArray(obj) || isObject(obj)) {
21
+ forEach(obj, (val) => {
22
+ if (Array.isArray(val) || isObject(val)) {
23
+ const tmpDepth = getTreeDepth(val);
24
+ if (tmpDepth > depth) {
25
+ depth = tmpDepth;
26
+ }
27
+ }
28
+ });
29
+ return depth + 1;
30
+ }
31
+ return depth;
32
+ }
33
+ function get(options, name, defaultValue) {
34
+ return (name in options ? options[name] : defaultValue);
35
+ }
36
+ // Note: This regex matches even invalid JSON strings, but since we’re
37
+ // working on the output of `JSON.stringify` we know that only valid strings
38
+ // are present (unless the user supplied a weird `options.indent` but in
39
+ // that case we don’t care since the output would be invalid anyway).
40
+ // This regex has been adjusted to allow replacement of { } and [ ] with {} and []
41
+ // to better mirror prettier formatting.
42
+ const stringOrChar = /("(?:[^\\"]|\\.)*")|[:,]|\{(?!})|(?<!\{)}|\[(?!])|(?<!\[)]/g;
43
+ function prettify(str, options = {}) {
44
+ const tokens = {
45
+ '{': '{',
46
+ '}': '}',
47
+ '[': '[',
48
+ ']': ']',
49
+ ',': ', ',
50
+ ':': ': ',
51
+ };
52
+ if (!!options.addMargin || !!options.addObjectMargin) {
53
+ tokens['{'] = '{ ';
54
+ tokens['}'] = ' }';
55
+ }
56
+ if (!!options.addMargin || !!options.addArrayMargin) {
57
+ tokens['['] = '[ ';
58
+ tokens[']'] = ' ]';
59
+ }
60
+ return str.replaceAll(stringOrChar, (match, string) => string ? match : tokens[match]);
61
+ }
62
+ export function stringifyPrettyCompact(rootObj, options = {}) {
63
+ const indent = JSON.stringify([1], null, get(options, 'indent', 2)).slice(2, -3);
64
+ const addMargin = get(options, 'margins', false);
65
+ const addArrayMargin = get(options, 'arrayMargins', false);
66
+ const addObjectMargin = get(options, 'objectMargins', true);
67
+ const maxLength = indent === '' ? Infinity : get(options, 'maxLength', 80);
68
+ const maxNesting = get(options, 'maxNesting', Infinity);
69
+ return (function stringifyRecursive(obj, currentIndent, reserved) {
70
+ if (obj &&
71
+ typeof obj === 'object' &&
72
+ typeof obj.toJSON === 'function') {
73
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
74
+ obj = obj.toJSON();
75
+ }
76
+ const string = JSON.stringify(obj);
77
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
78
+ if (string === undefined) {
79
+ return string;
80
+ }
81
+ const length = maxLength - currentIndent.length - reserved;
82
+ const treeDepth = getTreeDepth(obj);
83
+ if (treeDepth <= maxNesting && string.length <= length) {
84
+ const prettified = prettify(string, {
85
+ addMargin,
86
+ addArrayMargin,
87
+ addObjectMargin,
88
+ });
89
+ if (prettified.length <= length) {
90
+ return prettified;
91
+ }
92
+ }
93
+ if (isObject(obj)) {
94
+ const nextIndent = currentIndent + indent;
95
+ const items = [];
96
+ let delimiters;
97
+ const atEndOfArray = (array, index) => index === array.length - 1 ? 0 : 1;
98
+ if (Array.isArray(obj)) {
99
+ for (let index = 0; index < obj.length; index += 1) {
100
+ items.push(stringifyRecursive(obj[index], nextIndent, atEndOfArray(obj, index)) || 'null');
101
+ }
102
+ delimiters = '[]';
103
+ }
104
+ else {
105
+ // eslint-disable-next-line unicorn/no-array-for-each
106
+ Object.keys(obj).forEach((key, index, array) => {
107
+ const keyPart = `${JSON.stringify(key)}: `;
108
+ const value = stringifyRecursive(obj[key], nextIndent, keyPart.length + atEndOfArray(array, index));
109
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
110
+ if (value !== undefined) {
111
+ items.push(keyPart + value);
112
+ }
113
+ });
114
+ delimiters = '{}';
115
+ }
116
+ if (items.length > 0) {
117
+ return [
118
+ delimiters[0],
119
+ indent + items.join(`,\n${nextIndent}`),
120
+ delimiters[1],
121
+ ].join(`\n${currentIndent}`);
122
+ }
123
+ }
124
+ return string;
125
+ })(rootObj, '', 0);
126
+ }
127
+ //# sourceMappingURL=stringify-pretty-compact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify-pretty-compact.js","sourceRoot":"","sources":["../../src/json/stringify-pretty-compact.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wEAAwE;AAExE,SAAS,QAAQ,CAAC,GAAY;IAC5B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC;AACjD,CAAC;AAED,SAAS,OAAO,CACd,GAAY,EACZ,EAAgD;IAEhD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,qDAAqD;QACrD,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;SAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI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G,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBAC7C,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;oBAC3C,MAAM,KAAK,GAAG,kBAAkB,CAC9B,GAAG,CAAC,GAAG,CAAC,EACR,UAAU,EACV,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAC5C,CAAC;oBACF,uEAAuE;oBACvE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;wBACxB,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC,CAAC,CAAC;gBACH,UAAU,GAAG,IAAI,CAAC;YACpB,CAAC;YAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,OAAO;oBACL,UAAU,CAAC,CAAC,CAAC;oBACb,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,UAAU,EAAE,CAAC;oBACvC,UAAU,CAAC,CAAC,CAAC;iBACd,CAAC,IAAI,CAAC,KAAK,aAAa,EAAE,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACrB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Stringifies a value with stable pretty printing.
3
+ *
4
+ * That means the keys are sorted and the value is pretty printed.
5
+ *
6
+ * @param value - The value to stringify.
7
+ * @returns The stringified value.
8
+ */
9
+ export declare function stringifyPrettyStable(value: Record<string, unknown>): string;
10
+ //# sourceMappingURL=stringify-pretty-stable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify-pretty-stable.d.ts","sourceRoot":"","sources":["../../src/json/stringify-pretty-stable.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAK5E"}
@@ -0,0 +1,17 @@
1
+ import sortKeys from 'sort-keys';
2
+ import { stringifyPrettyCompact } from './stringify-pretty-compact.js';
3
+ /**
4
+ * Stringifies a value with stable pretty printing.
5
+ *
6
+ * That means the keys are sorted and the value is pretty printed.
7
+ *
8
+ * @param value - The value to stringify.
9
+ * @returns The stringified value.
10
+ */
11
+ export function stringifyPrettyStable(value) {
12
+ const sortedValue = sortKeys(value, {
13
+ deep: true,
14
+ });
15
+ return `${stringifyPrettyCompact(sortedValue)}\n`;
16
+ }
17
+ //# sourceMappingURL=stringify-pretty-stable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify-pretty-stable.js","sourceRoot":"","sources":["../../src/json/stringify-pretty-stable.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAA8B;IAClE,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,EAAE;QAClC,IAAI,EAAE,IAAI;KACX,CAAC,CAAC;IACH,OAAO,GAAG,sBAAsB,CAAC,WAAW,CAAC,IAAI,CAAC;AACpD,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Groups values of an iterable using a key-generating function and returns a Map.
3
+ *
4
+ * Mimics the behavior of ES2025 `Map.groupBy`.
5
+ *
6
+ * @template T The type of elements in the iterable.
7
+ * @template K The key type returned by the key function.
8
+ * @param iterable The iterable to group.
9
+ * @param keyFn A function that returns a grouping key for each element.
10
+ * @returns A Map where each key maps to an array of elements with that key.
11
+ */
12
+ export declare function mapGroupBy<T, K>(iterable: Iterable<T>, keyFn: (item: T) => K): Map<K, T[]>;
13
+ //# sourceMappingURL=group-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.d.ts","sourceRoot":"","sources":["../../src/maps/group-by.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAYb"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Groups values of an iterable using a key-generating function and returns a Map.
3
+ *
4
+ * Mimics the behavior of ES2025 `Map.groupBy`.
5
+ *
6
+ * @template T The type of elements in the iterable.
7
+ * @template K The key type returned by the key function.
8
+ * @param iterable The iterable to group.
9
+ * @param keyFn A function that returns a grouping key for each element.
10
+ * @returns A Map where each key maps to an array of elements with that key.
11
+ */
12
+ export function mapGroupBy(iterable, keyFn) {
13
+ const result = new Map();
14
+ for (const item of iterable) {
15
+ const key = keyFn(item);
16
+ const group = result.get(key);
17
+ if (group) {
18
+ group.push(item);
19
+ }
20
+ else {
21
+ result.set(key, [item]);
22
+ }
23
+ }
24
+ return result;
25
+ }
26
+ //# sourceMappingURL=group-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../src/maps/group-by.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,QAAqB,EACrB,KAAqB;IAErB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './group-by.js';
2
+ export * from './key-by.js';
3
+ export * from './map-values-of-map.js';
4
+ export * from './safe-merge-map.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/maps/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './group-by.js';
2
+ export * from './key-by.js';
3
+ export * from './map-values-of-map.js';
4
+ export * from './safe-merge-map.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/maps/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Creates a Map from an iterable, using a key-generating function.
3
+ * If multiple elements generate the same key, later elements override earlier ones.
4
+ *
5
+ * Analogous to lodash's keyBy function, but returns a Map instead of an object.
6
+ *
7
+ * @template T The type of elements in the iterable.
8
+ * @template K The key type returned by the key function.
9
+ * @param iterable The iterable to transform.
10
+ * @param keyFn A function that returns a unique key for each element.
11
+ * @returns A Map where each key maps to a single element.
12
+ */
13
+ export declare function mapKeyBy<T, K>(iterable: Iterable<T>, keyFn: (item: T) => K): Map<K, T>;
14
+ //# sourceMappingURL=key-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-by.d.ts","sourceRoot":"","sources":["../../src/maps/key-by.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAOX"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Creates a Map from an iterable, using a key-generating function.
3
+ * If multiple elements generate the same key, later elements override earlier ones.
4
+ *
5
+ * Analogous to lodash's keyBy function, but returns a Map instead of an object.
6
+ *
7
+ * @template T The type of elements in the iterable.
8
+ * @template K The key type returned by the key function.
9
+ * @param iterable The iterable to transform.
10
+ * @param keyFn A function that returns a unique key for each element.
11
+ * @returns A Map where each key maps to a single element.
12
+ */
13
+ export function mapKeyBy(iterable, keyFn) {
14
+ const result = new Map();
15
+ for (const item of iterable) {
16
+ const key = keyFn(item);
17
+ result.set(key, item);
18
+ }
19
+ return result;
20
+ }
21
+ //# sourceMappingURL=key-by.js.map