Skip to content

Dynamic-Innovative-Studio/friendly-dates

Repository files navigation

πŸ“† Friendly-Dates

Dynamic Innovative Studio Friendly Dates CI Code Quality npm version license bundle size TypeScript

A fast, secure, tiny, fully-typed and i18n-ready date formatting library by Dynamic Innovative Studio.


✨ Features

  • πŸ”₯ 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

πŸ“¦ Installation

npm install @dynamic-innovative-studio/friendly-dates
# or
yarn add @dynamic-innovative-studio/friendly-dates
# or
pnpm add @dynamic-innovative-studio/friendly-dates

πŸ”§ Usage

Basic

import format from '@dynamic-innovative-studio/friendly-dates';

format(new Date()); // "Just now"
format(new Date(Date.now() - 5 * 60 * 1000)); // "5 minutes ago"

Reference Date Support

format(new Date('2023-10-14T15:30:00Z'), new Date('2023-10-15T12:00:00Z'));
// => "Yesterday at 3:30 PM"

With Options

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 });

Custom Locale

import { format, LocaleConfig } from '@dynamic-innovative-studio/friendly-dates';

const esES: LocaleConfig = { ... };

format(new Date(), undefined, { locale: esES });

πŸ“š API Reference

format(date, referenceDate?, options?)

Parameters

  • date: Date | string | number β€” Input date
  • referenceDate?: Date β€” Optional reference to compare from
  • options?: Object

Options

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

🌐 i18n Support

  • βœ… Built-in:
    • brBR,
    • enUS,
    • esES,
    • frFR,
    • ptPT,
  • βœ… Easy to extend with LocaleConfig

🌍 Browser & Runtime Support

  • Modern Browsers: βœ… Chrome, Firefox, Safari, Edge
  • Node.js: βœ… 18+
  • ES2020+ support

πŸ› οΈ Development

git clone https://github.com/Dynamic-Innovative-Studio/friendly-dates.git
cd friendly-dates
npm install
npm run dev

Scripts

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

πŸ” CI/CD Pipeline

Using GitHub Actions:

  • βœ… Node 18, 20, 22 testing
  • βœ… Lint & Type Check
  • βœ… Coverage reports
  • βœ… Bundle size analysis
  • βœ… Automated releases
  • βœ… Dependency scanning

βš–οΈ Comparison

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 βœ… ⚠️ Partial ⚠️ Custom ⚠️ βœ… βœ…
Maintenance Status βœ… ❌ βœ… βœ… βœ… ❌
Performance πŸš€ Ultra Fast 🐒 Slow πŸš€ Fast πŸš€ ⚑ ⚠️ Mediocre

🧾 License

MIT License


Made with πŸ’‘ by Dynamic Innovative Studio

About

A tiny, super fast, secure and stable, zero-dependency library that formats dates into human-friendly.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •