Guide

@samline/formatter

Input formatting for phones, money, dates, times, card numbers and custom masks, with display and backend-ready values from one call.

Formatter formats input values while people type and returns two strings at once: formatted for the visible field and raw for your backend. It is one pure function with no DOM access, no state and no stylesheet, so it fits browsers, frameworks, CMS templates and server code alike.

import { format } from '@samline/formatter'
import { registerPhone } from '@samline/formatter/phone'

registerPhone()

format('5512345678', 'phone')
// => { formatted: '55 1234 5678', raw: '5512345678', type: 'phone' }

Start building

Choose your integration

Use @samline/formatter for named ESM or CommonJS imports, or @samline/formatter/vanilla for the same API under an explicit subpath. Plain HTML loads the standalone IIFE, which defines window.Formatter with format, intl, regex, checks and version. format() also runs on the server, in workers and in tests.

Read entrypoints and module formats for the loading terminology and framework integrations for controlled inputs in React, Vue and Svelte.

Styling and accessibility

Formatter returns strings and never touches the page. Your application owns the visible and hidden inputs, labels, inputmode and autocomplete, error messages, validation states and caret behavior. See Styling and UX.

Version

This site documents @samline/formatter 3.3.0. Use this version when copying the pinned CDN examples.