Skip to content

Type Editor


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

ts
new OrderedMap<T>(content): OrderedMap<T>;

Defined in: OrderedMap.ts:19

Create a new OrderedMap with the given content array.

Parameters

ParameterTypeDescription
content(string | T)[]Array of alternating keys and values [key1, value1, key2, value2, ...]

Returns

OrderedMap<T>

Accessors

size

Get Signature

ts
get size(): number;

Defined in: OrderedMap.ts:30

The amount of keys in this map.

Returns

number


type

Get Signature

ts
get type(): string;

Defined in: OrderedMap.ts:23

Returns

string

Methods

addBefore()

ts
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

ParameterTypeDescription
placestringThe key to add before
keystringThe key to add
valueTThe value to add

Returns

OrderedMap<T>

A new OrderedMap with the key added before the place key


addToEnd()

ts
addToEnd(key, value): OrderedMap<T>;

Defined in: OrderedMap.ts:158

Add a new key to the end of the map.

Parameters

ParameterTypeDescription
keystringThe key to add
valueTThe value to add

Returns

OrderedMap<T>

A new OrderedMap with the key added at the end


addToStart()

ts
addToStart(key, value): OrderedMap<T>;

Defined in: OrderedMap.ts:148

Add a new key to the start of the map.

Parameters

ParameterTypeDescription
keystringThe key to add
valueTThe value to add

Returns

OrderedMap<T>

A new OrderedMap with the key added at the start


append()

ts
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

ParameterTypeDescription
mapOrderedMap<T> | Record<string, T>The map to append, or an object

Returns

OrderedMap<T>

A new OrderedMap with the appended keys


find()

ts
find(key): number;

Defined in: OrderedMap.ts:82

Internal

Find the index of a key in the content array.

Parameters

ParameterTypeDescription
keystringThe key to find

Returns

number

The index of the key, or -1 if not found


forEach()

ts
forEach(f): void;

Defined in: OrderedMap.ts:185

Call the given function for each key/value pair in the map, in order.

Parameters

ParameterTypeDescription
f(key, value) => voidFunction to call for each key/value pair

Returns

void


get()

ts
get(key): T;

Defined in: OrderedMap.ts:97

Retrieve the value stored under key, or return undefined when no such key exists.

Parameters

ParameterTypeDescription
keystringThe key to retrieve

Returns

T

The value associated with the key, or undefined


prepend()

ts
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

ParameterTypeDescription
mapOrderedMap<T> | Record<string, T>The map to prepend, or an object

Returns

OrderedMap<T>

A new OrderedMap with the prepended keys


remove()

ts
remove(key): OrderedMap<T>;

Defined in: OrderedMap.ts:131

Return a map with the given key removed, if it existed.

Parameters

ParameterTypeDescription
keystringThe key to remove

Returns

OrderedMap<T>

A new OrderedMap with the key removed


subtract()

ts
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

ParameterTypeDescription
mapOrderedMap<T> | Record<string, T>The map to subtract, or an object

Returns

OrderedMap<T>

A new OrderedMap with the subtracted keys


toObject()

ts
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()

ts
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

ParameterTypeDescription
keystringThe key to update
valueTThe new value
newKey?stringOptional new key name

Returns

OrderedMap<T>

A new OrderedMap with the update applied


from()

ts
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

ParameterTypeDescription
valueOrderedMap<T> | Record<string, T>The value to create a map from

Returns

OrderedMap<T>

An OrderedMap