design-tokens icon indicating copy to clipboard operation
design-tokens copied to clipboard

Doesn't preserve camel casing in export

Open SteveAtKlover opened this issue 2 years ago • 7 comments

I have, for instance, a figma token called brandPrimary, but when it gets exported out to the file, it saves as brandprimary, lowercasing the P. I messed with the casing option and it doesn't do it correctly in any case.

SteveAtKlover avatar Mar 31 '22 23:03 SteveAtKlover

Hey @SteveAtKlover,

can you give me more details?

So you are using the "standard" token format? And you have set the name conversion option to camelCase but still get the converted version, correct?

lukasoppermann avatar Apr 06 '22 19:04 lukasoppermann

@lukasoppermann yeah, i use the standard format, and tried default as well as camel case.

when the file spits out, a figma token that is brandPrimary gets exported as brandprimary.

SteveAtKlover avatar Apr 07 '22 06:04 SteveAtKlover

Hey, you are right and this is a bug.

Currently the code just lowercases everything and merges words where you have spaces and uppercases the first letter. This does remove already existing camelCase names.

Another issue I ran across is that emojis like 😅 produce an error when camelCasing which breaks the plugin.

Would you be able to send a PR to address the issues?

lukasoppermann avatar Apr 07 '22 07:04 lukasoppermann

I can try. What file should I be working in? Thanks.

SteveAtKlover avatar Apr 07 '22 07:04 SteveAtKlover

Awesome, reach out any time if you have questions.

The conversion happens here: https://github.com/lukasoppermann/design-tokens/blob/main/src/utilities/transformName.ts

The module is than used here: https://github.com/lukasoppermann/design-tokens/blob/main/src/utilities/groupByName.ts

I think there are two things:

  1. Fixing the camelCase: https://github.com/lukasoppermann/design-tokens/blob/main/src/utilities/transformName.ts#L10-L20
  2. Changing the guard: https://github.com/lukasoppermann/design-tokens/blob/main/src/utilities/transformName.ts#L1-L8 here it would probably be better to try to convert, if it fails we should try to return the original and only throw if this fails as well, what do you think?

lukasoppermann avatar Apr 07 '22 07:04 lukasoppermann

Any update on this issue? Existing camelCase just needs to be passed through

cailborg avatar Oct 30 '23 23:10 cailborg

https://github.com/lukasoppermann/design-tokens/pull/290

cailborg avatar Oct 30 '23 23:10 cailborg