Data and storage

Store digits, show hyphens

normalizenational
Format stored digits with the groups from the numbering table.
Try it
Try 0352538111, 0942210000 or 0570123456.

04998-2-3111

How it works

Many systems store numbers as digits only. To show them, call normalize on the digits and use national.

You cannot place the hyphens by counting digits. 0499823111 is 04998-2-3111 and 0942210000 is 0942-21-0000: the length of the area code depends on the number. japan-phone reads it from the MIC tables.

In each language

import { normalize } from "@kurashina-design/japan-phone";

// Store only the digits, and add the hyphens when you show the number.
// The groups come from the numbering table: you cannot place them by counting digits.
for (const digits of ["0352538111", "0499823111", "0942210000", "0570123456", "0120950178"]) {
  console.log(digits, "->", normalize(digits).national);
}

Output:

0352538111 -> 03-5253-8111
0499823111 -> 04998-2-3111
0942210000 -> 0942-21-0000
0570123456 -> 0570-123-456
0120950178 -> 0120-950-178