Installation
Install via npm, pnpm, yarn, or bun, or drop the browser IIFE into a <script> tag.
A pure input formatter that returns two strings at once — a display-ready formatted value and a backend-ready raw value. No DOM, no I/O, no state. Works in Node, React, Vue, Svelte, Shopify themes, or anywhere JavaScript runs.
import { format } from '@samline/formatter'
format('5512345678', 'phone')// => { formatted: '55 1234 5678', raw: '5512345678', type: 'phone' }formatted for the visible <input>, raw for the hidden field. Never re-parse formatted text on the server.Date.now(). Safe to call on every keystroke.FormatType, FormatOptions, and FormatterResult exported.regex object pairs every common pattern with a ready-to-use error message.cleave-zen and libphonenumber-js. Optional browser IIFE ships with both dependencies bundled.Installation
Install via npm, pnpm, yarn, or bun, or drop the browser IIFE into a <script> tag.
Formatting with frameworks
Recommended wiring for React, Vue, Svelte, vanilla, and server-side pipelines.
Styling and UX
Accessible markup, CSS states, input attributes, and caret behavior for formatted fields.
API reference
Every public function, type, and constant documented with concrete examples.
Configuration
Every option, with defaults and per-formatType behavior.
Recipes
End-to-end recipes for common form scenarios.