New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@pyyupsk/fd

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@pyyupsk/fd

Lightweight, zero-dependency, ultra-fast JavaScript date-time formatting library

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

fd

Lightweight, ultra-fast, zero-dependency JavaScript date-time library

Bundle Size Test Coverage TypeScript License: MIT

fd is a blazing-fast alternative to Day.js and date-fns, built from scratch with zero runtime dependencies. At around 2KB gzipped (2.09 KB with English locale included), it delivers 2x faster performance while providing an intuitive, chainable API for all your date manipulation needs.

✨ Features

  • 🚀 Ultra-fast: 2x faster than Day.js, <10μs per operation
  • 📦 Tiny bundle: ~2KB gzipped, tree-shakable
  • 🔒 Zero dependencies: No external packages, no supply-chain risks
  • 🌳 Tree-shakable: Import only what you need
  • 🔗 Chainable API: Fluent, immutable operations
  • 💪 TypeScript-first: Strict types, excellent IntelliSense
  • 🌍 Locale support: Built-in i18n for formatting
  • Well-tested: 95%+ test coverage, 330+ passing tests
  • 📚 Day.js compatible: Easy migration path

📦 Installation

npm install @pyyupsk/fd
# or
yarn add @pyyupsk/fd
# or
pnpm add @pyyupsk/fd
# or
bun add @pyyupsk/fd

🚀 Quick Start

import fd from "@pyyupsk/fd";

// Current date/time
const now = fd();

// From various inputs
const date1 = fd("2025-09-30");
const date2 = fd(new Date(2025, 8, 30));
const date3 = fd(1727693745123);

// Format dates
now.format("YYYY-MM-DD"); // '2025-09-30'
now.format("MMMM DD, YYYY"); // 'September 30, 2025'
now.format("dddd [at] HH:mm"); // 'Monday at 14:30'

// Add/subtract (immutable)
const tomorrow = now.add(1, "day");
const nextMonth = now.add(1, "month");
const lastYear = now.subtract(1, "year");

// Compare dates
tomorrow.isAfter(now); // true
now.isBefore(tomorrow); // true
now.isSame(now, "day"); // true

// Calculate differences
tomorrow.diff(now, "day"); // 1
nextMonth.diff(now, "month"); // 1

// Chainable operations
fd("2025-01-01").add(1, "month").subtract(2, "day").format("YYYY-MM-DD"); // '2025-01-30'

📖 API Reference

Creation

fd(); // Current date/time
fd("2025-09-30"); // From ISO string
fd(new Date()); // From Date object
fd(1727693745123); // From Unix timestamp (ms)

Formatting

Supports Day.js-compatible format tokens:

TokenOutputDescription
YYYY20254-digit year
YY252-digit year
MMMMSeptemberFull month name
MMMSepShort month name
MM092-digit month (01-12)
M91-digit month (1-12)
DD302-digit day (01-31)
D301-digit day (1-31)
ddddMondayFull weekday name
dddMonShort weekday name
HH142-digit hour 24h (00-23)
H141-digit hour 24h (0-23)
hh022-digit hour 12h (01-12)
h21-digit hour 12h (1-12)
mm302-digit minute (00-59)
m301-digit minute (0-59)
ss452-digit second (00-59)
s451-digit second (0-59)
SSS1233-digit millisecond (000-999)
APMUppercase AM/PM
apmLowercase am/pm

Escaped literals: Use square brackets [...] for literal text

fd().format("[Today is] dddd, MMMM DD"); // 'Today is Monday, September 30'

Manipulation

All manipulation methods are immutable and return a new instance:

const date = fd("2025-09-30");

// Add time
date.add(1, "year"); // Add 1 year
date.add(3, "month"); // Add 3 months
date.add(7, "day"); // Add 7 days
date.add(2, "hour"); // Add 2 hours
date.add(30, "minute"); // Add 30 minutes
date.add(15, "second"); // Add 15 seconds

// Subtract time
date.subtract(1, "day"); // Subtract 1 day

// Chainable
date.add(1, "month").subtract(2, "day").add(3, "hour");

Supported units: year, month, week, day, hour, minute, second, millisecond

Comparison

const date1 = fd("2025-09-30");
const date2 = fd("2025-10-01");

// Boolean comparisons
date1.isBefore(date2); // true
date2.isAfter(date1); // true
date1.isSame(date1); // true
date1.isSame(date2, "month"); // true (same month)
date1.isSame(date2, "day"); // false (different day)

// Calculate difference
date2.diff(date1, "day"); // 1
date2.diff(date1, "hour"); // 24
date1.diff(date2, "day"); // -1 (negative)

Query

const date = fd("2025-09-30T14:30:45.123");

date.year(); // 2025
date.month(); // 8 (0-indexed, September)
date.date(); // 30
date.day(); // 1 (Monday, 0=Sunday)
date.hour(); // 14
date.minute(); // 30
date.second(); // 45
date.millisecond(); // 123

Conversion

const date = fd("2025-09-30");

date.toDate(); // Native Date object
date.toISOString(); // '2025-09-30T00:00:00.000Z'
date.valueOf(); // 1727654400000 (Unix timestamp)
date.isValid(); // true

Locale

import { fd, registerLocale } from "@pyyupsk/fd";

// Default locale (English)
fd().format("MMMM"); // 'September'

// Thai locale
import { th } from "@pyyupsk/fd/locale";
registerLocale("th", th);

fd().locale("th").format("MMMM"); // 'กันยายน'

🌳 Tree-Shaking

Import only what you need for optimal bundle size:

// Full import (includes everything)
import fd from "@pyyupsk/fd";

// Granular imports (recommended)
import { format } from "@pyyupsk/fd/format";
import { parse } from "@pyyupsk/fd/parse";
import { add, subtract } from "@pyyupsk/fd/manipulate";
import { diff, isBefore, isAfter } from "@pyyupsk/fd/compare";

📊 Performance

Benchmarks comparing fd vs Day.js:

OperationfdDay.jsSpeedup
Create from string~8μs~15μs1.9x faster
Format YYYY-MM-DD~6μs~12μs2.0x faster
Add 3 days~4μs~9μs2.3x faster
Diff in days~3μs~7μs2.3x faster
Complex workflow~25μs~55μs2.2x faster

Bundle size comparison:

LibraryMinifiedGzipped
fd8.22 KB2.09 KB
Day.js7.2 KB2.9 KB
date-fns78 KB13 KB

Note: fd includes English locale by default. Like Day.js, this keeps the library ready-to-use while staying under 2.1KB gzipped.

Run benchmarks yourself: npm run bench

🔄 Migrating from Day.js

fd is designed to be a drop-in replacement for Day.js with minimal changes:

// Day.js
import dayjs from "dayjs";
const date = dayjs("2025-09-30");
date.format("YYYY-MM-DD");
date.add(1, "day");
date.isBefore(other);

// @pyyupsk/fd (nearly identical)
import fd from "@pyyupsk/fd";
const date = fd("2025-09-30");
date.format("YYYY-MM-DD");
date.add(1, "day");
date.isBefore(other);

Key differences:

  • fd() returns null for invalid dates (Day.js returns an invalid date object)
  • Locale must be explicitly registered (Day.js auto-loads)
  • Some advanced plugins not yet supported (timezone conversion, calendar, etc.)

🛠️ Development

# Install dependencies
bun install

# Run tests
bun run test

# Run tests with coverage
bun run test:coverage

# Run benchmarks
bun run bench

# Build distribution
bun run build

# Lint code
bun run lint

# Type check
bun run typecheck

📜 License

MIT © Pongsakorn Thipayanate

🤝 Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

Made with ❤️ by Pongsakorn Thipayanate

Keywords

date

FAQs

Package last updated on 30 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts