Type Editor / @type-editor/commons / OrderedMap / OrderedMap
Class: OrderedMap<T>
Defined in: OrderedMap.ts:7
Persistent data structure representing an ordered mapping from strings to values, with some convenient update methods.
Type Parameters
| Type Parameter |
|---|
T |
Constructors
Constructor
new OrderedMap<T>(content): OrderedMap<T>;Defined in: OrderedMap.ts:19
Create a new OrderedMap with the given content array.
Parameters
| Parameter | Type | Description |
|---|---|---|
content | (string | T)[] | Array of alternating keys and values [key1, value1, key2, value2, ...] |
Returns
OrderedMap<T>
Accessors
size
Get Signature
get size(): number;Defined in: OrderedMap.ts:30
The amount of keys in this map.
Returns
number
type
Get Signature
get type(): string;Defined in: OrderedMap.ts:23
Returns
string
Methods
addBefore()
addBefore(
place,
key,
value): OrderedMap<T>;Defined in: OrderedMap.ts:172
Add the given key/value before place. If place is not found, the new key is added to the end.
Parameters
| Parameter | Type | Description |
|---|---|---|
place | string | The key to add before |
key | string | The key to add |
value | T | The value to add |
Returns
OrderedMap<T>
A new OrderedMap with the key added before the place key
addToEnd()
addToEnd(key, value): OrderedMap<T>;Defined in: OrderedMap.ts:158
Add a new key to the end of the map.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to add |
value | T | The value to add |
Returns
OrderedMap<T>
A new OrderedMap with the key added at the end
addToStart()
addToStart(key, value): OrderedMap<T>;Defined in: OrderedMap.ts:148
Add a new key to the start of the map.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to add |
value | T | The value to add |
Returns
OrderedMap<T>
A new OrderedMap with the key added at the start
append()
append(map): OrderedMap<T>;Defined in: OrderedMap.ts:211
Create a new map by appending the keys in this map that don't appear in map after the keys in map.
Parameters
| Parameter | Type | Description |
|---|---|---|
map | OrderedMap<T> | Record<string, T> | The map to append, or an object |
Returns
OrderedMap<T>
A new OrderedMap with the appended keys
find()
find(key): number;Defined in: OrderedMap.ts:82
Internal
Find the index of a key in the content array.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to find |
Returns
number
The index of the key, or -1 if not found
forEach()
forEach(f): void;Defined in: OrderedMap.ts:185
Call the given function for each key/value pair in the map, in order.
Parameters
| Parameter | Type | Description |
|---|---|---|
f | (key, value) => void | Function to call for each key/value pair |
Returns
void
get()
get(key): T;Defined in: OrderedMap.ts:97
Retrieve the value stored under key, or return undefined when no such key exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to retrieve |
Returns
T
The value associated with the key, or undefined
prepend()
prepend(map): OrderedMap<T>;Defined in: OrderedMap.ts:197
Create a new map by prepending the keys in this map that don't appear in map before the keys in map.
Parameters
| Parameter | Type | Description |
|---|---|---|
map | OrderedMap<T> | Record<string, T> | The map to prepend, or an object |
Returns
OrderedMap<T>
A new OrderedMap with the prepended keys
remove()
remove(key): OrderedMap<T>;Defined in: OrderedMap.ts:131
Return a map with the given key removed, if it existed.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to remove |
Returns
OrderedMap<T>
A new OrderedMap with the key removed
subtract()
subtract(map): OrderedMap<T>;Defined in: OrderedMap.ts:225
Create a map containing all the keys in this map that don't appear in map.
Parameters
| Parameter | Type | Description |
|---|---|---|
map | OrderedMap<T> | Record<string, T> | The map to subtract, or an object |
Returns
OrderedMap<T>
A new OrderedMap with the subtracted keys
toObject()
toObject(): Record<string, T>;Defined in: OrderedMap.ts:245
Turn ordered map into a plain object.
Returns
Record<string, T>
A plain object representation of the map
update()
update(
key,
value,
newKey?): OrderedMap<T>;Defined in: OrderedMap.ts:111
Create a new map by replacing the value of key with a new value, or adding a binding to the end of the map. If newKey is given, the key of the binding will be replaced with that key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to update |
value | T | The new value |
newKey? | string | Optional new key name |
Returns
OrderedMap<T>
A new OrderedMap with the update applied
from()
static from<T>(value): OrderedMap<T>;Defined in: OrderedMap.ts:41
Return a map with the given content. If null, create an empty map. If given an ordered map, return that map itself. If given an object, create a map from the object's properties.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | OrderedMap<T> | Record<string, T> | The value to create a map from |
Returns
OrderedMap<T>
An OrderedMap