A fast, secure, tiny, fully-typed and i18n-ready date formatting library by Dynamic Innovative Studio.
- π₯ Tiny footprint β Less than 2KB min+gzip
- π Zero dependencies β Lean and efficient
- π‘οΈ Type-safe β Written in strict TypeScript
- π i18n support β 8+ built-in locales + custom locales
- β‘ High performance β Optimized for speed and memory
- π¦ Tree-shakeable β Only import what you need
- π§ͺ Battle-tested β High test coverage
npm install @dynamic-innovative-studio/friendly-dates
# or
yarn add @dynamic-innovative-studio/friendly-dates
# or
pnpm add @dynamic-innovative-studio/friendly-datesimport format from '@dynamic-innovative-studio/friendly-dates';
format(new Date()); // "Just now"
format(new Date(Date.now() - 5 * 60 * 1000)); // "5 minutes ago"format(new Date('2023-10-14T15:30:00Z'), new Date('2023-10-15T12:00:00Z'));
// => "Yesterday at 3:30 PM"import format, { ptPT } from '@dynamic-innovative-studio/friendly-dates';
format(new Date(), undefined, { locale: ptPT });
format(new Date(), undefined, { timeFormat: '24h', includeTime: false });
format(new Date(Date.now() - 20_000), undefined, { justNowThreshold: 10 });import { format, LocaleConfig } from '@dynamic-innovative-studio/friendly-dates';
const esES: LocaleConfig = { ... };
format(new Date(), undefined, { locale: esES });date: Date | string | number β Input datereferenceDate?: Date β Optional reference to compare fromoptions?: Object
| Option | Type | Default | Description | |
|---|---|---|---|---|
locale |
LocaleConfig | enUS |
Internationalization config | |
includeTime |
boolean | true |
Show time component | |
timeFormat |
`'12h' | '24h'` | '12h' |
Time format style |
maxUnit |
string | 'year' |
Max unit: second β year | |
justNowThreshold |
number | 30 |
Seconds to consider "just now" | |
useWords |
boolean | true |
Use words or numbers |
- β
Built-in:
brBR,enUS,esES,frFR,ptPT,
- β
Easy to extend with
LocaleConfig
- Modern Browsers: β Chrome, Firefox, Safari, Edge
- Node.js: β 18+
- ES2020+ support
git clone https://github.com/Dynamic-Innovative-Studio/friendly-dates.git
cd friendly-dates
npm install
npm run dev| Command | Description |
|---|---|
dev |
Watch mode build |
build |
Production bundle |
test |
Run tests |
test:coverage |
Coverage reports |
test:performance |
Perf benchmarks |
lint |
Lint source code |
lint:fix |
Auto-fix issues |
type-check |
Type safety |
format |
Prettier formatting |
Using GitHub Actions:
- β Node 18, 20, 22 testing
- β Lint & Type Check
- β Coverage reports
- β Bundle size analysis
- β Automated releases
- β Dependency scanning
| Feature | Friendly-Dates | moment.js | date-fns | dayjs | luxon | intl-relativeformat |
|---|---|---|---|---|---|---|
| Bundle Size (gzip) | ~2KB | ~69KB | ~16KB | ~2KB | ~24KB | ~7KB |
| Dependencies | β | β | β | β | β | β (polyfill needed) |
| TypeScript Support | β | β | β | β | β | β |
| Tree-shakeable | β | β | β | β | β | β |
| i18n Customization | β | β | β | |||
| Maintenance Status | β | β | β | β | β | β |
| Performance | π Ultra Fast | π’ Slow | π Fast | π | β‘ |
Made with π‘ by Dynamic Innovative Studio