Registry / communication / phone-id

phone-id

JSON →
library1.0.1jsnpmunverified

Phone number parser, validator, formatter, and generator for Indonesia (Indonesian phone numbers). Version 1.0.1, zero dependencies, TypeScript-first with 100% test coverage, dual ESM+CJS, tree-shakeable. Unlike other libraries, it includes a built-in operator database (42 prefixes from 3 MNOs + 1 satellite operator) and uses Indonesian error messages. Supports E.164, international, domestic, and compact formats, and can generate valid phone numbers for testing.

npm install phone-id
INSTALL
IMPORT
SIG · PHONE-ID
P
phone-id
communicationjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validatePhone
import { validatePhone } from 'phone-id'
import validatePhone from 'phone-id'
Default export does not exist; must use named import
parsePhone
import { parsePhone } from 'phone-id'
const parsePhone = require('phone-id').parsePhone
Named import works with both ESM and CJS, but require() is fine. However, tree-shaking prefers ESM import
formatPhone
import { formatPhone } from 'phone-id'
const { formatPhone } = require('phone-id')
No wrong pattern; require destructuring is acceptable
generatePhone
import { generatePhone } from 'phone-id'
No common mistake

Demonstrates validation, parsing, formatting, and generation of Indonesian phone numbers using all main API functions.

import { validatePhone, parsePhone, formatPhone, generatePhone } from 'phone-id'; // Validate a phone number const valid = validatePhone("081234567890"); console.log(valid); // { valid: true } // Parse components const parsed = parsePhone("081234567890"); if (parsed.valid) { console.log(parsed.operator); // "Telkomsel" console.log(parsed.e164); // "+6281234567890" } // Format to E.164 const e164 = formatPhone("0812-3456-7890", "e164"); console.log(e164); // "+6281234567890" // Generate a test number const phone = generatePhone({ operator: "Telkomsel" }); console.log(phone); // "0812xxxxxxxx"
Debug
Known issues
gotchaThe 'generatePhone' function generates random numbers; it does not guarantee the number is real. Use only for testing.
fix
Do not use generated numbers in production without validation.
affects: >=1.0.0
breakingNode.js version must be >=20. Older versions will not work.
fix
Upgrade Node.js to version 20 or higher.
affects: >=1.0.0
gotchaError messages are in Indonesian language only. No English translations provided.
fix
Expect error strings in Bahasa Indonesia; handle them accordingly in your application.
affects: >=1.0.0
deprecatedNo deprecated APIs at version 1.0.1.
fix
N/A
affects: 1.0.1
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using CommonJS require() to import an ESM module without proper configuration.
fix
Use import statements or set "type": "module" in package.json. Alternatively, use dynamic import()
TypeError: phone is not a function
Default import used incorrectly (e.g., import phone from 'phone-id').
fix
Use named imports: import { validatePhone } from 'phone-id'
TypeError: Cannot read properties of undefined (reading 'valid')
Calling parsePhone() with an invalid phone number but not checking result.valid first.
fix
Always check result.valid before accessing other properties, or use validation beforehand.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
phone-id — npm install phone-id · libregistry