Skip to content

Commit 9692bb1

Browse files
committed
fix: added docs
1 parent 8eeb8c7 commit 9692bb1

2 files changed

Lines changed: 82 additions & 19 deletions

File tree

src/Types/NFTMap.ts

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,92 @@ export class NFTMap<V> {
77
this._map = new Map();
88
}
99

10-
// Helper function to convert an NFT to its string representation
10+
/**
11+
* Converts an NFT object into a string representation for use as a key in the map.
12+
* @param nft - The NFT to convert to a key.
13+
* @returns {string} - The string representation of the NFT (globalId).
14+
*/
1115
private toMapKey(nft: NFT): string {
1216
return nft.globalId();
1317
}
1418

15-
// Sets the value for a given NFT key
19+
/**
20+
* Sets the value for a given NFT key.
21+
* @param nft - The NFT key.
22+
* @param value - The value to associate with the NFT key.
23+
*/
1624
set(nft: NFT, value: V): void {
1725
this._map.set(this.toMapKey(nft), value);
1826
}
1927

20-
// Gets the value for a given NFT key
28+
/**
29+
* Gets the value associated with a given NFT key.
30+
* @param nft - The NFT key.
31+
* @returns - The value associated with the NFT key, or undefined if the key is not present.
32+
*/
2133
get(nft: NFT): V | undefined {
2234
return this._map.get(this.toMapKey(nft));
2335
}
2436

25-
// Checks if the map contains the given NFT key
37+
/**
38+
* Checks if the map contains the given NFT key.
39+
* @param nft - The NFT key.
40+
* @returns - True if the map contains the NFT key, otherwise false.
41+
*/
2642
has(nft: NFT): boolean {
2743
return this._map.has(this.toMapKey(nft));
2844
}
2945

30-
// Deletes a key-value pair by the given NFT key
46+
/**
47+
* Deletes the entry associated with a given NFT key.
48+
* @param nft - The NFT key.
49+
* @returns - True if the entry was successfully deleted, otherwise false.
50+
*/
3151
delete(nft: NFT): boolean {
3252
return this._map.delete(this.toMapKey(nft));
3353
}
3454

35-
// Clears the entire map
55+
/**
56+
* Clears all entries from the map.
57+
*/
3658
clear(): void {
3759
this._map.clear();
3860
}
3961

40-
// Returns the number of key-value pairs in the map
62+
/**
63+
* Returns the number of entries in the map.
64+
* @returns {number} - The size of the map.
65+
*/
4166
size(): number {
4267
return this._map.size;
4368
}
4469

45-
// Iterates through the map and applies the callback function to each entry
70+
/**
71+
* Iterates through the map and applies a callback function to each entry.
72+
* @param {Function} callback - A function that takes the value and NFT key as arguments.
73+
*/
4674
forEach(callback: (value: V, nft: NFT) => void): void {
4775
this._map.forEach((value, key) => {
4876
const nft = NFT.fromGlobalId(key);
4977
callback(value, nft);
5078
});
5179
}
5280

53-
// Converts the map back into an array of [NFT, V] pairs
81+
/**
82+
* Converts the map into an array of [NFT, V] pairs.
83+
* @returns {[NFT, V][]} - An array of [NFT, V] pairs.
84+
*/
5485
toArray(): [NFT, V][] {
5586
return Array.from(this._map).map(([key, value]) => [
5687
NFT.fromGlobalId(key),
5788
value,
5889
]);
5990
}
6091

61-
// Returns a string representation of the map (optional)
92+
/**
93+
* Returns a string representation of the map.
94+
* @returns {string} - A string representation of the map's key-value pairs.
95+
*/
6296
toString(): string {
6397
return `{${Array.from(this._map)
6498
.map(([key, value]) => `${key}: ${value}`)

src/Types/NFTSet.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,79 @@ export class NFTSet {
77
this._set = new Set();
88
}
99

10-
// Helper function to convert an NFT to its string representation
10+
/**
11+
* Converts an NFT object into a string representation for use as an item in the set.
12+
* @param nft - The NFT to convert to a string.
13+
* @returns {string} - The string representation of the NFT (globalId).
14+
*/
1115
private toSetItem(nft: NFT): string {
1216
return nft.globalId();
1317
}
1418

15-
// Adds an NFT to the set
19+
/**
20+
* Adds an NFT to the set.
21+
* @param nft - The NFT to add.
22+
*/
1623
add(nft: NFT): void {
1724
this._set.add(this.toSetItem(nft));
1825
}
1926

20-
// Removes an NFT from the set
27+
/**
28+
* Removes an NFT from the set.
29+
* @param nft - The NFT to remove.
30+
* @returns - True if the NFT was successfully deleted, otherwise false.
31+
*/
2132
delete(nft: NFT): boolean {
2233
return this._set.delete(this.toSetItem(nft));
2334
}
2435

25-
// Checks if an NFT is in the set
36+
/**
37+
* Checks if an NFT is in the set.
38+
* @param nft - The NFT to check.
39+
* @returns - True if the set contains the NFT, otherwise false.
40+
*/
2641
has(nft: NFT): boolean {
2742
return this._set.has(this.toSetItem(nft));
2843
}
2944

30-
// Clears the entire set
45+
/**
46+
* Clears the entire set, removing all elements.
47+
*/
3148
clear(): void {
3249
this._set.clear();
3350
}
3451

35-
// Returns the size of the set
52+
/**
53+
* Returns the number of NFTs in the set.
54+
* @returns {number} - The size of the set.
55+
*/
3656
size(): number {
3757
return this._set.size;
3858
}
3959

40-
// Iterates through the NFTs in the set
60+
/**
61+
* Iterates through the NFTs in the set and applies the provided callback function to each one.
62+
* @param callback - A function that takes an NFT as its argument.
63+
*/
4164
forEach(callback: (nft: NFT) => void): void {
4265
this._set.forEach((item) => {
4366
const nft = NFT.fromGlobalId(item);
4467
callback(nft);
4568
});
4669
}
4770

48-
// Converts the set back into an array of NFTs
71+
/**
72+
* Converts the set into an array of NFT objects.
73+
* @returns - An array of NFT objects.
74+
*/
4975
toArray(): NFT[] {
5076
return Array.from(this._set).map((item) => NFT.fromGlobalId(item));
5177
}
5278

53-
// Returns a string representation of the set
79+
/**
80+
* Returns a string representation of the set.
81+
* @returns {string} - A string representing the NFTs in the set.
82+
*/
5483
toString(): string {
5584
return `[${Array.from(this._set).join(", ")}]`;
5685
}

0 commit comments

Comments
 (0)