Skip to content

Browser

@samline/formatter ships a pre-built IIFE bundle that works in plain HTML pages, Shopify themes, WordPress templates, or any project without a bundler.

The browser bundle exposes a global window.Formatter object:

<script src="https://cdn.jsdelivr.net/npm/@samline/formatter@2.0.3/dist/browser/global.global.js"></script>
<script>
const result = window.Formatter.format('5512345678', 'phone')
// => { formatted: '55 1234 5678', raw: '5512345678', type: 'phone' }
</script>
interface FormatterGlobal {
/** Format any value using the core formatter. */
format: (value: unknown, formatType: FormatType, options?: FormatOptions) => FormatterResult
/** Validation regex patterns with paired error messages. */
regex: typeof regex
/** Library version. */
version: string
}
<input type="text" id="phone" placeholder="55 1234 5678" />
<input type="hidden" id="phone-raw" name="phone" />
<script>
const phoneInput = document.getElementById('phone')
const phoneRaw = document.getElementById('phone-raw')
phoneInput.addEventListener('input', (e) => {
const result = window.Formatter.format(e.target.value, 'phone', {
country: 'MX'
})
// Update visible field with formatted value
e.target.value = result.formatted
// Update hidden field with raw value for form submission
phoneRaw.value = result.raw
})
</script>
CDN URL
jsDelivr https://cdn.jsdelivr.net/npm/@samline/formatter@2.0.3/dist/browser/global.global.js
unpkg https://unpkg.com/@samline/formatter@2.0.3/dist/browser/global.global.js

These URLs intentionally pin the current release instead of latest, so you can choose the exact package version to ship. The published browser bundle is the unminified dist/browser/global.global.js; there is no formatter.iife.min.js artifact in the package.