Jigsass-tools-maps - 1.0.10
JigSass Tools Maps
Map helper functions
Installation
Using npm:
npm i -S jigsass-tools-maps
Usage
@import 'path/to/jigsass-tools-maps/index.scss';
should give you all you need.
jigsass-tools-maps
provides the following utility functions:
- jigsass-get
- Get a value from nested maps
- jigsass-set
- Set a value in nested maps
- jigsass-deep-has-key
- Check if a map has a nested key
- jigsass-merge-deep
- Recursively assign values from multiple maps into a single map
License: MIT
General
functions
jigsass-get
@function jigsass-get($map, $keys...) { ... }
Description
Get key values from nested maps Nesting can go as deep as needed, where keys are separated by commas.
Parameters
parameterName | parameterDescription | parameterType | parameterDefault value |
---|---|---|---|
$map | Map | Map | —none |
$keys | Key chain | Arglist | —none |
Returns
The value stored in the last key provided.
Throws
jigsass-get:
#{$map}
is a #{type-of($map)}, not a map.
Example
// scss
$typography: (
h1: (
size: 36px;
weight: 700;
);
);
.alpha {
font-size: js-get($typography, h1, size);
font-weight: js-get($typography, h1, weight);
}
// css ouput
.alpha{
font-size: 36px;
font-weight: 700;
}
jigsass-set
@function jigsass-set($map, $keys-value......, $value) { ... }
Description
Set a value of a key in a nested map. Nesting can go as deep as needed.
Parameters
parameterName | parameterDescription | parameterType | parameterDefault value |
---|---|---|---|
$map | The parent map in which keys and values will be set in. | Map | —none |
$keys-value... | A comma-seperated list of keys to denote nesting hierarchy. | Arglist | —none |
$value | The value to assign to the last key in | Any | —none |
Returns
Map
Throws
jigsass-set:
#{$map}
is a #{type-of($map)}, not a map.
Example
// Input:
$map: (
key1: (
key2: (
existing-key: existing-value,
),
),
);
$map: jigsass-set($map, key1, key2, new-key, new-value);
// Outcome:
$map: (
key1: (
key2: (
existing-key: existing-value,
new-key: new-value,
),
),
);
jigsass-deep-has-key
@function jigsass-deep-has-key($map, $key...) { ... }
Description
Checks whether a map has a value associated with a given nested key.
Parameters
parameterName | parameterDescription | parameterType | parameterDefault value |
---|---|---|---|
$map | The map to search in | Map | —none |
$key | the key hierarchy to look for | Arglist | —none |
Returns
Boolean
jigsass-deep-merge
@function jigsass-deep-merge($sources...) { ... }
Description
Recursively assign values from multiple maps into a single map.
Parameters
parameterName | parameterDescription | parameterType | parameterDefault value |
---|---|---|---|
$sources | Sources to be merged into a single | Arglist | —none |
Returns
Map
Throws
jigsass-deep-merge: Only maps can be merged into,
jigsass-deep-merge: Only maps can be merged,