The type of the keys. Has to be an array type
The type of the values.
Creates a new ArrayStringMap.
const map = new ArrayStringMap<string[], number>();
The seperator that is being used to seperate list items. By default, this is the zero-width space character, which is unlikely to be used in most trusted strings. However, if the data used can be arbritary strings that are provided as user input, it is recommended to validate given strings to remove the zero-width space character or set the seperator to another string that cannot be in the input due to validation checks.
Private Readonly _converterA map storing the string versions and the original array versions.
Private Readonly _mapThe map that stores the string and values.
Private Readonly _sepThe seperator that is being used to seperate list items.
The name of the class.
The seperator that is being used to seperate list items.
const map = new ArrayStringMap<string[], number>();
map.sep; // '\u200b'
The number of items in the map.
Deletes an entry from the map.
Whether the entry was deleted (true) or never existed (false)
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
map.delete(['a', 'b', 'c']); // true
map.delete(['a', 'b', 'c']); // false
The key to delete
Private encodeAn iterator over the entries in the map.
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
map.set(['a', 'b', 'd'], 456);
for (const [key, value] of map.entries()) {
console.log(key, value);
}
// ['a', 'b', 'c'] 123
// ['a', 'b', 'd'] 456
Executes a function for each entry in the map.
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
map.set(['a', 'b', 'd'], 456);
map.forEach((value, key) => {
console.log(key, value);
});
// ['a', 'b', 'c'] 123
// ['a', 'b', 'd'] 456
The function to execute for each entry.
Optional thisArg: anyThe value to use as this when executing the function.
Gets the value for a given key.
The value for the given key, or undefined if the key does not exist.
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
map.get(['a', 'b', 'c']); // 123
map.get(['a', 'b']); // undefined
The key to get the value for
Checks whether the map has a given key.
Whether the map has the given key.
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
map.has(['a', 'b', 'c']); // true
map.has(['a', 'b']); // false
The key to check for.
Get the keys in the map in array form.
An iterator over the keys in the map.
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
map.set(['a', 'b', 'd'], 456);
for (const key of map.keys()) {
console.log(key);
}
// ['a', 'b', 'c']
// ['a', 'b', 'd']
Sets a value for a given key.
The map itself.
const map = new ArrayStringMap<string[], number>();
map.set(['a', 'b', 'c'], 123);
The key to set the value for.
The value to set.
Generated using TypeDoc
A Map that uses arrays as keys by encoding them as strings.
This class implements the Map interface. All methods that can be used on a normal Map are available on the ArrayStringMap.
Example