code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Ability to transform string values

Open jimmymorris opened this issue 1 year ago • 3 comments

Describe the feature you'd like:

With some of our components the prop's type is number, but there is no option for us to transform the figma.string into a number. I feel like being able to do a callback like figma.string('label', (val:string) => Number(val)) would be sufficient.

jimmymorris avatar Jul 25 '24 00:07 jimmymorris

Hi @jimmymorris! We are looking at how we can make string handling more flexible, thanks for providing another use case for us to look at.

dentrado avatar Jul 25 '24 14:07 dentrado

I have this same question. I opened an issue here because I wasn't sure if it was supported.

In our case, we want to use the textContent from a layer and parse it as a number instead of a string. Something like:

      value: figma.nestedProps("✏️ Value", {
        number: parseInt(figma.textContent("✏️ Text")),
      }),

but then we get the Unknown intrinsic error.

What @jimmymorris mentioned would work too! Provided it also works for figma.textContent()! Something like:

      value: figma.nestedProps("✏️ Value", {
        number: figma.textContent("✏️ Text", (val:string) => Number(val)),
      }),

ericandrewscott avatar Sep 17 '24 20:09 ericandrewscott

Hey @ericandrewscott, unfortunately this is not supported right now. We are working on ways to improve flexibility here.

tomduncalf-figma avatar Sep 18 '24 09:09 tomduncalf-figma