A TypeScript library for formatting strings during input and presentation, following ISO standards. Tidily provides robust handling for various data types including dates, numbers, phone numbers, credit cards, and more.
- 🎯 Type-safe formatting with TypeScript
- 🔄 Real-time input formatting
- 📅 Date formatting (DMY, MDY, YMD)
- 💳 Credit card number formatting
- 📞 Phone number formatting
- 💰 Price and currency formatting
- 📧 Email validation and formatting
- 🔢 Number formatting (integers, decimals, percentages)
- ⚡️ Zero dependencies (except isoly)
- 📦 Works in both ESM and CommonJS environments
npm install tidily
import { tidily } from "tidily"
// Format a credit card number during input
const formatted = tidily.format("4111111111111111", "card-number")
console.log(formatted) // "4111 1111 1111 1111"
// Format a date
const date = tidily.format("20250528", "date")
console.log(date) // "2025-05-28"
card-csc
- Card security codecard-expires
- Card expiration datecard-number
- Card number with spacesdate
- Date formatting (DMY/MDY/YMD)date-time
- DateTime formattingdivisor
- Number divisor formattingduration
- Time durationemail
- Email addresshex-color
- Hexadecimal color codesidentifier
- Custom identifiersidentity-number
- Identity numbersinteger
- Integer numberspassword
- Password inputpercent
- Percentage valuesphone
- Phone numberspostal-code
- Postal/ZIP codesprice
- Price/currency valuestext
- General text formatting
Formats a string value according to the specified type and optional settings.
Parses a formatted string back into its raw value.
Each formatter type can accept specific settings. For example:
// Format a price with specific currency and locale
const price = tidily.format("1234.56", "price", {
currency: "USD",
locale: "en-US",
})
console.log(price) // "$1,234.56"
- Clone the repository
- Install dependencies:
npm install
- Build:
npm run build
- Test:
npm test
- Lint:
npm run lint
See CONTRIBUTING.md for detailed development guidelines.
MIT © Utily Contributors