aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils.ts
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-02-06 20:01:19 -0500
committerAjay <[email protected]>2022-02-06 20:01:19 -0500
commit0b6ade4a1d9c547fdc475387e7a581fa8a3f5415 (patch)
tree18bd1dd1e63e34305de76b48a6e8c6e8d3ba8368 /src/utils.ts
parent816e9a78be62ff624214d26b487b0eef562ca62f (diff)
downloadSponsorBlock-0b6ade4a1d9c547fdc475387e7a581fa8a3f5415.tar.gz
SponsorBlock-0b6ade4a1d9c547fdc475387e7a581fa8a3f5415.zip
Improve typing on getHash
Diffstat (limited to 'src/utils.ts')
-rw-r--r--src/utils.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/utils.ts b/src/utils.ts
index 5b3c71dc..087f40ab 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,5 +1,5 @@
import Config from "./config";
-import { CategorySelection, SponsorTime, FetchResponse, BackgroundScriptContainer, Registration } from "./types";
+import { CategorySelection, SponsorTime, FetchResponse, BackgroundScriptContainer, Registration, HashedValue } from "./types";
import * as CompileConfig from "../config.json";
import { findValidElementFromSelector } from "./utils/pageUtils";
@@ -475,10 +475,10 @@ export default class Utils {
return typeof(browser) !== "undefined";
}
- async getHash(value: string, times = 5000): Promise<string> {
- if (times <= 0) return "";
+ async getHash<T extends string>(value: T, times = 5000): Promise<T & HashedValue> {
+ if (times <= 0) return "" as T & HashedValue;
- let hashHex = value;
+ let hashHex: string = value;
for (let i = 0; i < times; i++) {
const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(hashHex).buffer);
@@ -486,6 +486,6 @@ export default class Utils {
hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
- return hashHex;
+ return hashHex as T & HashedValue;
}
}