@fgv/ts-web-extras 5.0.1-8 → 5.0.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 (77) hide show
  1. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +9 -9
  2. package/.rush/temp/operation/build/all.log +9 -9
  3. package/.rush/temp/operation/build/log-chunks.jsonl +9 -9
  4. package/.rush/temp/operation/build/state.json +1 -1
  5. package/.rush/temp/shrinkwrap-deps.json +40 -38
  6. package/config/jest.config.json +1 -1
  7. package/config/rig.json +1 -1
  8. package/dist/index.browser.js +24 -0
  9. package/dist/index.browser.js.map +1 -0
  10. package/dist/index.js +42 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/packlets/crypto/browserHashProvider.js +66 -0
  13. package/dist/packlets/crypto/browserHashProvider.js.map +1 -0
  14. package/dist/packlets/crypto/index.js +27 -0
  15. package/dist/packlets/crypto/index.js.map +1 -0
  16. package/dist/packlets/file-api-types/index.js +156 -0
  17. package/dist/packlets/file-api-types/index.js.map +1 -0
  18. package/dist/packlets/file-tree/fileApiTreeAccessors.js +330 -0
  19. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -0
  20. package/dist/packlets/file-tree/index.js +27 -0
  21. package/dist/packlets/file-tree/index.js.map +1 -0
  22. package/dist/packlets/helpers/fileTreeHelpers.js +94 -0
  23. package/dist/packlets/helpers/fileTreeHelpers.js.map +1 -0
  24. package/dist/packlets/helpers/index.js +27 -0
  25. package/dist/packlets/helpers/index.js.map +1 -0
  26. package/dist/packlets/url-utils/index.js +27 -0
  27. package/dist/packlets/url-utils/index.js.map +1 -0
  28. package/dist/packlets/url-utils/urlParams.js +157 -0
  29. package/dist/packlets/url-utils/urlParams.js.map +1 -0
  30. package/dist/test/setupTests.js +74 -0
  31. package/dist/test/setupTests.js.map +1 -0
  32. package/dist/test/unit/browserHashProvider.test.js +140 -0
  33. package/dist/test/unit/browserHashProvider.test.js.map +1 -0
  34. package/dist/test/unit/fileApiTreeAccessors.test.js +1137 -0
  35. package/dist/test/unit/fileApiTreeAccessors.test.js.map +1 -0
  36. package/dist/test/unit/fileApiTypes.test.js +442 -0
  37. package/dist/test/unit/fileApiTypes.test.js.map +1 -0
  38. package/dist/test/unit/fileTreeHelpers.test.js +590 -0
  39. package/dist/test/unit/fileTreeHelpers.test.js.map +1 -0
  40. package/dist/test/unit/urlParams.test.js +393 -0
  41. package/dist/test/unit/urlParams.test.js.map +1 -0
  42. package/dist/test/utils/testHelpers.js +124 -0
  43. package/dist/test/utils/testHelpers.js.map +1 -0
  44. package/dist/tsdoc-metadata.json +1 -1
  45. package/lib/index.browser.d.ts +2 -0
  46. package/lib/index.browser.d.ts.map +1 -0
  47. package/lib/index.browser.js +40 -0
  48. package/lib/index.browser.js.map +1 -0
  49. package/package.json +20 -6
  50. package/rush-logs/ts-web-extras.build.cache.log +1 -3
  51. package/rush-logs/ts-web-extras.build.log +9 -9
  52. package/src/index.browser.ts +24 -0
  53. package/temp/build/typescript/ts_vnCx6LlY.json +1 -0
  54. package/temp/coverage/crypto/browserHashProvider.ts.html +1 -1
  55. package/temp/coverage/crypto/index.html +1 -1
  56. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1 -1
  57. package/temp/coverage/file-tree/index.html +1 -1
  58. package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
  59. package/temp/coverage/helpers/index.html +1 -1
  60. package/temp/coverage/index.html +1 -1
  61. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +1 -1
  62. package/temp/coverage/lcov-report/crypto/index.html +1 -1
  63. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1 -1
  64. package/temp/coverage/lcov-report/file-tree/index.html +1 -1
  65. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
  66. package/temp/coverage/lcov-report/helpers/index.html +1 -1
  67. package/temp/coverage/lcov-report/index.html +1 -1
  68. package/temp/coverage/lcov-report/url-utils/index.html +1 -1
  69. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
  70. package/temp/coverage/url-utils/index.html +1 -1
  71. package/temp/coverage/url-utils/urlParams.ts.html +1 -1
  72. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  73. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -1
  74. package/temp/ts-web-extras.api.json +1 -1
  75. package/.rush/temp/3b013d9faf7f9da4019da446f1d05aef5eb5f80d.tar.log +0 -121
  76. package/temp/build/typescript/ts_l9Fw4VUO.json +0 -1
  77. /package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/{3f/package_3fe59327dabcb949f1b2ad415f67debd → 0e/package_0eb6535f5987849d93ea51ef33a14cf6} +0 -0
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { FileTree } from '@fgv/ts-json-base';
23
+ import { FileApiTreeAccessors } from '../file-tree/fileApiTreeAccessors';
24
+ /**
25
+ * Default initialization parameters for a `FileTree` using {@link FileApiTreeAccessors}.
26
+ * @public
27
+ */
28
+ export const defaultFileApiTreeInitParams = {
29
+ inferContentType: FileTree.FileItem.defaultAcceptContentType
30
+ };
31
+ /**
32
+ * Helper function to create a new FileTree instance
33
+ * from a browser FileList (e.g., from input[type="file"]).
34
+ * @param fileList - FileList from a file input element
35
+ * @param params - Optional `IFileTreeInitParams` for the file tree.
36
+ * @returns Promise resolving to a successful Result with the new FileTree instance
37
+ * if successful, or a failed Result with an error message otherwise
38
+ * @remarks The content type of the files is always `string` and the default
39
+ * accept contentType function (`FileTree.FileItem.defaultAcceptContentType`) is
40
+ * used, so content type is derived from the mime type of the file, when
41
+ * available.
42
+ * @public
43
+ */
44
+ export function fromFileList(fileList, params) {
45
+ params = Object.assign(Object.assign({}, defaultFileApiTreeInitParams), (params !== null && params !== void 0 ? params : {}));
46
+ return FileApiTreeAccessors.fromFileList(fileList, params);
47
+ }
48
+ /**
49
+ * Helper function to create a new FileTree instance
50
+ * from a directory upload with webkitRelativePath support.
51
+ * @param fileList - FileList from a directory upload (input with webkitdirectory)
52
+ * @param params - Optional `IFileTreeInitParams` for the file tree.
53
+ * @returns Promise resolving to a successful Result with the new FileTree instance
54
+ * if successful, or a failed Result with an error message otherwise
55
+ * @remarks The content type of the files is always `string` and the default
56
+ * accept contentType function (`FileTree.FileItem.defaultAcceptContentType`) is
57
+ * is used, so content type is derived from the mime type of the file, when
58
+ * available.
59
+ * @public
60
+ */
61
+ export function fromDirectoryUpload(fileList, params) {
62
+ params = Object.assign(Object.assign({}, defaultFileApiTreeInitParams), (params !== null && params !== void 0 ? params : {}));
63
+ return FileApiTreeAccessors.fromDirectoryUpload(fileList, params);
64
+ }
65
+ /**
66
+ * Helper function to get the original File object from a FileList by path.
67
+ * @param fileList - The original FileList
68
+ * @param path - The path to the file
69
+ * @returns A successful Result with the File object if found,
70
+ * or a failed Result with an error message otherwise
71
+ * @public
72
+ */
73
+ export function getOriginalFile(fileList, path) {
74
+ return FileApiTreeAccessors.getOriginalFile(fileList, path);
75
+ }
76
+ /**
77
+ * Helper function to extract metadata from a `FileList`.
78
+ * @param fileList - The `FileList` to extract metadata from
79
+ * @returns Array of {@link IFileMetadata | file metadata} objects
80
+ * @public
81
+ */
82
+ export function extractFileListMetadata(fileList) {
83
+ return Array.from(fileList).map((f) => FileApiTreeAccessors.extractFileMetadata(f));
84
+ }
85
+ /**
86
+ * Helper function to extract metadata from a `File`.
87
+ * @param file - The File to extract metadata from
88
+ * @returns {@link IFileMetadata | file metadata} object
89
+ * @public
90
+ */
91
+ export function extractFileMetadata(file) {
92
+ return FileApiTreeAccessors.extractFileMetadata(file);
93
+ }
94
+ //# sourceMappingURL=fileTreeHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileTreeHelpers.js","sourceRoot":"","sources":["../../../src/packlets/helpers/fileTreeHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAiB,MAAM,mCAAmC,CAAC;AAExF;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAyC;IAChF,gBAAgB,EAAE,QAAQ,CAAC,QAAQ,CAAC,wBAAwB;CAC7D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAkB,EAClB,MAA6C;IAE7C,MAAM,mCAAQ,4BAA4B,GAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAE,CAAC;IAChE,OAAO,oBAAoB,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAkB,EAClB,MAA6C;IAE7C,MAAM,mCAAQ,4BAA4B,GAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAE,CAAC;IAChE,OAAO,oBAAoB,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,QAAkB,EAAE,IAAY;IAC9D,OAAO,oBAAoB,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAkB;IACxD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAU;IAC5C,OAAO,oBAAoB,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport { FileApiTreeAccessors, IFileMetadata } from '../file-tree/fileApiTreeAccessors';\n\n/**\n * Default initialization parameters for a `FileTree` using {@link FileApiTreeAccessors}.\n * @public\n */\nexport const defaultFileApiTreeInitParams: FileTree.IFileTreeInitParams<string> = {\n inferContentType: FileTree.FileItem.defaultAcceptContentType\n};\n\n/**\n * Helper function to create a new FileTree instance\n * from a browser FileList (e.g., from input[type=\"file\"]).\n * @param fileList - FileList from a file input element\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a successful Result with the new FileTree instance\n * if successful, or a failed Result with an error message otherwise\n * @remarks The content type of the files is always `string` and the default\n * accept contentType function (`FileTree.FileItem.defaultAcceptContentType`) is\n * used, so content type is derived from the mime type of the file, when\n * available.\n * @public\n */\nexport function fromFileList(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<string>\n): Promise<Result<FileTree.FileTree<string>>> {\n params = { ...defaultFileApiTreeInitParams, ...(params ?? {}) };\n return FileApiTreeAccessors.fromFileList(fileList, params);\n}\n\n/**\n * Helper function to create a new FileTree instance\n * from a directory upload with webkitRelativePath support.\n * @param fileList - FileList from a directory upload (input with webkitdirectory)\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a successful Result with the new FileTree instance\n * if successful, or a failed Result with an error message otherwise\n * @remarks The content type of the files is always `string` and the default\n * accept contentType function (`FileTree.FileItem.defaultAcceptContentType`) is\n * is used, so content type is derived from the mime type of the file, when\n * available.\n * @public\n */\nexport function fromDirectoryUpload(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<string>\n): Promise<Result<FileTree.FileTree<string>>> {\n params = { ...defaultFileApiTreeInitParams, ...(params ?? {}) };\n return FileApiTreeAccessors.fromDirectoryUpload(fileList, params);\n}\n\n/**\n * Helper function to get the original File object from a FileList by path.\n * @param fileList - The original FileList\n * @param path - The path to the file\n * @returns A successful Result with the File object if found,\n * or a failed Result with an error message otherwise\n * @public\n */\nexport function getOriginalFile(fileList: FileList, path: string): Result<File> {\n return FileApiTreeAccessors.getOriginalFile(fileList, path);\n}\n\n/**\n * Helper function to extract metadata from a `FileList`.\n * @param fileList - The `FileList` to extract metadata from\n * @returns Array of {@link IFileMetadata | file metadata} objects\n * @public\n */\nexport function extractFileListMetadata(fileList: FileList): Array<IFileMetadata> {\n return Array.from(fileList).map((f) => FileApiTreeAccessors.extractFileMetadata(f));\n}\n\n/**\n * Helper function to extract metadata from a `File`.\n * @param file - The File to extract metadata from\n * @returns {@link IFileMetadata | file metadata} object\n * @public\n */\nexport function extractFileMetadata(file: File): IFileMetadata {\n return FileApiTreeAccessors.extractFileMetadata(file);\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /**
23
+ * Tree-shakeable helper functions for browser-compatible file operations.
24
+ * @packageDocumentation
25
+ */
26
+ export * as FileTreeHelpers from './fileTreeHelpers';
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AAEH,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Tree-shakeable helper functions for browser-compatible file operations.\n * @packageDocumentation\n */\n\nexport * as FileTreeHelpers from './fileTreeHelpers';\n"]}
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /**
23
+ * URL parameter parsing utilities for web applications.
24
+ * @packageDocumentation
25
+ */
26
+ export * from './urlParams';
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/url-utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AAEH,cAAc,aAAa,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * URL parameter parsing utilities for web applications.\n * @packageDocumentation\n */\n\nexport * from './urlParams';\n"]}
@@ -0,0 +1,157 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /**
23
+ * Parses URL parameters and extracts configuration options
24
+ * @public
25
+ */
26
+ export function parseUrlParameters() {
27
+ const params = new URLSearchParams(window.location.search);
28
+ const options = {};
29
+ // Parse string parameters
30
+ const input = params.get('input');
31
+ if (input) {
32
+ options.input = input;
33
+ // Set starting directory for input file picker
34
+ if (isFilePath(input)) {
35
+ options.inputStartDir = extractDirectoryPath(input);
36
+ }
37
+ }
38
+ const config = params.get('config');
39
+ if (config) {
40
+ options.config = config;
41
+ // Set starting directory for config file picker
42
+ if (isFilePath(config)) {
43
+ options.configStartDir = extractDirectoryPath(config);
44
+ }
45
+ }
46
+ const contextFilter = params.get('contextFilter');
47
+ if (contextFilter)
48
+ options.contextFilter = contextFilter;
49
+ const qualifierDefaults = params.get('qualifierDefaults');
50
+ if (qualifierDefaults)
51
+ options.qualifierDefaults = qualifierDefaults;
52
+ const resourceTypes = params.get('resourceTypes');
53
+ if (resourceTypes)
54
+ options.resourceTypes = resourceTypes;
55
+ // Parse numeric parameters
56
+ const maxDistance = params.get('maxDistance');
57
+ if (maxDistance) {
58
+ const parsed = parseInt(maxDistance, 10);
59
+ if (!isNaN(parsed))
60
+ options.maxDistance = parsed;
61
+ }
62
+ // Parse boolean parameters
63
+ const reduceQualifiers = params.get('reduceQualifiers');
64
+ if (reduceQualifiers === 'true')
65
+ options.reduceQualifiers = true;
66
+ const interactive = params.get('interactive');
67
+ if (interactive === 'true')
68
+ options.interactive = true;
69
+ // Parse ZIP loading parameters
70
+ const loadZip = params.get('loadZip');
71
+ if (loadZip === 'true')
72
+ options.loadZip = true;
73
+ const zipPath = params.get('zipPath');
74
+ if (zipPath)
75
+ options.zipPath = zipPath;
76
+ const zipFile = params.get('zipFile');
77
+ if (zipFile)
78
+ options.zipFile = zipFile;
79
+ return options;
80
+ }
81
+ /**
82
+ * Converts context filter token to context object
83
+ * Example: "language=en-US|territory=US" -\> \{ language: "en-US", territory: "US" \}
84
+ * @public
85
+ */
86
+ export function parseContextFilter(contextFilter) {
87
+ const context = {};
88
+ const tokens = contextFilter.split('|');
89
+ for (const token of tokens) {
90
+ const [key, value] = token.split('=');
91
+ if (key && value) {
92
+ context[key.trim()] = value.trim();
93
+ }
94
+ }
95
+ return context;
96
+ }
97
+ /**
98
+ * Converts qualifier defaults token to structured format
99
+ * Example: "language=en-US,en-CA|territory=US" -\> \{ language: ["en-US", "en-CA"], territory: ["US"] \}
100
+ * @public
101
+ */
102
+ export function parseQualifierDefaults(qualifierDefaults) {
103
+ const defaults = {};
104
+ const tokens = qualifierDefaults.split('|');
105
+ for (const token of tokens) {
106
+ const [key, values] = token.split('=');
107
+ if (key && values) {
108
+ defaults[key.trim()] = values.split(',').map((v) => v.trim());
109
+ }
110
+ }
111
+ return defaults;
112
+ }
113
+ /**
114
+ * Converts resource types string to array
115
+ * Example: "json,string" -\> ["json", "string"]
116
+ * @public
117
+ */
118
+ export function parseResourceTypes(resourceTypes) {
119
+ return resourceTypes
120
+ .split(',')
121
+ .map((t) => t.trim())
122
+ .filter((t) => t.length > 0);
123
+ }
124
+ /**
125
+ * Extracts the directory path from a file or directory path
126
+ * If the path appears to be a directory (no extension), returns it as-is
127
+ * If the path appears to be a file, returns the parent directory
128
+ * @public
129
+ */
130
+ export function extractDirectoryPath(path) {
131
+ if (!path)
132
+ return '';
133
+ // Normalize path separators
134
+ const normalizedPath = path.replace(/\\/g, '/');
135
+ // Check if it looks like a file (has an extension)
136
+ const parts = normalizedPath.split('/');
137
+ const lastPart = parts[parts.length - 1];
138
+ // If the last part has an extension, treat as file and return directory
139
+ if (lastPart.includes('.') && !lastPart.startsWith('.')) {
140
+ return parts.slice(0, -1).join('/') || '/';
141
+ }
142
+ // Otherwise, treat as directory
143
+ return normalizedPath;
144
+ }
145
+ /**
146
+ * Determines if a path appears to be a file (has extension) or directory
147
+ * @public
148
+ */
149
+ export function isFilePath(path) {
150
+ if (!path)
151
+ return false;
152
+ const parts = path.split('/');
153
+ const lastPart = parts[parts.length - 1];
154
+ // Has extension and doesn't start with dot (hidden files)
155
+ return lastPart.includes('.') && !lastPart.startsWith('.');
156
+ }
157
+ //# sourceMappingURL=urlParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlParams.js","sourceRoot":"","sources":["../../../src/packlets/url-utils/urlParams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAyEH;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE3D,MAAM,OAAO,GAAsB,EAAE,CAAC;IAEtC,0BAA0B;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACtB,+CAA+C;QAC/C,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,aAAa,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QACxB,gDAAgD;QAChD,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,cAAc,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,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CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Configuration options that can be passed via URL parameters\n * @public\n */\nexport interface IUrlConfigOptions {\n /**\n * Input file path\n */\n input?: string;\n\n /**\n * Configuration name or path\n */\n config?: string;\n\n /**\n * Context filter token (pipe-separated)\n */\n contextFilter?: string;\n\n /**\n * Qualifier defaults token (pipe-separated)\n */\n qualifierDefaults?: string;\n\n /**\n * Resource types filter (comma-separated)\n */\n resourceTypes?: string;\n\n /**\n * Maximum distance for language matching\n */\n maxDistance?: number;\n\n /**\n * Whether to reduce qualifiers\n */\n reduceQualifiers?: boolean;\n\n /**\n * Whether to launch in interactive mode\n */\n interactive?: boolean;\n\n /**\n * Starting directory for input file picker (derived from input path)\n */\n inputStartDir?: string;\n\n /**\n * Starting directory for config file picker (derived from config path)\n */\n configStartDir?: string;\n\n /**\n * Whether to use ZIP loading mode\n */\n loadZip?: boolean;\n\n /**\n * Path to ZIP file to load (for CLI-generated ZIPs)\n */\n zipPath?: string;\n\n /**\n * Name of ZIP file to load from Downloads (filename only)\n */\n zipFile?: string;\n}\n\n/**\n * Parses URL parameters and extracts configuration options\n * @public\n */\nexport function parseUrlParameters(): IUrlConfigOptions {\n const params = new URLSearchParams(window.location.search);\n\n const options: IUrlConfigOptions = {};\n\n // Parse string parameters\n const input = params.get('input');\n if (input) {\n options.input = input;\n // Set starting directory for input file picker\n if (isFilePath(input)) {\n options.inputStartDir = extractDirectoryPath(input);\n }\n }\n\n const config = params.get('config');\n if (config) {\n options.config = config;\n // Set starting directory for config file picker\n if (isFilePath(config)) {\n options.configStartDir = extractDirectoryPath(config);\n }\n }\n\n const contextFilter = params.get('contextFilter');\n if (contextFilter) options.contextFilter = contextFilter;\n\n const qualifierDefaults = params.get('qualifierDefaults');\n if (qualifierDefaults) options.qualifierDefaults = qualifierDefaults;\n\n const resourceTypes = params.get('resourceTypes');\n if (resourceTypes) options.resourceTypes = resourceTypes;\n\n // Parse numeric parameters\n const maxDistance = params.get('maxDistance');\n if (maxDistance) {\n const parsed = parseInt(maxDistance, 10);\n if (!isNaN(parsed)) options.maxDistance = parsed;\n }\n\n // Parse boolean parameters\n const reduceQualifiers = params.get('reduceQualifiers');\n if (reduceQualifiers === 'true') options.reduceQualifiers = true;\n\n const interactive = params.get('interactive');\n if (interactive === 'true') options.interactive = true;\n\n // Parse ZIP loading parameters\n const loadZip = params.get('loadZip');\n if (loadZip === 'true') options.loadZip = true;\n\n const zipPath = params.get('zipPath');\n if (zipPath) options.zipPath = zipPath;\n\n const zipFile = params.get('zipFile');\n if (zipFile) options.zipFile = zipFile;\n\n return options;\n}\n\n/**\n * Converts context filter token to context object\n * Example: \"language=en-US|territory=US\" -\\> \\{ language: \"en-US\", territory: \"US\" \\}\n * @public\n */\nexport function parseContextFilter(contextFilter: string): Record<string, string> {\n const context: Record<string, string> = {};\n\n const tokens = contextFilter.split('|');\n for (const token of tokens) {\n const [key, value] = token.split('=');\n if (key && value) {\n context[key.trim()] = value.trim();\n }\n }\n\n return context;\n}\n\n/**\n * Converts qualifier defaults token to structured format\n * Example: \"language=en-US,en-CA|territory=US\" -\\> \\{ language: [\"en-US\", \"en-CA\"], territory: [\"US\"] \\}\n * @public\n */\nexport function parseQualifierDefaults(qualifierDefaults: string): Record<string, string[]> {\n const defaults: Record<string, string[]> = {};\n\n const tokens = qualifierDefaults.split('|');\n for (const token of tokens) {\n const [key, values] = token.split('=');\n if (key && values) {\n defaults[key.trim()] = values.split(',').map((v) => v.trim());\n }\n }\n\n return defaults;\n}\n\n/**\n * Converts resource types string to array\n * Example: \"json,string\" -\\> [\"json\", \"string\"]\n * @public\n */\nexport function parseResourceTypes(resourceTypes: string): string[] {\n return resourceTypes\n .split(',')\n .map((t) => t.trim())\n .filter((t) => t.length > 0);\n}\n\n/**\n * Extracts the directory path from a file or directory path\n * If the path appears to be a directory (no extension), returns it as-is\n * If the path appears to be a file, returns the parent directory\n * @public\n */\nexport function extractDirectoryPath(path: string): string {\n if (!path) return '';\n\n // Normalize path separators\n const normalizedPath = path.replace(/\\\\/g, '/');\n\n // Check if it looks like a file (has an extension)\n const parts = normalizedPath.split('/');\n const lastPart = parts[parts.length - 1];\n\n // If the last part has an extension, treat as file and return directory\n if (lastPart.includes('.') && !lastPart.startsWith('.')) {\n return parts.slice(0, -1).join('/') || '/';\n }\n\n // Otherwise, treat as directory\n return normalizedPath;\n}\n\n/**\n * Determines if a path appears to be a file (has extension) or directory\n * @public\n */\nexport function isFilePath(path: string): boolean {\n if (!path) return false;\n\n const parts = path.split('/');\n const lastPart = parts[parts.length - 1];\n\n // Has extension and doesn't start with dot (hidden files)\n return lastPart.includes('.') && !lastPart.startsWith('.');\n}\n"]}
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { webcrypto } from 'crypto';
23
+ import { TextEncoder, TextDecoder } from 'util';
24
+ // Setup Web Crypto API using Node.js webcrypto
25
+ Object.defineProperty(global, 'crypto', {
26
+ value: webcrypto,
27
+ writable: true,
28
+ configurable: true
29
+ });
30
+ // Setup TextEncoder/TextDecoder for Node environment
31
+ Object.defineProperty(global, 'TextEncoder', {
32
+ value: TextEncoder,
33
+ writable: true,
34
+ configurable: true
35
+ });
36
+ Object.defineProperty(global, 'TextDecoder', {
37
+ value: TextDecoder,
38
+ writable: true,
39
+ configurable: true
40
+ });
41
+ // Mock DataTransfer for File API testing
42
+ class MockDataTransfer {
43
+ constructor() {
44
+ const fileArray = [];
45
+ this.items = {
46
+ add: (file) => {
47
+ fileArray.push(file);
48
+ this.files = createFileList(fileArray);
49
+ }
50
+ };
51
+ this.files = createFileList([]);
52
+ }
53
+ }
54
+ function createFileList(files) {
55
+ const fileList = {
56
+ length: files.length,
57
+ item: (index) => files[index] || null,
58
+ [Symbol.iterator]: function* () {
59
+ for (const file of files) {
60
+ yield file;
61
+ }
62
+ }
63
+ };
64
+ for (let i = 0; i < files.length; i++) {
65
+ fileList[i] = files[i];
66
+ }
67
+ return fileList;
68
+ }
69
+ Object.defineProperty(global, 'DataTransfer', {
70
+ value: MockDataTransfer,
71
+ writable: true,
72
+ configurable: true
73
+ });
74
+ //# sourceMappingURL=setupTests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupTests.js","sourceRoot":"","sources":["../../src/test/setupTests.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEhD,+CAA+C;AAC/C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;IACtC,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,qDAAqD;AACrD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE;IAC3C,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE;IAC3C,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,yCAAyC;AACzC,MAAM,gBAAgB;IAIpB;QACE,MAAM,SAAS,GAAW,EAAE,CAAC;QAE7B,IAAI,CAAC,KAAK,GAAG;YACX,GAAG,EAAE,CAAC,IAAU,EAAE,EAAE;gBAClB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACrB,IAAI,CAAC,KAAK,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;YACzC,CAAC;SACF,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;CACF;AAED,SAAS,cAAc,CAAC,KAAa;IACnC,MAAM,QAAQ,GAAG;QACf,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI;QAC7C,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;YAC1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,IAAI,CAAC;YACb,CAAC;QACH,CAAC;KACF,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,QAA4C,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,QAA+B,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE;IAC5C,KAAK,EAAE,gBAAgB;IACvB,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { webcrypto } from 'crypto';\nimport { TextEncoder, TextDecoder } from 'util';\n\n// Setup Web Crypto API using Node.js webcrypto\nObject.defineProperty(global, 'crypto', {\n value: webcrypto,\n writable: true,\n configurable: true\n});\n\n// Setup TextEncoder/TextDecoder for Node environment\nObject.defineProperty(global, 'TextEncoder', {\n value: TextEncoder,\n writable: true,\n configurable: true\n});\n\nObject.defineProperty(global, 'TextDecoder', {\n value: TextDecoder,\n writable: true,\n configurable: true\n});\n\n// Mock DataTransfer for File API testing\nclass MockDataTransfer {\n items: { add: (file: File) => void };\n files: FileList;\n\n constructor() {\n const fileArray: File[] = [];\n\n this.items = {\n add: (file: File) => {\n fileArray.push(file);\n this.files = createFileList(fileArray);\n }\n };\n\n this.files = createFileList([]);\n }\n}\n\nfunction createFileList(files: File[]): FileList {\n const fileList = {\n length: files.length,\n item: (index: number) => files[index] || null,\n [Symbol.iterator]: function* () {\n for (const file of files) {\n yield file;\n }\n }\n };\n\n for (let i = 0; i < files.length; i++) {\n (fileList as unknown as Record<number, File>)[i] = files[i];\n }\n\n return fileList as unknown as FileList;\n}\n\nObject.defineProperty(global, 'DataTransfer', {\n value: MockDataTransfer,\n writable: true,\n configurable: true\n});\n"]}
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import '@fgv/ts-utils-jest';
23
+ import { BrowserHashProvider } from '../../packlets/crypto';
24
+ describe('BrowserHashProvider', () => {
25
+ describe('hashString', () => {
26
+ test('successfully hashes a string with SHA-256', async () => {
27
+ const result = await BrowserHashProvider.hashString('test data', 'SHA-256');
28
+ expect(result).toSucceedAndSatisfy((hash) => {
29
+ expect(typeof hash).toBe('string');
30
+ expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters
31
+ });
32
+ });
33
+ test('successfully hashes a string with SHA-1', async () => {
34
+ const result = await BrowserHashProvider.hashString('test data', 'SHA-1');
35
+ expect(result).toSucceedAndSatisfy((hash) => {
36
+ expect(typeof hash).toBe('string');
37
+ expect(hash).toMatch(/^[a-f0-9]{40}$/); // SHA-1 produces 40 hex characters
38
+ });
39
+ });
40
+ test('successfully hashes a string with SHA-512', async () => {
41
+ const result = await BrowserHashProvider.hashString('test data', 'SHA-512');
42
+ expect(result).toSucceedAndSatisfy((hash) => {
43
+ expect(typeof hash).toBe('string');
44
+ expect(hash).toMatch(/^[a-f0-9]{128}$/); // SHA-512 produces 128 hex characters
45
+ });
46
+ });
47
+ test('uses SHA-256 as default algorithm', async () => {
48
+ const result = await BrowserHashProvider.hashString('test data');
49
+ expect(result).toSucceedAndSatisfy((hash) => {
50
+ expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters
51
+ });
52
+ });
53
+ test('produces consistent hash for same input', async () => {
54
+ const input = 'consistent input';
55
+ const result1 = await BrowserHashProvider.hashString(input);
56
+ const result2 = await BrowserHashProvider.hashString(input);
57
+ expect(result1).toSucceed();
58
+ expect(result2).toSucceed();
59
+ if (result1.isSuccess() && result2.isSuccess()) {
60
+ expect(result1.value).toBe(result2.value);
61
+ }
62
+ });
63
+ test('produces different hashes for different inputs', async () => {
64
+ const result1 = await BrowserHashProvider.hashString('input1');
65
+ const result2 = await BrowserHashProvider.hashString('input2');
66
+ expect(result1).toSucceed();
67
+ expect(result2).toSucceed();
68
+ if (result1.isSuccess() && result2.isSuccess()) {
69
+ expect(result1.value).not.toBe(result2.value);
70
+ }
71
+ });
72
+ test('handles empty string input', async () => {
73
+ const result = await BrowserHashProvider.hashString('');
74
+ expect(result).toSucceed();
75
+ });
76
+ test('handles unicode input', async () => {
77
+ const result = await BrowserHashProvider.hashString('🚀 Unicode test 测试');
78
+ expect(result).toSucceedAndSatisfy((hash) => {
79
+ expect(hash).toMatch(/^[a-f0-9]{64}$/);
80
+ });
81
+ });
82
+ test('fails when crypto.subtle is unavailable', async () => {
83
+ const originalCrypto = global.crypto;
84
+ // @ts-ignore - Intentionally removing crypto for test
85
+ delete global.crypto;
86
+ const result = await BrowserHashProvider.hashString('test');
87
+ expect(result).toFailWith(/Hash computation failed/);
88
+ global.crypto = originalCrypto;
89
+ });
90
+ test('handles invalid algorithm gracefully', async () => {
91
+ const result = await BrowserHashProvider.hashString('test', 'INVALID-ALG');
92
+ expect(result).toFailWith(/Hash computation failed/);
93
+ });
94
+ });
95
+ describe('hashParts', () => {
96
+ test('hashes multiple parts with default separator', async () => {
97
+ const parts = ['part1', 'part2', 'part3'];
98
+ const result = await BrowserHashProvider.hashParts(parts);
99
+ expect(result).toSucceedAndSatisfy((hash) => {
100
+ expect(hash).toMatch(/^[a-f0-9]{64}$/);
101
+ });
102
+ });
103
+ test('hashes multiple parts with custom separator', async () => {
104
+ const parts = ['part1', 'part2', 'part3'];
105
+ const result1 = await BrowserHashProvider.hashParts(parts, 'SHA-256', '|');
106
+ const result2 = await BrowserHashProvider.hashParts(parts, 'SHA-256', ',');
107
+ expect(result1).toSucceed();
108
+ expect(result2).toSucceed();
109
+ if (result1.isSuccess() && result2.isSuccess()) {
110
+ expect(result1.value).not.toBe(result2.value);
111
+ }
112
+ });
113
+ test('produces same hash as hashString for joined parts', async () => {
114
+ const parts = ['a', 'b', 'c'];
115
+ const separator = '-';
116
+ const joined = parts.join(separator);
117
+ const partsResult = await BrowserHashProvider.hashParts(parts, 'SHA-256', separator);
118
+ const stringResult = await BrowserHashProvider.hashString(joined);
119
+ expect(partsResult).toSucceed();
120
+ expect(stringResult).toSucceed();
121
+ if (partsResult.isSuccess() && stringResult.isSuccess()) {
122
+ expect(partsResult.value).toBe(stringResult.value);
123
+ }
124
+ });
125
+ test('handles empty array', async () => {
126
+ const result = await BrowserHashProvider.hashParts([]);
127
+ expect(result).toSucceed();
128
+ });
129
+ test('handles single part', async () => {
130
+ const result = await BrowserHashProvider.hashParts(['single']);
131
+ const stringResult = await BrowserHashProvider.hashString('single');
132
+ expect(result).toSucceed();
133
+ expect(stringResult).toSucceed();
134
+ if (result.isSuccess() && stringResult.isSuccess()) {
135
+ expect(result.value).toBe(stringResult.value);
136
+ }
137
+ });
138
+ });
139
+ });
140
+ //# sourceMappingURL=browserHashProvider.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserHashProvider.test.js","sourceRoot":"","sources":["../../../src/test/unit/browserHashProvider.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAA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YACpE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;YAC3B,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC;gBACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport '@fgv/ts-utils-jest';\nimport { BrowserHashProvider } from '../../packlets/crypto';\n\ndescribe('BrowserHashProvider', () => {\n describe('hashString', () => {\n test('successfully hashes a string with SHA-256', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-256');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters\n });\n });\n\n test('successfully hashes a string with SHA-1', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-1');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{40}$/); // SHA-1 produces 40 hex characters\n });\n });\n\n test('successfully hashes a string with SHA-512', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-512');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{128}$/); // SHA-512 produces 128 hex characters\n });\n });\n\n test('uses SHA-256 as default algorithm', async () => {\n const result = await BrowserHashProvider.hashString('test data');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters\n });\n });\n\n test('produces consistent hash for same input', async () => {\n const input = 'consistent input';\n const result1 = await BrowserHashProvider.hashString(input);\n const result2 = await BrowserHashProvider.hashString(input);\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).toBe(result2.value);\n }\n });\n\n test('produces different hashes for different inputs', async () => {\n const result1 = await BrowserHashProvider.hashString('input1');\n const result2 = await BrowserHashProvider.hashString('input2');\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).not.toBe(result2.value);\n }\n });\n\n test('handles empty string input', async () => {\n const result = await BrowserHashProvider.hashString('');\n expect(result).toSucceed();\n });\n\n test('handles unicode input', async () => {\n const result = await BrowserHashProvider.hashString('🚀 Unicode test 测试');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n test('fails when crypto.subtle is unavailable', async () => {\n const originalCrypto = global.crypto;\n // @ts-ignore - Intentionally removing crypto for test\n delete global.crypto;\n const result = await BrowserHashProvider.hashString('test');\n expect(result).toFailWith(/Hash computation failed/);\n global.crypto = originalCrypto;\n });\n\n test('handles invalid algorithm gracefully', async () => {\n const result = await BrowserHashProvider.hashString('test', 'INVALID-ALG');\n expect(result).toFailWith(/Hash computation failed/);\n });\n });\n\n describe('hashParts', () => {\n test('hashes multiple parts with default separator', async () => {\n const parts = ['part1', 'part2', 'part3'];\n const result = await BrowserHashProvider.hashParts(parts);\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n test('hashes multiple parts with custom separator', async () => {\n const parts = ['part1', 'part2', 'part3'];\n const result1 = await BrowserHashProvider.hashParts(parts, 'SHA-256', '|');\n const result2 = await BrowserHashProvider.hashParts(parts, 'SHA-256', ',');\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).not.toBe(result2.value);\n }\n });\n\n test('produces same hash as hashString for joined parts', async () => {\n const parts = ['a', 'b', 'c'];\n const separator = '-';\n const joined = parts.join(separator);\n const partsResult = await BrowserHashProvider.hashParts(parts, 'SHA-256', separator);\n const stringResult = await BrowserHashProvider.hashString(joined);\n expect(partsResult).toSucceed();\n expect(stringResult).toSucceed();\n if (partsResult.isSuccess() && stringResult.isSuccess()) {\n expect(partsResult.value).toBe(stringResult.value);\n }\n });\n\n test('handles empty array', async () => {\n const result = await BrowserHashProvider.hashParts([]);\n expect(result).toSucceed();\n });\n\n test('handles single part', async () => {\n const result = await BrowserHashProvider.hashParts(['single']);\n const stringResult = await BrowserHashProvider.hashString('single');\n expect(result).toSucceed();\n expect(stringResult).toSucceed();\n if (result.isSuccess() && stringResult.isSuccess()) {\n expect(result.value).toBe(stringResult.value);\n }\n });\n });\n});\n"]}