Methods
(static) mapValuesToFloat(object) → {object}
- Source:
- Since:
- 0.1.0
Return a copy of the object with values converted to float.
Use if absolutely sure all values can be turned into numbers to avoid NaN
s,
otherwise use mapValuesToFloatPossibly
.
Example
> mapValuesToFloat({a: '1.2px', b: '20px'})
{a: 1.2, b: 20}
> mapValuesToFloat({a: '1.2', b: 'h2o'})
{a: 1.2, b: NaN}
Parameters:
Name | Type | Description |
---|---|---|
object |
object |
Returns:
- Type
- object
(static) mapValuesToFloatPossibly(object) → {object}
- Source:
- Since:
- 0.1.0
Return the object with values converted to numbers where possible
Example
> mapValuesToFloatPossibly({a: '1.2', b: '2px', c: 'h2o'})
{a: 1.2, b: 2, c: 'h2o'}
Parameters:
Name | Type | Description |
---|---|---|
object |
object |
Returns:
- Type
- object
(static) mapValuesToNumber(object) → {object}
- Source:
- Since:
- 0.1.0
Return a copy of the object with values converted to numbers.
Use if absolutely sure all values can be turned into numbers to avoid NaN
s,
otherwise use mapValuesToFloatPossibly
.
Example
> mapValuesToNumber({a: '1.2', b: '2'})
{a: 1.2, b: 2}
> mapValuesToNumber({a: '1.2', b: '2s'})
{a: 1.2, b: NaN}
Parameters:
Name | Type | Description |
---|---|---|
object |
object |
Returns:
- Type
- object
(static) mergeWithAppendTo(baseObject, objectToMerge) → {object}
- Source:
- Since:
- 0.1.0
Return the merge of the two provided objects appending values of correspondent keys
Example
> obj1 = {a: [1, 2, 3], b: [4, 5, 6]}
> obj2 = {a: 4, b: [7]}
> mergeWithAppendTo(obj1, obj2)
{a: [1, 2, 3, 4], b: [4, 5, 6, [7]]}
Parameters:
Name | Type | Description |
---|---|---|
baseObject |
object | The base object |
objectToMerge |
object | The object to merge on the base object |
Returns:
- The merged object
- Type
- object
(static) mergeWithConcat(baseObject, objectToMerge) → {object}
- Source:
- Since:
- 0.1.0
Return the merge of the two provided objects concatenating values of correspondent keys
Example
> obj1 = {a: [1, 2, 3], b: [4, 5, 6]}
> obj2 = {a: [1, 2, 3], b: [4, 5, 6]}
> mergeWithConcat(obj1, obj2)
{a: [1, 2, 3, 1, 2, 3], b: [4, 5, 6, 4, 5, 6]}
Parameters:
Name | Type | Description |
---|---|---|
baseObject |
object | The base object |
objectToMerge |
object | The object to merge on the base object |
Returns:
- The merged object
- Type
- object
(static) mergeWithMerge(baseObject, objectToMerge) → {object}
- Source:
- Since:
- 0.1.0
Return the merge of the two provided objects merging values of correspondent keys
Example
> obj1 = {A: {a: 1}, B: {b: 1}}
> obj2 = {A: {b: 10}, B: {a: 10}}
> mergeWithMerge(obj1, obj2)
{A: {a: 1, b: 10}, B: {a: 10, b: 1}}
Parameters:
Name | Type | Description |
---|---|---|
baseObject |
object | The base object |
objectToMerge |
object | The object to merge on the base object |
Returns:
- The merged object
- Type
- object
(static) mergeWithSum(baseObject, objectToMerge) → {object}
- Source:
- Since:
- 0.1.0
Return the merge of the two provided objects adding values of correspondent keys
Example
> mergeWithSum({a: 1, b: 2}, {a: 10, c: 1})
{a: 11, b: 2, c: 1}
Parameters:
Name | Type | Description |
---|---|---|
baseObject |
object | The base object |
objectToMerge |
object | The object to merge on the base object |
Returns:
- The merged object
- Type
- object
(static) pickIfTruthy(object) → {object}
- Source:
- Since:
- 0.2.0
Return a copy of the object without falsy values
Example
> pickIfTruthy({a: true, b: true, c: false})
{a: true, b: true}
> pickIfTruthy({a: 1, b: 0, c: false})
{a: 1}
> pickIfTruthy({a: [1, 2], b: {a: 1}, c: false})
{a: [1, 2], b: {a: 1}}
Parameters:
Name | Type | Description |
---|---|---|
object |
object | The input object |
Returns:
object - The object with truthy values
- Type
- object
(static) sortObjectKeysAsc() → {object}
- Source:
- Since:
- 0.17.0
Return a copy of the input object with enumerable properties sorted in ascending order. Note that this should work from ES6 on.
Example
> sortObjectKeysAsc({c: 1, a: 2, b: 15})
{a: 2, b: 15, c: 1}
Parameters:
Type | Description |
---|---|
object |
Returns:
- Type
- object
(static) sortObjectKeysDesc() → {object}
- Source:
- Since:
- 0.17.0
Return a copy of the input object with enumerable properties sorted in descending order. Note that this should work from ES6 on.
Example
> sortObjectKeysDesc({c: 1, a: 2, b: 15})
{c: 1, b: 15, a: 2}
Parameters:
Type | Description |
---|---|
object |
Returns:
- Type
- object
(static) swapKeyValue() → {object}
- Source:
- Since:
- 0.6.0
- See:
Return an object with swapped keys and values. Note that if there are duplicate values, since the keys of the resulting object have to be unique, the last occurrence of each value would be used but depending on the interpreter implementation the output keys might vary.
Example
// unique values
> swapKeyValue({a: 1, b: 2, c: 'd'})
{1: 'a', 2: 'b', d: 'c'}
// duplicate values
> swapKeyValue({a: 1, b: 2, c: 'd', e: 1})
{2: 'b', d: 'c', 1: 'e'}
Parameters:
Type | Description |
---|---|
object |
Returns:
- Type
- object