Skip to content

Commit

Permalink
Throw error if layer names start with a number
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Bok committed Dec 16, 2015
1 parent 864d7d5 commit b4583d4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion framer/Importer.coffee
Expand Up @@ -27,7 +27,8 @@ getScaleFromName = (str) ->


return null return null



startsWithNumber = (str) ->
return (new RegExp("^[0-9]")).test(str)


class exports.Importer class exports.Importer


Expand Down Expand Up @@ -123,6 +124,10 @@ class exports.Importer
else if superLayer else if superLayer
layerInfo.superLayer = superLayer layerInfo.superLayer = superLayer


# Layer names cannot start with a number
if startsWithNumber(layerInfo.name)
throw new Error("(#{layerInfo.name}) Layer or Artboard names can not start with a number")

# Sanitize the layer names so mylayer.jpg gets converted to mylayer # Sanitize the layer names so mylayer.jpg gets converted to mylayer
for suffix in [".jpg", ".pdf"] for suffix in [".jpg", ".pdf"]
layerInfo.name = layerInfo.name.replace(suffix, "") if _.endsWith(layerInfo.name, suffix) layerInfo.name = layerInfo.name.replace(suffix, "") if _.endsWith(layerInfo.name, suffix)
Expand Down

0 comments on commit b4583d4

Please sign in to comment.