Skip to content

Commit

Permalink
Add line-height as optional 3rd argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Mar 9, 2019
1 parent da619ca commit 2461074
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The ["Klokantech Noto Sans"](https://github.com/klokantech/klokantech-gl-fonts)

```js
var parseFont = require('mapbox-to-css-font');
parseFont('Open Sans Regular', 16);
// returns 'normal 400 16px "Open Sans"'
parseFont('Open Sans Regular', 16, 1.2);
// returns 'normal 400 16px/1.2 "Open Sans"'
```

## API
Expand All @@ -22,4 +22,6 @@ parseFont('Open Sans Regular', 16);

- `size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Font size in pixels.

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** CSS font definition, e.g. `'normal 400 16px "Open Sans"'`.
- `lineHeight` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Line height as css [line-height](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height). Optional.

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var italicRE = /(italic|oblique)$/i;

var fontCache = {};

module.exports = function(fonts, size) {
module.exports = function(fonts, size, lineHeight) {
var cssData = fontCache[fonts];
if (!cssData) {
if (!Array.isArray(fonts)) {
Expand Down Expand Up @@ -68,8 +68,8 @@ module.exports = function(fonts, size) {
}
fontFamilies.push(fontFamily);
}
// CSS font property: font-style font-weight font-size font-family
// CSS font property: font-style font-weight font-size/line-height font-family
cssData = fontCache[fonts] = [style, weight, fontFamilies];
}
return cssData[0] + sp + cssData[1] + sp + size + 'px' + sp + cssData[2];
return cssData[0] + sp + cssData[1] + sp + size + 'px' + (lineHeight ? '/' + lineHeight : '') + sp + cssData[2];
}

0 comments on commit 2461074

Please sign in to comment.