fecha

A lightweight, dependency-free JavaScript library for formatting and parsing dates.

Library
npm
v4.2.3
2,068stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity0
Maintenance20
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
61/100Good
Architecture60
Code Quality65
Innovation45
Learning Curve75

fecha is a small JavaScript library for formatting and parsing dates using token-based format strings (YYYY, MM, DD, HH, and so on), similar in spirit to Moment.js’s format tokens but with a much smaller footprint and no runtime dependencies. It exposes fecha.format() and fecha.parse() as the two core functions, plus configurable i18n settings for month/day names and AM/PM strings so formatted output can be localized.

Because it only handles formatting and parsing — not date arithmetic, time zones, or duration math — fecha stays tiny and fast, making it a common choice for projects that need Moment-style format strings without pulling in a full date library.

What You Get

  • fecha.format(date, pattern) to render a Date as a string using token-based format patterns
  • fecha.parse(string, pattern) to parse a formatted string back into a Date object
  • Configurable i18n settings (month names, day names, AM/PM tokens) for localized formatting
  • Named/custom format registration via fecha.masks for reusable format shortcuts
  • Zero runtime dependencies and both UMD and ES module builds

Common Use Cases

  • Formatting timestamps for display in UI components without adding a full date library
  • Parsing user-entered or API-provided date strings against a known format pattern
  • Migrating away from Moment.js format-string usage without rewriting formatting logic
  • Localizing displayed dates via custom day/month name and AM/PM configuration

Under The Hood

Architecture fecha’s implementation lives in a single module, src/fecha.ts, built around a regex-driven token scanner (the token regex) that formatter and parser functions both walk: format() replaces each matched token with a value computed from the Date, while parse() builds an equivalent regex from the same tokens and extracts a DateInfo object (year/month/day/hour/minute/second/millisecond/isPm/timezoneOffset) that is then assembled into a Date.

Tech Stack Written in TypeScript, compiled and bundled with Rollup into UMD (lib/fecha.umd.js) and ES module (lib/fecha.js) outputs plus a separate tsc type-declaration pass; distributed with no runtime dependencies, keeping install and bundle size minimal.

Code Quality The project has a real test suite (test.js) run under the painless test runner with nyc for coverage, checked in CI via GitHub Actions (.github/workflows/test.yml), and enforces prettier formatting and eslint rules as part of its npm test script — solid discipline for a library whose entire value proposition is correctness of string parsing/formatting edge cases.

API Design The two-function surface (format/parse) plus a masks registry for named formats keeps the API small and quick to learn for anyone already familiar with Moment-style tokens, though the token regex-based design means unusual or ambiguous format strings can be harder to debug than a more structured formatter API.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search