データと保存

種別ごとに数える

normalizetype
携帯、固定電話、フリーダイヤル、不正の件数を数えます。
試す
  • fixed_line2
  • invalid1
  • ip_phone1
  • mobile2
  • toll_free2
  • unified_number1

しくみ

type ごとに数えると、連絡先の内訳が分かります。たとえば、SMS を受け取れる顧客の数です。不正な記録は別に数えるので、整える必要のある量も分かります。

各言語で

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

const numbers = [
  "090-1234-5678", "080-1000-0000", "03-5253-8111", "092-513-5612", "050-3818-1250",
  "0120-123-456", "0800-123-4567", "0570-123-456", "03-1234-5678",
];

const counts = {};
for (const input of numbers) {
  const type = normalize(input)?.type ?? "invalid";
  counts[type] = (counts[type] ?? 0) + 1;
}
for (const type of Object.keys(counts).sort()) console.log(type, counts[type]);

出力:

fixed_line 2
invalid 1
ip_phone 1
mobile 2
toll_free 2
unified_number 1