Created
September 17, 2015 18:21
-
-
Save jednano/6f3abba202c0db9bd325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkers = { | |
isSize(value) { | |
throw new Error('Not implemented'); | |
}, | |
isStyle(value) { | |
throw new Error('Not implemented'); | |
}, | |
isVariant(value) { | |
throw new Error('Not implemented'); | |
}, | |
isWeight(value) { | |
throw new Error('Not implemented'); | |
}, | |
isStretch(value) { | |
throw new Error('Not implemented'); | |
} | |
} | |
const result = { | |
style: 'normal', | |
variant: 'normal', | |
weight: 'normal', | |
stretch: 'normal', | |
height: 'normal', | |
warnings: [], | |
errors: [] | |
}; | |
const preProps = ['style', 'variant', 'weight', 'stretch']; | |
module.exports = parseFont(value) { | |
const tokens = value.split(/\s+/); | |
for (const token = tokens.shift(); tokens.length; token = tokens.shift()) { | |
if (token === 'normal') { | |
continue; | |
} | |
if (token === 'inherit') { | |
preProps.forEach(prop => { | |
result[prop] = token; | |
}); | |
continue; | |
} | |
if (checkers.isSize(token)) { | |
const [ size, lineHeight ] = token.split('/'); | |
result.size = size; | |
if (typeof lineHeight !== undefined) { | |
result.lineHeight = lineHeight; | |
} | |
result.family = unquote(tokens); | |
break; | |
} | |
preProps.forEach(prop => { | |
if (checkers[`is${prop}`](token)) { | |
result[prop] = token; | |
continue; | |
} | |
}); | |
result.errors.push(new Error(`Unknown value: ${token}`)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment