deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

fix(fmt): handle missing group separator for 1000.1 in some locales

Open IgorM867 opened this issue 1 year ago • 2 comments

In some locales there is no group separator in parts which cause error during tests.

const parts = new Intl.NumberFormat().formatToParts(1000.1);
console.log(parts);
const group = parts.find(({ type }) => type === "group")!.value;
[
  { type: "integer", value: "1000" },
  { type: "decimal", value: "," },   
  { type: "fraction", value: "1" }   
]
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'value')
const group = parts.find(({ type }) => type === "group")!.value;

Change to 10000.1 fix this issue.

const parts = new Intl.NumberFormat().formatToParts(10000.1);
console.log(parts);
const group = parts.find(({ type }) => type === "group")!.value;
[
  { type: "integer", value: "10" },
  { type: "group", value: " " },
  { type: "integer", value: "000" },
  { type: "decimal", value: "," },
  { type: "fraction", value: "1" }
]

IgorM867 avatar Oct 14 '24 07:10 IgorM867