Skip to content

Instantly share code, notes, and snippets.

@lerouxb
Last active December 16, 2015 12:19
Show Gist options
  • Select an option

  • Save lerouxb/5433456 to your computer and use it in GitHub Desktop.

Select an option

Save lerouxb/5433456 to your computer and use it in GitHub Desktop.
# extract the weight and style from a google font variant string
splitVariant = (variant) ->
weight = 'normal'
style = 'normal'
unless variant == 'regular'
if variant == 'italic'
style = 'italic'
else
weight = variant[..2]
italic = variant[3..]
if italic == 'italic'
style = 'italic'
info =
weight: weight
style: style
info
# turn weight and style into a google font compatible variant string
combineVariant = (weight, style) ->
weight ?= 'normal'
style ?= 'normal'
if weight == 'normal' and style == 'normal'
'regular'
else
if weight == 'normal'
# normal + italic becomes 'italic' only
# (normal/normal is already handled as regular above)
weight = ''
else if weight == 'bold'
weight = '700'
unless style == 'italic'
# assume everything else is normal
style = ''
"#{weight}#{style}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment