Skip to content

Commit 2461074

Browse files
committed
Add line-height as optional 3rd argument
1 parent da619ca commit 2461074

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ The ["Klokantech Noto Sans"](https://github.com/klokantech/klokantech-gl-fonts)
1010

1111
```js
1212
var parseFont = require('mapbox-to-css-font');
13-
parseFont('Open Sans Regular', 16);
14-
// returns 'normal 400 16px "Open Sans"'
13+
parseFont('Open Sans Regular', 16, 1.2);
14+
// returns 'normal 400 16px/1.2 "Open Sans"'
1515
```
1616

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

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

25-
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"'`.
25+
- `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.
26+
27+
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"'`.

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var italicRE = /(italic|oblique)$/i;
2929

3030
var fontCache = {};
3131

32-
module.exports = function(fonts, size) {
32+
module.exports = function(fonts, size, lineHeight) {
3333
var cssData = fontCache[fonts];
3434
if (!cssData) {
3535
if (!Array.isArray(fonts)) {
@@ -68,8 +68,8 @@ module.exports = function(fonts, size) {
6868
}
6969
fontFamilies.push(fontFamily);
7070
}
71-
// CSS font property: font-style font-weight font-size font-family
71+
// CSS font property: font-style font-weight font-size/line-height font-family
7272
cssData = fontCache[fonts] = [style, weight, fontFamilies];
7373
}
74-
return cssData[0] + sp + cssData[1] + sp + size + 'px' + sp + cssData[2];
74+
return cssData[0] + sp + cssData[1] + sp + size + 'px' + (lineHeight ? '/' + lineHeight : '') + sp + cssData[2];
7575
}

0 commit comments

Comments
 (0)