RedMadRobot / figma-export

Command line utility to export colors, typography, icons and images from Figma to Xcode / Android Studio project
MIT License
718 stars 114 forks source link

Fix convert to snake case algorithm #145

Closed subdan closed 2 years ago

subdan commented 2 years ago

Figma's icon name icons / 24 / arrow back

nameValidateRegexp: '^icons _ (\d\d) _ ([A-Za-z0-9 /_-]+)$'
nameReplaceRegexp: 'n2_icon_$2_$1'

Expected result n2_icon_arrow_back_24 Actual result n_2_icon_arrow_back_24

When RegExp replace operation finishes, icon name becomes "n2_icon_arrow back_24". Next step is converting the string to snake case. This operation doesn't execute if name already in snake case. Because icon name contains space « » symbol, converting to snake case operation initiated. How converting to snake case works:

  1. split string to substring. Every number becomes substring. ["n", "2", "icon", "arrow", "back", "24"]
  2. lowercase each substring
  3. Join using "_" separator

The result is n_2_icon_arrow_back_24

Need to update convert to snake case algorithm to not to split n2 to two substrings.