From f01aeee4c3892b62bb3a32c5d8f570e21e0b66f8 Mon Sep 17 00:00:00 2001 From: Jonathan Berger Date: Mon, 2 Dec 2024 17:59:10 +0100 Subject: [PATCH] Fix pxToBaseSize method returning a comma instead for decimals on local environment (fr_BE) --- scripts/transform.ts | 4 ++-- tests/transform.spec.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/transform.ts b/scripts/transform.ts index 02de110..547527a 100644 --- a/scripts/transform.ts +++ b/scripts/transform.ts @@ -138,8 +138,8 @@ function addTokenToObject( return obj; } -function pxToBaseSize(value: number, decimals = 3) { - return (value / BASE_FONT_SIZE).toLocaleString(undefined, { +export function pxToBaseSize(value: number, decimals = 3) { + return (value / BASE_FONT_SIZE).toLocaleString('en', { maximumFractionDigits: decimals, }); } diff --git a/tests/transform.spec.ts b/tests/transform.spec.ts index 5632d1b..1826c59 100644 --- a/tests/transform.spec.ts +++ b/tests/transform.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from 'vitest'; -import { flattenDefaultTokens } from '../scripts/transform'; +import { flattenDefaultTokens, pxToBaseSize } from '../scripts/transform'; import { TransformedToken } from 'style-dictionary'; const sampleTokens: TransformedToken[] = [ @@ -63,4 +63,6 @@ test('Flatten default tokens', () => { value: 'number', }, }); + + expect(pxToBaseSize(40)).toEqual('2.857'); });