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

datefmt-lite

v2.1.0

Published

Lightweight string‑to‑string date format converter with pluggable tokens

Readme

datefmt-lite

A lightweight, zero‑dependency string‑to‑string date format converter with pluggable tokens and an extensible architecture.

Convert date strings from one format to another using pure token-to-token logic—no internal Date objects and no assumptions. You control everything via inputs.


🚀 Features

  • Fast: Parses and formats via pre‑compiled templates
  • Pluggable Tokens: Add or override tokens without touching core code
  • Flexible Year Handling: Supply a yearConverter to expand two‑digit years or provide defaults
  • Override & Default Tokens: Control individual token output on a per-call basis
  • Error Policies: Choose strict (throw) or silent (best‑effort) behavior
  • Bracketed Literals: Use [text] to preserve literals in format output
  • Zero Dependencies: Core library is pure JS—no external packages

📦 Installation

npm install datefmt-lite
# or
yarn add datefmt-lite

🔰 Quick Usage

import { formatDate } from 'datefmt-lite';

formatDate('20250425', 'yyyyMMdd', 'dd/MM/yyyy');
// → '25/04/2025'

formatDate('250425', 'yyMMdd', 'dd/MM/yyyy', {
  yearConverter: (yy) => 2000 + yy,
});
// → '25/04/2025'

📘 When to Use This Library

  • You control both the input and output formats
  • You want predictable, fast token-to-token formatting
  • You want fallback behavior instead of runtime errors
  • You don’t need built-in date math, timezone offsets, or localization (but you can inject that logic via tokens)

✅ Perfect for:

  • ETL data pipelines
  • Formatted export tools
  • Browser-safe string conversion
  • Small-bundle apps where you want full control

🔠 Supported Tokens

| Token | Meaning | Example | | ----- | ---------------- | ------- | | yyyy | full year | 2025 | | yy | 2-digit year | 25 | | MMMM | full month | April | | MMM | short month | Apr | | MM | 2-digit month | 04 | | M | 1/2-digit month | 4 | | dd | 2-digit day | 09 | | d | 1/2-digit day | 9 | | HH | 2-digit hour | 03 | | H | 1/2-digit hour | 3 | | mm | 2-digit minute | 07 | | m | 1/2-digit minute | 7 | | ss | 2-digit second | 09 | | s | 1/2-digit second | 9 |

➡️ Token definitions follow Unicode Date Field Symbols.

➡️ See docs/tokens.md for the full list and examples.


🔧 Advanced Options

formatDate(inputDate, inputFormat, outputFormat, {
  errorPolicy: 'silent',
  yearConverter: (yy) => 1900 + yy,
  customTokens: {
    Q: (p) => 'Q' + Math.ceil(p.month / 3),
  },
  overrideTokens: {
    dd: '01',
  },
  defaultTokens: {
    MM: '00',
  },
});

errorPolicy: 'throw' | 'silent'

  • 'throw' (default): throws on parse/validation errors
  • 'silent': returns raw input if nothing parsed; otherwise returns best-effort output with literal token fallback

➡️ See docs/formatting-behavior.md

yearConverter

  • Required when using yy (2-digit year)
  • If not provided in silent mode, raw yy is used as-is ('25' → 0025)

customTokens

  • Add your own tokens
customTokens: {
  Q: (p) => 'Q' + Math.ceil(p.month / 3)
}

overrideTokens

  • Override built-in or derived tokens (e.g., force day = '01')

defaultTokens

  • Provide fallback values when parsed data is missing

🧪 Scripts

# Run tests
yarn test

# Build ESM and CJS
yarn build

📚 Full Docs

See /docs for:

  • api.md: Main formatDate function signature, options, and behavior
  • tokens.md: List of supported tokens (e.g., yyyy, dd, MMM, HH) and how they're matched
  • examples.md: Real-world and edge-case formatting examples
  • formatting-behavior.md: How overrideTokens, defaultTokens, and errorPolicy interact
  • internals.md: Behind-the-scenes architecture and function flow for contributors
  • contributing.md: Development setup, code structure, and how to contribute
  • design.md: Core philosophy, extensibility plan, and long-term goals

📓 Changelog

See CHANGELOG.md for release history, breaking changes, and upgrade notes.


📄 License

MIT © 2025