npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@samline/formatter

v2.0.0

Published

Lightweight, framework-agnostic input formatter (phone, numeral, date, time, credit card, general) that returns split formatted/raw outputs.

Readme

Formatter

Lightweight, framework-agnostic input formatter that returns split formatted/raw outputs.

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.


Table of Contents


Installation

npm install @samline/formatter
pnpm add @samline/formatter
bun add @samline/formatter

Requires Node 20+ when bundling. Runtime target is ES2020.


CDN / Browser

Use 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.

<script src="https://unpkg.com/@samline/[email protected]/dist/browser/global.global.js"></script>

Pin the version in production. Replace 2.0.0 with the version you ship.

The browser bundle exposes a single global: window.Formatter.

<script src="https://unpkg.com/@samline/[email protected]/dist/browser/global.global.js"></script>
<script>
  const result = window.Formatter.format('5512345678', 'phone')
  console.log(result.formatted) // '55 1234 5678'
  console.log(result.raw)       // '5512345678'
</script>

See docs/browser.md for the full browser surface.


Entrypoints

| Entrypoint | When to use | | --- | --- | | @samline/formatter | Main API for bundlers, ESM, or CJS consumers. | | @samline/formatter/vanilla | Direct re-export of the base utility for non-framework consumers. | | @samline/formatter/browser | Pre-bundled IIFE that registers window.Formatter for direct <script> usage. |


Quick Start

import { format } from '@samline/formatter'

// Phone (Mexico by default, space-delimited)
format('5512345678', 'phone')
// => { formatted: '55 1234 5678', raw: '5512345678', type: 'phone' }

// Numeral (thousand separators)
format('1234567', 'numeral')
// => { formatted: '1,234,567', raw: '1234567', type: 'numeral' }

// Date (raw Y-m-d -> display d/m/Y)
format('2026-05-12', 'date')
// => { formatted: '12/05/2026', raw: '2026-05-12', type: 'date' }

// Credit card (grouped by brand, digits-only raw)
format('4111111111111111', 'creditCard')
// => { formatted: '4111 1111 1111 1111', raw: '4111111111111111', type: 'creditCard' }

// Card brand detection
format('4111111111111111', 'creditCardType')
// => { formatted: 'visa', raw: '4111111111111111', type: 'creditCardType' }

Supported format types

| formatType | What it does | Default output | | --- | --- | --- | | 'general' | Block-based masking with custom delimiter/delimiters | Digits-only raw | | 'phone' | Country-aware phone formatting via libphonenumber-js | Space-delimited, digits-only raw (preserves leading +) | | 'numeral' | Thousand separators, optional decimals | '1,234.56' style raw | | 'date' | Raw Y-m-d → display pattern | '12/05/2026', raw '2026-05-12' | | 'time' | Raw h:m → display pattern | '14:30:00', raw '14:30' | | 'creditCard' | Brand-aware grouping | '4111 1111 1111 1111', digits-only raw | | 'creditCardType' | Returns the card brand name | Brand string, digits-only raw from input |

Documentation

Full API reference, guides, and examples are available at samline.github.io/formatter.

| Doc | Purpose | | --- | --- | | docs/getting-started.md | Concepts, observable contract, and lifecycle overview. | | docs/options.md | Full FormatOptions reference. | | docs/typescript.md | Every exported TypeScript type, with examples. | | docs/vanilla.md | Vanilla surface for non-framework consumers. | | docs/browser.md | Browser global (window.Formatter) usage. |


License

MIT