Skip to content

Commit

Permalink
Modify number variables (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
aparlato authored May 18, 2022
1 parent 38b360d commit b082724
Show file tree
Hide file tree
Showing 9 changed files with 779 additions and 10 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,53 @@ The parameters are as follows:
* `--out-dir`: the directory built styles will be placed within
* `-v`: include for verbose output

### Helper functions

As a module, this library also exports two helper functions:

**`mergeVariables`:**
Merges a variables object with an extender object to override variable values.

_Example:_
```
// style-template.js
const { mergeVariables, modifyNumberVariables } = require('mapbox-gl-style-build');
const textSizes = require('../variables/textSizes');
module.exports.context = {
textSizes: mergeVariables(textSizes, { countryLabelSize: 16 }),
...
};
```

**`modifyNumberVariables`:**
Takes a variable or object specifying variables and applies a math function to the values. Expression values have the math function applied to all outputs within the expression.

Supports the following operations:
- `*`: multiplication
- `/`: division
- `+`: addition
- `-`: subtraction

Also added support for passing optional options object to round the modified value in different ways:
- `floor`: boolean
- `ceil`: boolean
- `round`: boolean
- `toFixed`: number

_Example:_
```
// style-template.js
const { mergeVariables, modifyNumberVariables } = require('mapbox-gl-style-build');
const textSizes = require('../variables/textSizes');
module.exports.context = {
textSizes: modifyNumberVariables(textSizes, '*', 2, { round: true }),
...
};
```

## Development

Expand Down
142 changes: 142 additions & 0 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b082724

Please sign in to comment.