Skip to content

Commit

Permalink
Fix Node.js 0.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Dec 21, 2017
1 parent d733a21 commit dca33f7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/parse-font.js
Expand Up @@ -4,7 +4,7 @@
* Font RegExp helpers.
*/

const weights = 'bold|bolder|lighter|[1-9]00'
var weights = 'bold|bolder|lighter|[1-9]00'
, styles = 'italic|oblique'
, variants = 'small-caps'
, stretches = 'ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded'
Expand All @@ -14,21 +14,21 @@ const weights = 'bold|bolder|lighter|[1-9]00'
// [ [ <‘font-style’> || <font-variant-css21> || <‘font-weight’> || <‘font-stretch’> ]?
// <‘font-size’> [ / <‘line-height’> ]? <‘font-family’> ]
// https://drafts.csswg.org/css-fonts-3/#font-prop
const weightRe = new RegExp(`(${weights}) +`, 'i')
const styleRe = new RegExp(`(${styles}) +`, 'i')
const variantRe = new RegExp(`(${variants}) +`, 'i')
const stretchRe = new RegExp(`(${stretches}) +`, 'i')
const sizeFamilyRe = new RegExp(
var weightRe = new RegExp('(' + weights + ') +', 'i')
var styleRe = new RegExp('(' + styles + ') +', 'i')
var variantRe = new RegExp('(' + variants + ') +', 'i')
var stretchRe = new RegExp('(' + stretches + ') +', 'i')
var sizeFamilyRe = new RegExp(
'([\\d\\.]+)(' + units + ') *'
+ '((?:' + string + ')( *, *(?:' + string + '))*)')

/**
* Cache font parsing.
*/

const cache = {}
var cache = {}

const defaultHeight = 16 // pt, common browser default
var defaultHeight = 16 // pt, common browser default

/**
* Parse font `str`.
Expand All @@ -44,11 +44,11 @@ module.exports = function (str) {
if (cache[str]) return cache[str]

// Try for required properties first.
const sizeFamily = sizeFamilyRe.exec(str)
var sizeFamily = sizeFamilyRe.exec(str)
if (!sizeFamily) return // invalid

// Default values and required properties
const font = {
var font = {
weight: 'normal',
style: 'normal',
stretch: 'normal',
Expand All @@ -59,9 +59,9 @@ module.exports = function (str) {
}

// Optional, unordered properties.
let weight, style, variant, stretch
var weight, style, variant, stretch
// Stop search at `sizeFamily.index`
let substr = str.substring(0, sizeFamily.index)
var substr = str.substring(0, sizeFamily.index)
if ((weight = weightRe.exec(substr))) font.weight = weight[1]
if ((style = styleRe.exec(substr))) font.style = style[1]
if ((variant = variantRe.exec(substr))) font.variant = variant[1]
Expand Down

0 comments on commit dca33f7

Please sign in to comment.