Skip to content

Commit

Permalink
return clone of the tags from getAllDecoders
Browse files Browse the repository at this point in the history
  • Loading branch information
irfan798 committed Dec 3, 2024
1 parent 7273ec6 commit 57f131d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ export class Tag implements ToCBOR, Decodeable {
}

/**
* Get all registered decoders as object
* Get all registered decoders clone of the map.
*/
public static getAllDecoders(): {
[key: string]: TagDecoder;
} {
return Object.fromEntries(this.#tags);
public static getAllDecoders(): ReadonlyMap<TagNumber, TagDecoder> {
return new Map(this.#tags);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ test('Tag Register and verify decoders', () => {

// Verify decoder is in all decoder list
const allDecoders = Tag.getAllDecoders();
assert.equal(allDecoders[9999], myDecoder);
assert.equal(allDecoders.get(9999), myDecoder);
assert.equal(allDecoders.has(9999), true);

// Remove the decoder from the registry
Tag.clearDecoder(9999);
Expand Down

0 comments on commit 57f131d

Please sign in to comment.