{"id":19257558,"url":"https://github.com/ericvera/e164num","last_synced_at":"2025-04-21T15:31:23.609Z","repository":{"id":237714914,"uuid":"795138856","full_name":"ericvera/e164num","owner":"ericvera","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-21T10:50:28.000Z","size":2026,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T11:42:37.215Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericvera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-02T16:55:44.000Z","updated_at":"2025-04-21T10:50:25.000Z","dependencies_parsed_at":"2024-09-16T10:59:13.077Z","dependency_job_id":"fc393644-dec8-4c6e-8211-828294a48cac","html_url":"https://github.com/ericvera/e164num","commit_stats":null,"previous_names":["ericvera/e164num"],"tags_count":9,"template":false,"template_full_name":"ericvera/ts-lib-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fe164num","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fe164num/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fe164num/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fe164num/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericvera","download_url":"https://codeload.github.com/ericvera/e164num/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250052857,"owners_count":21367033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T19:10:39.362Z","updated_at":"2025-04-21T15:31:23.603Z","avatar_url":"https://github.com/ericvera.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# e164num\n\n**Light validation and manipulation of E.164 phone numbers.**\n\n[![github license](https://img.shields.io/github/license/ericvera/e164num.svg?style=flat-square)](https://github.com/ericvera/e164num/blob/master/LICENSE)\n[![npm version](https://img.shields.io/npm/v/e164num.svg?style=flat-square)](https://npmjs.org/package/e164num)\n\n## Features\n\n- E.164 phone number validation and formatting\n- Real-time input handling\n- US number formatting with proper spacing\n- Secure number masking\n- TypeScript ready, zero dependencies\n\n## Installation\n\n```bash\nnpm install e164num\n# or\nyarn add e164num\n# or\npnpm add e164num\n```\n\n## Usage\n\n```typescript\nimport {\n  isValidE164PhoneNumber,\n  formatPartialUSPhoneNumber,\n  getPartialE164PhoneNumber,\n  maskPhoneNumber,\n} from 'e164num'\n\n// Validate a complete E.164 phone number (e.g., on form submission)\nisValidE164PhoneNumber('+17871234567') // returns true\nisValidE164PhoneNumber('+1') // returns false\n\n// Validate a partial E.164 phone number (e.g., for intermediate validation)\nisValidPartialE164PhoneNumber('+1787') // returns true\nisValidPartialE164PhoneNumber('abc') // returns false\n\n// Format a US phone number for display\nformatPartialUSPhoneNumber('+17871234567') // returns \"(787) 123-4567\"\n\n// Convert partial number to E.164 format (great for input fields)\ngetPartialE164PhoneNumber('7871234567') // returns \"+17871234567\"\ngetPartialE164PhoneNumber('787123', { code: '+34', maxLength: 12 }) // returns \"+34787123\"\n\n// Mask a phone number for display\nmaskPhoneNumber('+17871234567') // returns \"+1*******567\"\n```\n\n## API Reference\n\n### `isValidE164PhoneNumber(e164PhoneNumber: string): boolean`\n\nValidates if a string is a complete, valid E.164 phone number. For US numbers (+1), it checks for the correct length. For international numbers, it validates the basic E.164 format. Use this function for final validation, such as when a form is submitted.\n\n### `isValidPartialE164PhoneNumber(partialE164PhoneNumber: string): boolean`\n\nValidates if a string follows the E.164 format rules but may be incomplete. This is useful for intermediate validation states, such as validating a phone number that's been pasted in or when you need to check if the current input could potentially become a valid E.164 number.\n\n### `getPartialE164PhoneNumber(phoneNumber: string | undefined, defaultCountryInfo?: { code: string, maxLength: number }): string`\n\nConverts a partial phone number to E.164 format. This is the ideal function for processing phone numbers in input fields as the user types, as it handles formatting and country code insertion in real-time.\n\n- `defaultCountryInfo` defaults to `{ code: '+1', maxLength: 12 }` for US numbers\n- Automatically adds the country code if not present\n- Truncates numbers to the specified maximum length\n\n### `formatPartialUSPhoneNumber(e164PhoneNumber: string): string`\n\nFormats a US phone number with proper spacing and punctuation: (XXX) XXX-XXXX. Works with both regular and masked phone numbers - masked digits will be shown as bullet points (•) in the formatted output.\n\nExample with masked number:\n\n```typescript\nformatPartialUSPhoneNumber('+1******1234') // returns \"(•••) •••-1234\"\n```\n\n### `maskPhoneNumber(e164PhoneNumber: string): string`\n\nMasks a phone number for display, showing only the country code and last 3 digits. All other digits are replaced with asterisks.\n\n## E.164 Format\n\nE.164 is the international standard format for phone numbers. An E.164 number can have a maximum of 15 digits and is usually written with a leading + symbol.\n\nFormat: `+[country code][area code][local phone number]`\n\nExamples:\n\n- US: `+17871234567`\n- UK: `+447911123456`\n- Spain: `+34612345678`\n\n## License\n\nMIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericvera%2Fe164num","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericvera%2Fe164num","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericvera%2Fe164num/lists"}