tokens-studio / sd-transforms

Custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio
MIT License
175 stars 27 forks source link

[Feature]: Make Decimal Rounding Configurable #289

Closed onurorhon closed 3 weeks ago

onurorhon commented 3 weeks ago

What feature would you like?

Currently, the number of decimal places in checkAndEvaluateMath.ts is fixed to 3. We want to make this number configurable by introducing a platform option called mathRoundDecimals (or a similar name). This will allow users to define the number of decimal places according to their requirements.

Acceptance Criteria:

Here is the relevant code snippet:

// the outer Number() gets rid of insignificant trailing zeros of decimal numbers
const reducedTo3Fixed = Number(Number.parseFloat(`${result}`).toFixed(3));
result = resultUnit ? `${reducedTo3Fixed}${resultUnit}` : reducedTo3Fixed;
return result;

Related TS plugin ticket: https://github.com/tokens-studio/figma-plugin/issues/2874

@jorenbroekema

Would you be available to contribute this feature?

jorenbroekema commented 3 weeks ago

Suggested API seems good to me, goal is to configure like so:

{
  platforms: {
    css: {
      mathRoundDecimals: 4,
      // rest of the options
    }
  }
}

and the check evaluate math transform can pick up on that platform option, I'm also okay additionally to set the default value to 4 instead of 3 because em/rem and the rounding to 4 could be significant for pixels, where 5th usually isn't.