mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 08:05:13 +00:00
accepts an IntegrityMetadata like object as input
This commit is contained in:
parent
5ad019029b
commit
f8aff38a6b
2 changed files with 8 additions and 3 deletions
|
@ -51,12 +51,17 @@ export class IntegrityMetadata implements IntegrityMetadataLike {
|
|||
alg: PrioritizedHashAlgorithm;
|
||||
val: string;
|
||||
opt: string[];
|
||||
constructor(integrity: string | null | undefined) {
|
||||
constructor(integrity: IntegrityMetadataLike | string | null | undefined) {
|
||||
const integrityString =
|
||||
typeof integrity === "object" && integrity !== null
|
||||
? IntegrityMetadata.stringify(integrity)
|
||||
: String(integrity ?? "").trim();
|
||||
|
||||
const {
|
||||
alg = "",
|
||||
val = "",
|
||||
opt,
|
||||
} = IntegrityMetadataRegex.exec((integrity ?? "").trim())?.groups ?? {};
|
||||
} = IntegrityMetadataRegex.exec(integrityString)?.groups ?? {};
|
||||
|
||||
Object.assign(this, {
|
||||
alg,
|
||||
|
|
|
@ -50,7 +50,7 @@ test("accepts options", function () {
|
|||
});
|
||||
});
|
||||
|
||||
test.todo("accepts an IntegrityMetadata like object as input", function () {
|
||||
test("accepts an IntegrityMetadata like object as input", function () {
|
||||
const integrityMetadata = new IntegrityMetadata({
|
||||
alg: "sha256",
|
||||
val: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
|
||||
|
|
Loading…
Add table
Reference in a new issue