@baseplate-dev/utils 0.3.3 → 0.3.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.
@@ -1,2 +1,2 @@
1
- export declare function hashWithSHA256(content: string | ArrayBuffer): Promise<string>;
1
+ export declare function hashWithSHA256(content: string | ArrayBuffer | Buffer): Promise<string>;
2
2
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/crypto/hash.ts"],"names":[],"mappings":"AAQA,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,GAAG,WAAW,GAC5B,OAAO,CAAC,MAAM,CAAC,CAKjB"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/crypto/hash.ts"],"names":[],"mappings":"AAcA,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,GACrC,OAAO,CAAC,MAAM,CAAC,CAKjB"}
@@ -1,7 +1,11 @@
1
1
  function normalizeContent(content) {
2
2
  if (typeof content === 'string') {
3
3
  const encoder = new TextEncoder();
4
- return encoder.encode(content);
4
+ const { buffer } = encoder.encode(content);
5
+ if (!(buffer instanceof ArrayBuffer)) {
6
+ throw new TypeError('Buffer is not an ArrayBuffer');
7
+ }
8
+ return buffer;
5
9
  }
6
10
  return content;
7
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/crypto/hash.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAgB,CAAC,OAA6B;IACrD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA6B;I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,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC"}
@@ -6,5 +6,5 @@
6
6
  * @param filePath - The path to the file.
7
7
  * @param data - The data to write to the file.
8
8
  */
9
- export declare function writeStablePrettyJson(filePath: string, data: Record<string, unknown>): Promise<void>;
9
+ export declare function writeStablePrettyJson(filePath: string, data: object): Promise<void>;
10
10
  //# sourceMappingURL=write-stable-pretty-json.d.ts.map
@@ -1 +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"}
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,GACX,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -1 +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"}
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,IAAY;IAEZ,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,17 @@
1
+ /**
2
+ * Finds the n closest matches to a target string from an array of strings using Levenshtein distance.
3
+ *
4
+ * @param target - The string to find matches for
5
+ * @param candidates - Array of candidate strings to search through
6
+ * @param n - Number of closest matches to return (defaults to 1)
7
+ * @returns Array of the n closest matches, sorted by distance (closest first)
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const candidates = ['apple', 'banana', 'orange', 'grape'];
12
+ * const matches = findClosestMatch('aple', candidates, 2);
13
+ * // Returns: ['apple', 'grape'] (assuming these are the 2 closest matches)
14
+ * ```
15
+ */
16
+ export declare function findClosestMatch(target: string, candidates: string[], n?: number): string[];
17
+ //# sourceMappingURL=find-closest-match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-closest-match.d.ts","sourceRoot":"","sources":["../../src/string/find-closest-match.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAAE,EACpB,CAAC,SAAI,GACJ,MAAM,EAAE,CA0BV"}
@@ -0,0 +1,40 @@
1
+ import { distance } from 'fastest-levenshtein';
2
+ /**
3
+ * Finds the n closest matches to a target string from an array of strings using Levenshtein distance.
4
+ *
5
+ * @param target - The string to find matches for
6
+ * @param candidates - Array of candidate strings to search through
7
+ * @param n - Number of closest matches to return (defaults to 1)
8
+ * @returns Array of the n closest matches, sorted by distance (closest first)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const candidates = ['apple', 'banana', 'orange', 'grape'];
13
+ * const matches = findClosestMatch('aple', candidates, 2);
14
+ * // Returns: ['apple', 'grape'] (assuming these are the 2 closest matches)
15
+ * ```
16
+ */
17
+ export function findClosestMatch(target, candidates, n = 1) {
18
+ if (candidates.length === 0) {
19
+ return [];
20
+ }
21
+ if (n <= 0) {
22
+ return [];
23
+ }
24
+ // Calculate distances for all candidates
25
+ const distances = candidates.map((candidate, index) => ({
26
+ candidate,
27
+ distance: distance(target, candidate),
28
+ index,
29
+ }));
30
+ // Sort by distance (ascending) and then by original index for stable sorting
31
+ distances.sort((a, b) => {
32
+ if (a.distance !== b.distance) {
33
+ return a.distance - b.distance;
34
+ }
35
+ return a.index - b.index;
36
+ });
37
+ // Return the n closest matches
38
+ return distances.slice(0, n).map((item) => item.candidate);
39
+ }
40
+ //# sourceMappingURL=find-closest-match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-closest-match.js","sourceRoot":"","sources":["../../src/string/find-closest-match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,UAAoB,EACpB,CAAC,GAAG,CAAC;IAEL,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,yCAAyC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACtD,SAAS;QACT,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;QACrC,KAAK;KACN,CAAC,CAAC,CAAC;IAEJ,6EAA6E;IAC7E,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACtB,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC9B,OAAO,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QACjC,CAAC;QACD,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,+BAA+B;IAC/B,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC7D,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './convert-case-with-prefix.js';
2
+ export * from './find-closest-match.js';
2
3
  export * from './quot.js';
3
4
  export * from './random-key.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './convert-case-with-prefix.js';
2
+ export * from './find-closest-match.js';
2
3
  export * from './quot.js';
3
4
  export * from './random-key.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baseplate-dev/utils",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Shared utility functions for Baseplate",
5
5
  "keywords": [
6
6
  "utilities",
@@ -39,19 +39,20 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "es-toolkit": "1.31.0",
42
+ "fastest-levenshtein": "^1.0.16",
42
43
  "nanoid": "5.0.9",
43
44
  "sort-keys": "^5.1.0",
44
45
  "tinyqueue": "3.0.0",
45
- "zod": "3.24.1"
46
+ "zod": "3.25.76"
46
47
  },
47
48
  "devDependencies": {
48
- "@types/node": "^22.0.0",
49
+ "@types/node": "^22.17.2",
49
50
  "eslint": "9.32.0",
50
51
  "memfs": "4.15.1",
51
52
  "prettier": "3.6.2",
52
- "typescript": "5.7.3",
53
+ "typescript": "5.8.3",
53
54
  "vitest": "3.2.4",
54
- "@baseplate-dev/tools": "0.3.3"
55
+ "@baseplate-dev/tools": "0.3.4"
55
56
  },
56
57
  "engines": {
57
58
  "node": "^22.0.0"