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'); });