Data and storage

Find duplicates written differently

normalize
Group entries that are the same number in different notations.
Try it
  • 03-5253-81114
  • 090-1234-56782

How it works

03-5253-8111, 03-5253-8111, (03)5253-8111, and +81-3-5253-8111 are one number. Group by the normalized value to find duplicate customers or contacts.

Entries that are not valid keep their original text as the key, so they stay visible for a person to check.

In each language

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

// A customer list where the same numbers were typed in different ways.
const entries = ["03-5253-8111", "03-5253-8111", "(03)5253-8111", "+81-3-5253-8111", "090-1234-5678", "09012345678"];

const counts = new Map();
for (const entry of entries) {
  const key = normalize(entry)?.national ?? entry;
  counts.set(key, (counts.get(key) ?? 0) + 1);
}
for (const [number, count] of counts) console.log(`${number}: ${count}`);

Output:

03-5253-8111: 4
090-1234-5678: 2