@fgv/ts-web-extras 5.0.0
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.
- package/.rush/temp/86c9c1ad46e237e0b957c2442bf0355cf39babba.tar.log +121 -0
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +40 -0
- package/.rush/temp/operation/build/all.log +40 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +40 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +624 -0
- package/config/api-extractor.json +343 -0
- package/config/jest.config.json +16 -0
- package/config/rig.json +16 -0
- package/dist/ts-web-extras.d.ts +574 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/docs/index.md +34 -0
- package/docs/ts-web-extras.browserhashprovider.hashparts.md +88 -0
- package/docs/ts-web-extras.browserhashprovider.hashstring.md +72 -0
- package/docs/ts-web-extras.browserhashprovider.md +66 -0
- package/docs/ts-web-extras.exportasjson.md +70 -0
- package/docs/ts-web-extras.exportusingfilesystemapi.md +104 -0
- package/docs/ts-web-extras.extractdirectorypath.md +52 -0
- package/docs/ts-web-extras.fileapitreeaccessors.create.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +54 -0
- package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.md +114 -0
- package/docs/ts-web-extras.filepickeraccepttype.accept.md +11 -0
- package/docs/ts-web-extras.filepickeraccepttype.description.md +11 -0
- package/docs/ts-web-extras.filepickeraccepttype.md +75 -0
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +11 -0
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +146 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +50 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +15 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +52 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +15 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.md +92 -0
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +11 -0
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +11 -0
- package/docs/ts-web-extras.filesystemgetfileoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +50 -0
- package/docs/ts-web-extras.filesystemhandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemhandle_2.md +119 -0
- package/docs/ts-web-extras.filesystemhandle_2.name.md +11 -0
- package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +52 -0
- package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +52 -0
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +58 -0
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +11 -0
- package/docs/ts-web-extras.filesystemremoveoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +11 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.md +57 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +50 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +50 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +50 -0
- package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +13 -0
- package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +56 -0
- package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +56 -0
- package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +76 -0
- package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +76 -0
- package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +72 -0
- package/docs/ts-web-extras.filetreehelpers.md +102 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +11 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +100 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +11 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +11 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +11 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.md +79 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +11 -0
- package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +11 -0
- package/docs/ts-web-extras.ifilelisttreeinitializer.md +58 -0
- package/docs/ts-web-extras.ifilemetadata.lastmodified.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.md +124 -0
- package/docs/ts-web-extras.ifilemetadata.name.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.path.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.size.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.type.md +11 -0
- package/docs/ts-web-extras.ifsaccessapis.md +56 -0
- package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +52 -0
- package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +52 -0
- package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +52 -0
- package/docs/ts-web-extras.isdirectoryhandle.md +56 -0
- package/docs/ts-web-extras.isfilehandle.md +56 -0
- package/docs/ts-web-extras.isfilepath.md +52 -0
- package/docs/ts-web-extras.iurlconfigoptions.config.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.input.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.interactive.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.md +286 -0
- package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.zippath.md +13 -0
- package/docs/ts-web-extras.md +512 -0
- package/docs/ts-web-extras.parsecontextfilter.md +52 -0
- package/docs/ts-web-extras.parsequalifierdefaults.md +52 -0
- package/docs/ts-web-extras.parseresourcetypes.md +52 -0
- package/docs/ts-web-extras.parseurlparameters.md +17 -0
- package/docs/ts-web-extras.safeshowdirectorypicker.md +72 -0
- package/docs/ts-web-extras.safeshowopenfilepicker.md +72 -0
- package/docs/ts-web-extras.safeshowsavefilepicker.md +72 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.md +96 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +11 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.md +134 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.types.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.md +134 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.types.md +11 -0
- package/docs/ts-web-extras.supportsfilesystemaccess.md +56 -0
- package/docs/ts-web-extras.treeinitializer.md +15 -0
- package/docs/ts-web-extras.wellknowndirectory.md +13 -0
- package/docs/ts-web-extras.windowwithfsaccess.md +15 -0
- package/etc/ts-web-extras.api.md +310 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +58 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/crypto/browserHashProvider.d.ts +24 -0
- package/lib/packlets/crypto/browserHashProvider.d.ts.map +1 -0
- package/lib/packlets/crypto/browserHashProvider.js +70 -0
- package/lib/packlets/crypto/browserHashProvider.js.map +1 -0
- package/lib/packlets/crypto/index.d.ts +6 -0
- package/lib/packlets/crypto/index.d.ts.map +1 -0
- package/lib/packlets/crypto/index.js +43 -0
- package/lib/packlets/crypto/index.js.map +1 -0
- package/lib/packlets/file-api-types/index.d.ts +205 -0
- package/lib/packlets/file-api-types/index.d.ts.map +1 -0
- package/lib/packlets/file-api-types/index.js +166 -0
- package/lib/packlets/file-api-types/index.js.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +129 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js +334 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts +6 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.js +43 -0
- package/lib/packlets/file-tree/index.js.map +1 -0
- package/lib/packlets/helpers/fileTreeHelpers.d.ts +60 -0
- package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -0
- package/lib/packlets/helpers/fileTreeHelpers.js +102 -0
- package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -0
- package/lib/packlets/helpers/index.d.ts +6 -0
- package/lib/packlets/helpers/index.d.ts.map +1 -0
- package/lib/packlets/helpers/index.js +63 -0
- package/lib/packlets/helpers/index.js.map +1 -0
- package/lib/packlets/url-utils/index.d.ts +6 -0
- package/lib/packlets/url-utils/index.d.ts.map +1 -0
- package/lib/packlets/url-utils/index.js +43 -0
- package/lib/packlets/url-utils/index.js.map +1 -0
- package/lib/packlets/url-utils/urlParams.d.ts +94 -0
- package/lib/packlets/url-utils/urlParams.d.ts.map +1 -0
- package/lib/packlets/url-utils/urlParams.js +165 -0
- package/lib/packlets/url-utils/urlParams.js.map +1 -0
- package/lib/test/setupTests.d.ts +2 -0
- package/lib/test/setupTests.d.ts.map +1 -0
- package/lib/test/setupTests.js +76 -0
- package/lib/test/setupTests.js.map +1 -0
- package/lib/test/unit/browserHashProvider.test.d.ts +2 -0
- package/lib/test/unit/browserHashProvider.test.d.ts.map +1 -0
- package/lib/test/unit/browserHashProvider.test.js +142 -0
- package/lib/test/unit/browserHashProvider.test.js.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js +1139 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -0
- package/lib/test/unit/fileApiTypes.test.d.ts +2 -0
- package/lib/test/unit/fileApiTypes.test.d.ts.map +1 -0
- package/lib/test/unit/fileApiTypes.test.js +444 -0
- package/lib/test/unit/fileApiTypes.test.js.map +1 -0
- package/lib/test/unit/fileTreeHelpers.test.d.ts +2 -0
- package/lib/test/unit/fileTreeHelpers.test.d.ts.map +1 -0
- package/lib/test/unit/fileTreeHelpers.test.js +592 -0
- package/lib/test/unit/fileTreeHelpers.test.js.map +1 -0
- package/lib/test/unit/urlParams.test.d.ts +2 -0
- package/lib/test/unit/urlParams.test.d.ts.map +1 -0
- package/lib/test/unit/urlParams.test.js +395 -0
- package/lib/test/unit/urlParams.test.js.map +1 -0
- package/lib/test/utils/testHelpers.d.ts +51 -0
- package/lib/test/utils/testHelpers.d.ts.map +1 -0
- package/lib/test/utils/testHelpers.js +133 -0
- package/lib/test/utils/testHelpers.js.map +1 -0
- package/package.json +68 -0
- package/rush-logs/ts-web-extras.build.cache.log +3 -0
- package/rush-logs/ts-web-extras.build.log +40 -0
- package/src/index.ts +47 -0
- package/src/packlets/crypto/browserHashProvider.ts +73 -0
- package/src/packlets/crypto/index.ts +28 -0
- package/src/packlets/file-api-types/index.ts +345 -0
- package/src/packlets/file-tree/fileApiTreeAccessors.ts +420 -0
- package/src/packlets/file-tree/index.ts +28 -0
- package/src/packlets/helpers/fileTreeHelpers.ts +107 -0
- package/src/packlets/helpers/index.ts +28 -0
- package/src/packlets/url-utils/index.ts +28 -0
- package/src/packlets/url-utils/urlParams.ts +245 -0
- package/src/test/setupTests.ts +87 -0
- package/src/test/unit/browserHashProvider.test.ts +155 -0
- package/src/test/unit/browserHashProvider.test.ts.bak +376 -0
- package/src/test/unit/fileApiTreeAccessors.test.ts +1318 -0
- package/src/test/unit/fileApiTypes.test.ts +551 -0
- package/src/test/unit/fileTreeHelpers.test.ts +694 -0
- package/src/test/unit/urlParams.test.ts +464 -0
- package/src/test/utils/testHelpers.ts +155 -0
- package/temp/build/typescript/ts_l9Fw4VUO.json +1 -0
- package/temp/coverage/base.css +224 -0
- package/temp/coverage/block-navigation.js +87 -0
- package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
- package/temp/coverage/crypto/index.html +116 -0
- package/temp/coverage/favicon.png +0 -0
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1345 -0
- package/temp/coverage/file-tree/index.html +116 -0
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +406 -0
- package/temp/coverage/helpers/index.html +116 -0
- package/temp/coverage/index.html +161 -0
- package/temp/coverage/lcov-report/base.css +224 -0
- package/temp/coverage/lcov-report/block-navigation.js +87 -0
- package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
- package/temp/coverage/lcov-report/crypto/index.html +116 -0
- package/temp/coverage/lcov-report/favicon.png +0 -0
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1345 -0
- package/temp/coverage/lcov-report/file-tree/index.html +116 -0
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +406 -0
- package/temp/coverage/lcov-report/helpers/index.html +116 -0
- package/temp/coverage/lcov-report/index.html +161 -0
- package/temp/coverage/lcov-report/prettify.css +1 -0
- package/temp/coverage/lcov-report/prettify.js +2 -0
- package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/temp/coverage/lcov-report/sorter.js +210 -0
- package/temp/coverage/lcov-report/url-utils/index.html +116 -0
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +820 -0
- package/temp/coverage/lcov.info +1096 -0
- package/temp/coverage/prettify.css +1 -0
- package/temp/coverage/prettify.js +2 -0
- package/temp/coverage/sort-arrow-sprite.png +0 -0
- package/temp/coverage/sorter.js +210 -0
- package/temp/coverage/url-utils/index.html +116 -0
- package/temp/coverage/url-utils/urlParams.ts.html +820 -0
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/63/package_63a8257b0e4d0e7ff33f927d75f27a75 +53 -0
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
- package/temp/ts-web-extras.api.json +5040 -0
- package/temp/ts-web-extras.api.md +310 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,376 @@
|
|
|
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
|
+
import '@fgv/ts-utils-jest';
|
|
24
|
+
import { BrowserHashProvider, BrowserHashingNormalizer } from '../../packlets/crypto';
|
|
25
|
+
|
|
26
|
+
describe('BrowserHashProvider', () => {
|
|
27
|
+
describe('Static factory methods', () => {
|
|
28
|
+
test('createSha256Normalizer returns BrowserHashingNormalizer with SHA-256', () => {
|
|
29
|
+
const normalizer = BrowserHashProvider.createSha256Normalizer();
|
|
30
|
+
expect(normalizer).toBeInstanceOf(BrowserHashingNormalizer);
|
|
31
|
+
expect(normalizer.algorithm).toBe('SHA-256');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('createSha1Normalizer returns BrowserHashingNormalizer with SHA-1', () => {
|
|
35
|
+
const normalizer = BrowserHashProvider.createSha1Normalizer();
|
|
36
|
+
expect(normalizer).toBeInstanceOf(BrowserHashingNormalizer);
|
|
37
|
+
expect(normalizer.algorithm).toBe('SHA-1');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('createSha512Normalizer returns BrowserHashingNormalizer with SHA-512', () => {
|
|
41
|
+
const normalizer = BrowserHashProvider.createSha512Normalizer();
|
|
42
|
+
expect(normalizer).toBeInstanceOf(BrowserHashingNormalizer);
|
|
43
|
+
expect(normalizer.algorithm).toBe('SHA-512');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('hashString', () => {
|
|
48
|
+
test('successfully hashes a string with SHA-256', async () => {
|
|
49
|
+
const result = await BrowserHashProvider.hashString('test data', 'SHA-256');
|
|
50
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
51
|
+
expect(typeof hash).toBe('string');
|
|
52
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('successfully hashes a string with SHA-1', async () => {
|
|
57
|
+
const result = await BrowserHashProvider.hashString('test data', 'SHA-1');
|
|
58
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
59
|
+
expect(typeof hash).toBe('string');
|
|
60
|
+
expect(hash).toMatch(/^[a-f0-9]{40}$/); // SHA-1 produces 40 hex characters
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('successfully hashes a string with SHA-512', async () => {
|
|
65
|
+
const result = await BrowserHashProvider.hashString('test data', 'SHA-512');
|
|
66
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
67
|
+
expect(typeof hash).toBe('string');
|
|
68
|
+
expect(hash).toMatch(/^[a-f0-9]{128}$/); // SHA-512 produces 128 hex characters
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('uses SHA-256 as default algorithm', async () => {
|
|
73
|
+
const result = await BrowserHashProvider.hashString('test data');
|
|
74
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
75
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('produces consistent hash for same input', async () => {
|
|
80
|
+
const input = 'consistent input';
|
|
81
|
+
const result1 = await BrowserHashProvider.hashString(input);
|
|
82
|
+
const result2 = await BrowserHashProvider.hashString(input);
|
|
83
|
+
|
|
84
|
+
expect(result1).toSucceed();
|
|
85
|
+
expect(result2).toSucceed();
|
|
86
|
+
if (result1.isSuccess() && result2.isSuccess()) {
|
|
87
|
+
expect(result1.value).toBe(result2.value);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('produces different hashes for different inputs', async () => {
|
|
92
|
+
const result1 = await BrowserHashProvider.hashString('input1');
|
|
93
|
+
const result2 = await BrowserHashProvider.hashString('input2');
|
|
94
|
+
|
|
95
|
+
expect(result1).toSucceed();
|
|
96
|
+
expect(result2).toSucceed();
|
|
97
|
+
if (result1.isSuccess() && result2.isSuccess()) {
|
|
98
|
+
expect(result1.value).not.toBe(result2.value);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('handles empty string input', async () => {
|
|
103
|
+
const result = await BrowserHashProvider.hashString('');
|
|
104
|
+
expect(result).toSucceed();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('handles unicode input', async () => {
|
|
108
|
+
const result = await BrowserHashProvider.hashString('🚀 Unicode test 测试');
|
|
109
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
110
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('fails when crypto.subtle is unavailable', async () => {
|
|
115
|
+
const originalCrypto = global.crypto;
|
|
116
|
+
// @ts-ignore - Intentionally removing crypto for test
|
|
117
|
+
delete global.crypto;
|
|
118
|
+
|
|
119
|
+
const result = await BrowserHashProvider.hashString('test');
|
|
120
|
+
expect(result).toFailWith(/Hash computation failed/);
|
|
121
|
+
|
|
122
|
+
global.crypto = originalCrypto;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('handles invalid algorithm gracefully', async () => {
|
|
126
|
+
const result = await BrowserHashProvider.hashString('test', 'INVALID-ALG');
|
|
127
|
+
expect(result).toFailWith(/Hash computation failed/);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('hashParts', () => {
|
|
132
|
+
test('hashes multiple parts with default separator', async () => {
|
|
133
|
+
const parts = ['part1', 'part2', 'part3'];
|
|
134
|
+
const result = await BrowserHashProvider.hashParts(parts);
|
|
135
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
136
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('hashes multiple parts with custom separator', async () => {
|
|
141
|
+
const parts = ['part1', 'part2', 'part3'];
|
|
142
|
+
const result1 = await BrowserHashProvider.hashParts(parts, 'SHA-256', '|');
|
|
143
|
+
const result2 = await BrowserHashProvider.hashParts(parts, 'SHA-256', ',');
|
|
144
|
+
|
|
145
|
+
expect(result1).toSucceed();
|
|
146
|
+
expect(result2).toSucceed();
|
|
147
|
+
if (result1.isSuccess() && result2.isSuccess()) {
|
|
148
|
+
expect(result1.value).not.toBe(result2.value);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('produces same hash as hashString for joined parts', async () => {
|
|
153
|
+
const parts = ['a', 'b', 'c'];
|
|
154
|
+
const separator = '-';
|
|
155
|
+
const joined = parts.join(separator);
|
|
156
|
+
|
|
157
|
+
const partsResult = await BrowserHashProvider.hashParts(parts, 'SHA-256', separator);
|
|
158
|
+
const stringResult = await BrowserHashProvider.hashString(joined);
|
|
159
|
+
|
|
160
|
+
expect(partsResult).toSucceed();
|
|
161
|
+
expect(stringResult).toSucceed();
|
|
162
|
+
if (partsResult.isSuccess() && stringResult.isSuccess()) {
|
|
163
|
+
expect(partsResult.value).toBe(stringResult.value);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('handles empty array', async () => {
|
|
168
|
+
const result = await BrowserHashProvider.hashParts([]);
|
|
169
|
+
expect(result).toSucceed();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('handles single part', async () => {
|
|
173
|
+
const result = await BrowserHashProvider.hashParts(['single']);
|
|
174
|
+
const stringResult = await BrowserHashProvider.hashString('single');
|
|
175
|
+
|
|
176
|
+
expect(result).toSucceed();
|
|
177
|
+
expect(stringResult).toSucceed();
|
|
178
|
+
if (result.isSuccess() && stringResult.isSuccess()) {
|
|
179
|
+
expect(result.value).toBe(stringResult.value);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('BrowserHashingNormalizer', () => {
|
|
186
|
+
describe('constructor', () => {
|
|
187
|
+
test('creates instance with default SHA-256 algorithm', () => {
|
|
188
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
189
|
+
expect(normalizer).toBeInstanceOf(BrowserHashingNormalizer);
|
|
190
|
+
expect(normalizer.algorithm).toBe('SHA-256');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('creates instance with custom algorithm', () => {
|
|
194
|
+
const normalizer = new BrowserHashingNormalizer('SHA-512');
|
|
195
|
+
expect(normalizer.algorithm).toBe('SHA-512');
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('hashAsync', () => {
|
|
200
|
+
test('hashes array of strings', async () => {
|
|
201
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
202
|
+
const result = await normalizer.hashAsync(['test1', 'test2']);
|
|
203
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
204
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('produces consistent results', async () => {
|
|
209
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
210
|
+
const parts = ['consistent', 'parts'];
|
|
211
|
+
|
|
212
|
+
const result1 = await normalizer.hashAsync(parts);
|
|
213
|
+
const result2 = await normalizer.hashAsync(parts);
|
|
214
|
+
|
|
215
|
+
expect(result1).toSucceed();
|
|
216
|
+
expect(result2).toSucceed();
|
|
217
|
+
if (result1.isSuccess() && result2.isSuccess()) {
|
|
218
|
+
expect(result1.value).toBe(result2.value);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe('normalizeAsync', () => {
|
|
224
|
+
test('normalizes primitive values', async () => {
|
|
225
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
226
|
+
|
|
227
|
+
const stringResult = await normalizer.normalizeAsync('test');
|
|
228
|
+
expect(stringResult).toSucceed();
|
|
229
|
+
|
|
230
|
+
const numberResult = await normalizer.normalizeAsync(42);
|
|
231
|
+
expect(numberResult).toSucceed();
|
|
232
|
+
|
|
233
|
+
const booleanResult = await normalizer.normalizeAsync(true);
|
|
234
|
+
expect(booleanResult).toSucceed();
|
|
235
|
+
|
|
236
|
+
const nullResult = await normalizer.normalizeAsync(null);
|
|
237
|
+
expect(nullResult).toSucceed();
|
|
238
|
+
|
|
239
|
+
const undefinedResult = await normalizer.normalizeAsync(undefined);
|
|
240
|
+
expect(undefinedResult).toSucceed();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test('normalizes arrays', async () => {
|
|
244
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
245
|
+
const array = ['item1', 'item2', 42, true];
|
|
246
|
+
|
|
247
|
+
const result = await normalizer.normalizeAsync(array);
|
|
248
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
249
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('normalizes nested arrays', async () => {
|
|
254
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
255
|
+
const nestedArray = ['item1', ['nested1', 'nested2'], 'item3'];
|
|
256
|
+
|
|
257
|
+
const result = await normalizer.normalizeAsync(nestedArray);
|
|
258
|
+
expect(result).toSucceed();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('normalizes objects', async () => {
|
|
262
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
263
|
+
const obj = {
|
|
264
|
+
name: 'test',
|
|
265
|
+
value: 42,
|
|
266
|
+
nested: { key: 'value' }
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const result = await normalizer.normalizeAsync(obj);
|
|
270
|
+
expect(result).toSucceedAndSatisfy(hash => {
|
|
271
|
+
expect(hash).toMatch(/^[a-f0-9]{64}$/);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('normalizes objects with consistent key ordering', async () => {
|
|
276
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
277
|
+
const obj1 = { b: 2, a: 1, c: 3 };
|
|
278
|
+
const obj2 = { a: 1, c: 3, b: 2 };
|
|
279
|
+
|
|
280
|
+
const result1 = await normalizer.normalizeAsync(obj1);
|
|
281
|
+
const result2 = await normalizer.normalizeAsync(obj2);
|
|
282
|
+
|
|
283
|
+
expect(result1).toSucceed();
|
|
284
|
+
expect(result2).toSucceed();
|
|
285
|
+
if (result1.isSuccess() && result2.isSuccess()) {
|
|
286
|
+
expect(result1.value).toBe(result2.value);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('normalizes Date objects', async () => {
|
|
291
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
292
|
+
const date = new Date('2025-01-01T00:00:00Z');
|
|
293
|
+
|
|
294
|
+
const result = await normalizer.normalizeAsync(date);
|
|
295
|
+
expect(result).toSucceed();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('normalizes RegExp objects', async () => {
|
|
299
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
300
|
+
const regex = /test.*pattern/gi;
|
|
301
|
+
|
|
302
|
+
const result = await normalizer.normalizeAsync(regex);
|
|
303
|
+
expect(result).toSucceed();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('normalizes complex nested structures', async () => {
|
|
307
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
308
|
+
const complex = {
|
|
309
|
+
id: 'test-id',
|
|
310
|
+
data: {
|
|
311
|
+
values: [1, 2, 3],
|
|
312
|
+
metadata: {
|
|
313
|
+
created: new Date('2025-01-01'),
|
|
314
|
+
tags: ['tag1', 'tag2']
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
flags: {
|
|
318
|
+
active: true,
|
|
319
|
+
validated: false
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const result = await normalizer.normalizeAsync(complex);
|
|
324
|
+
expect(result).toSucceed();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('handles bigint values', async () => {
|
|
328
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
329
|
+
const bigIntValue = BigInt(9007199254740991);
|
|
330
|
+
|
|
331
|
+
const result = await normalizer.normalizeAsync(bigIntValue);
|
|
332
|
+
expect(result).toSucceed();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('handles symbol values', async () => {
|
|
336
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
337
|
+
const symbolValue = Symbol('test');
|
|
338
|
+
|
|
339
|
+
const result = await normalizer.normalizeAsync(symbolValue);
|
|
340
|
+
expect(result).toSucceed();
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
describe('computeHash', () => {
|
|
345
|
+
test('throws error for synchronous operation', () => {
|
|
346
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
347
|
+
const result = normalizer.computeHash('test');
|
|
348
|
+
|
|
349
|
+
expect(result).toFailWith(/Synchronous hashing not supported in browser/);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
describe('algorithm getter', () => {
|
|
354
|
+
test('returns the correct algorithm', () => {
|
|
355
|
+
const sha256 = new BrowserHashingNormalizer('SHA-256');
|
|
356
|
+
expect(sha256.algorithm).toBe('SHA-256');
|
|
357
|
+
|
|
358
|
+
const sha1 = new BrowserHashingNormalizer('SHA-1');
|
|
359
|
+
expect(sha1.algorithm).toBe('SHA-1');
|
|
360
|
+
|
|
361
|
+
const sha512 = new BrowserHashingNormalizer('SHA-512');
|
|
362
|
+
expect(sha512.algorithm).toBe('SHA-512');
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
describe('_computeHashAsync', () => {
|
|
367
|
+
test('handles unexpected types gracefully', async () => {
|
|
368
|
+
const normalizer = new BrowserHashingNormalizer();
|
|
369
|
+
|
|
370
|
+
// Test with function (which is an unexpected type)
|
|
371
|
+
const func = () => 'test';
|
|
372
|
+
const result = await normalizer.normalizeAsync(func as unknown);
|
|
373
|
+
expect(result).toFailWith(/Unexpected type/);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
});
|