Constructor
new LightMap(nopt, optsopt)
constructor
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n |
Array.<array> |
<optional> |
constructed map |
||||||||||
opts |
object |
<optional> |
construction options Properties
|
Extends
- Map
Methods
(static) version() → {string}
return LightMap module version
Returns:
- returns LightMap module version
- Type
- string
Example
LightMap.version();
// -> v0.0.0
filter(fn) → {LightMap}
Filter LightMap based on keys and values based in. Comparisons can be made on the key and/or value.
Parameters:
Name | Type | Description |
---|---|---|
fn |
FilterCallback | comparison method |
Returns:
- returns new LightMap with filtered results
- Type
- LightMap
Example
const _ = new LightMap();
_.set( 'key', 'value' );
_.set( 'key1', 'value1' );
const result = _.filter(
( v, k ) => k === 'key'
);
// -> LightMap { 'key' => 'value' }
find(fn) → {Array.<(*|*)>|undefined}
The find()
method returns the tuple pair of the first element in the LightMap that satisfies the provided
testing function.
Parameters:
Name | Type | Description |
---|---|---|
fn |
FindCallback | find method |
Returns:
- returns tuple result or undefined if no matches are found
- Type
- Array.<(*|*)> | undefined
Example
const _ = new LightMap();
_.set( 'key', 'value' );
_.set( 'key1', 'value1' );
const result = _.find(
( v, k, arr ) => {
return v === 'value';
}
);
// -> [ 'key', 'value' ]
findAll(fn) → {LightMap}
Alias for filter
Parameters:
Name | Type | Description |
---|---|---|
fn |
FilterCallback | same as filter method |
Returns:
- returns new LightMap with matching results
- Type
- LightMap
Example
const _ = new LightMap();
_.set( 'key', 'value' );
_.set( 'key1', 'value' );
_.set( 'key2', 'value2' );
const result = _.findAll(
( v, k, arr ) => {
return v === 'value';
}
);
// -> LightMap { 'key' => 'value', 'key1' => 'value' }
indexOf(n) → {number}
returns the first index at which a given element can be found in the array, or -1 if it is not present
Parameters:
Name | Type | Description |
---|---|---|
n |
string | key name to search for |
Returns:
- index of the element
- Type
- number
map(fn) → {LightMap}
Map LightMap with new key and/or value.
Return the new item in a "tuple" form matching the Map paradigm ([ x, y ]
).
Parameters:
Name | Type | Description |
---|---|---|
fn |
MapCallback | map method |
Returns:
- returns new LightMap with mapped results
- Type
- LightMap
Example
const _ = new LightMap();
_.set( 'key', 'value' );
const result = _.map(
( v, k ) => [ k + 1, v + 1 ]
);
// -> LightMap { 'key1' => 'value1' }
mapToArray() → {Array}
maps a LightMap object to an array of arrays in the Map Pattern (re-constructable pattern)
Returns:
- returns array of tuple key-value pairs
- Type
- Array
Example
const _ = new LightMap();
_.set( 'key', new LightMap( [ [ 'key1', 'value1' ] ] ) );
const result = _.mapToArray();
// -> [ [ 'key', [ [ 'key1', 'value1' ] ] ] ]
reduce(fn, r) → {*}
Reduce LightMap with new value. Must return the carriage value just like Array.reduce.
Parameters:
Name | Type | Description |
---|---|---|
fn |
ReduceCallback | reducing method |
r |
* | carriage value |
Returns:
- returns reduced result
- Type
- *
Example
const _ = new LightMap();
_.set( 'key', 'value' );
const result = _.reduce(
( r, [ k, v ] ) => {
r += `Key: ${ k }\n`;
r += `Value: ${ v }\n`;
return r;
}, ''
);
// -> 'Key: key\nValue: value\n'
sortKeys(fnopt) → {LightMap}
Map LightMap with sorted key-value pairs.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function |
<optional> |
sorting method |
Returns:
- returns new LightMap with sorted results
- Type
- LightMap
Example
const _ = new LightMap();
_.set( 'key2', 'value2' );
_.set( 'key1', 'value1' );
_.set( 'key', 'value' );
const result = _.sortKeys();
// -> LightMap { 'key' => 'value', 'key1' => 'value1', 'key2' => 'value2' }
sortValues(fnnullable) → {LightMap}
Map LightMap with sorted key-value pairs sorted by value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function |
<nullable> |
sorting method |
Returns:
- returns new LightMap with sorted results
- Type
- LightMap
Example
const _ = new LightMap();
_.set( 'key', 'value2' );
_.set( 'key1', 'value1' );
_.set( 'key2', 'value' );
const result = _.sortValues();
// -> LightMap { 'key2' => 'value', 'key1' => 'value1', 'key' => 'value2' }
toObject() → {Object}
maps a LightMap object's keys and values to an object
Returns:
- returns Object of key-value pairs
- Type
- Object
Example
const _ = new LightMap();
_.set( 'key', new LightMap( [ [ 'key1', 'value1' ] ] ) );
const result = _.toObject();
// -> { key: { key1: 'value1' } }
version() → {string}
return LightMap module version
Returns:
- returns LightMap module version
- Type
- string
Example
this.version();
// -> v0.0.0