{"id":51496060,"url":"https://github.com/samline/formatter","last_synced_at":"2026-07-07T15:30:49.497Z","repository":{"id":368324499,"uuid":"1284539620","full_name":"samline/formatter","owner":"samline","description":"Lightweight, framework-agnostic input formatter that returns split formatted/raw outputs. ","archived":false,"fork":false,"pushed_at":"2026-06-30T05:08:52.000Z","size":238,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-30T05:10:20.623Z","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/samline.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-30T01:06:02.000Z","updated_at":"2026-06-30T05:08:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/samline/formatter","commit_stats":null,"previous_names":["samline/formatter"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/samline/formatter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samline%2Fformatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samline%2Fformatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samline%2Fformatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samline%2Fformatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samline","download_url":"https://codeload.github.com/samline/formatter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samline%2Fformatter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35234127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-07T02:00:07.222Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-07-07T15:30:38.202Z","updated_at":"2026-07-07T15:30:49.488Z","avatar_url":"https://github.com/samline.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Formatter\n\n\u003e Lightweight, framework-agnostic input formatter that returns split formatted/raw outputs.\n\n\u003e It formats strings for input fields (phones, numerals, dates, times, credit cards,  generic masked inputs) and returns **two strings** in one call: the display-ready `formatted` value and the backend-ready `raw` value. The function is pure (no DOM, no I/O) so it works in Node, in React, in Vue, in Svelte, in Shopify themes, or anywhere JavaScript runs.\n\n---\n\n## Table of Contents\n\n- [Installation](#installation)\n- [CDN / Browser](#cdn--browser)\n- [Entrypoints](#entrypoints)\n- [Quick Start](#quick-start)\n- [Supported format types](#supported-format-types)\n- [Documentation](#documentation)\n- [License](#license)\n\n---\n\n## Installation\n\n```bash\nnpm install @samline/formatter\n```\n\n```bash\npnpm add @samline/formatter\n```\n\n```bash\nbun add @samline/formatter\n```\n\nRequires Node 20+ when bundling. Runtime target is ES2020.\n\n---\n\n## CDN / Browser\n\nUse the browser build when you do not have a bundler and need to run the package directly in HTML, Shopify, WordPress, or any traditional template.\n\n```html\n\u003cscript src=\"https://unpkg.com/@samline/formatter@1.1.0/dist/browser/global.global.js\"\u003e\u003c/script\u003e\n```\n\n\u003e Pin the version in production. Replace `1.1.0` with the version you ship.\n\nThe browser bundle exposes a single global: `window.Formatter`.\n\n```html\n\u003cscript src=\"https://unpkg.com/@samline/formatter@1.1.0/dist/browser/global.global.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const result = window.Formatter.format('5512345678', 'phone')\n  console.log(result.formatted) // '55 1234 5678'\n  console.log(result.raw)       // '5512345678'\n\u003c/script\u003e\n```\n\nSee [docs/browser.md](docs/browser.md) for the full browser surface.\n\n---\n\n## Entrypoints\n\n| Entrypoint | When to use |\n| --- | --- |\n| `@samline/formatter` | Main API for bundlers, ESM, or CJS consumers. |\n| `@samline/formatter/vanilla` | Direct re-export of the base utility for non-framework consumers. |\n| `@samline/formatter/browser` | Pre-bundled IIFE that registers `window.Formatter` for direct `\u003cscript\u003e` usage. |\n\n---\n\n## Quick Start\n\n```ts\nimport { format } from '@samline/formatter'\n\n// Phone (Mexico by default, space-delimited)\nformat('5512345678', 'phone')\n// =\u003e { formatted: '55 1234 5678', raw: '5512345678', type: 'phone' }\n\n// Numeral (thousand separators)\nformat('1234567', 'numeral')\n// =\u003e { formatted: '1,234,567', raw: '1234567', type: 'numeral' }\n\n// Date (raw Y-m-d -\u003e display d/m/Y)\nformat('2026-05-12', 'date')\n// =\u003e { formatted: '12/05/2026', raw: '2026-05-12', type: 'date' }\n\n// Credit card (grouped by brand, digits-only raw)\nformat('4111111111111111', 'creditCard')\n// =\u003e { formatted: '4111 1111 1111 1111', raw: '4111111111111111', type: 'creditCard' }\n\n// Card brand detection\nformat('4111111111111111', 'creditCardType')\n// =\u003e { formatted: 'visa', raw: '4111111111111111', type: 'creditCardType' }\n```\n\n---\n\n## Supported format types\n\n| `formatType` | What it does | Default output |\n| --- | --- | --- |\n| `'general'` | Block-based masking with custom delimiter/delimiters | Digits-only raw |\n| `'phone'` | Country-aware phone formatting via `libphonenumber-js` | Space-delimited, digits-only raw (preserves leading `+`) |\n| `'numeral'` | Thousand separators, optional decimals | `'1,234.56'` style raw |\n| `'date'` | Raw `Y-m-d` → display pattern | `'12/05/2026'`, raw `'2026-05-12'` |\n| `'time'` | Raw `h:m` → display pattern | `'14:30:00'`, raw `'14:30'` |\n| `'creditCard'` | Brand-aware grouping | `'4111 1111 1111 1111'`, digits-only raw |\n| `'creditCardType'` | Returns the card brand name | Brand string, digits-only raw from input |\n\n## Documentation\n\nFull API reference, guides, and examples are available at **[samline.github.io/formatter](https://samline.github.io/formatter)**.\n\n| Doc | Purpose |\n| --- | --- |\n| [docs/getting-started.md](docs/getting-started.md) | Concepts, observable contract, and lifecycle overview. |\n| [docs/options.md](docs/options.md) | Full `FormatOptions` reference. |\n| [docs/typescript.md](docs/typescript.md) | Every exported TypeScript type, with examples. |\n| [docs/vanilla.md](docs/vanilla.md) | Vanilla surface for non-framework consumers. |\n| [docs/browser.md](docs/browser.md) | Browser global (`window.Formatter`) usage. |\n\n---\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamline%2Fformatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamline%2Fformatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamline%2Fformatter/lists"}