@pyyupsk/fdu

Getting Started

Learn how to get started with @pyyupsk/fdu, a zero-dependency, immutable, and type-safe date manipulation library for TypeScript and JavaScript. Install, configure, and start working with dates in minutes with comprehensive examples for date creation, formatting, manipulation, comparison, and localization.

Beta Version

This library is currently in beta. The API may change in future releases.

Installation

Install @pyyupsk/fdu using your preferred package manager:

npm install @pyyupsk/fdu
pnpm add @pyyupsk/fdu
yarn add @pyyupsk/fdu
bun add @pyyupsk/fdu

Basic Usage

Creating Dates

import { fdu } from "@pyyupsk/fdu";

// Current date and time
const now = fdu();

// From ISO string
const date1 = fdu("2025-09-30");
const date2 = fdu("2025-09-30T14:30:00");

// From Date object
const date3 = fdu(new Date());

// From timestamp
const date4 = fdu(1727704200000);

Formatting

const date = fdu("2025-09-30T14:30:45");

date.format("YYYY-MM-DD"); // '2025-09-30'
date.format("MMMM DD, YYYY"); // 'September 30, 2025'
date.format("dddd [at] HH:mm"); // 'Monday at 14:30'
date.format("hh:mm:ss A"); // '02:30:45 PM'

Manipulation

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

// Add time
date.add(1, "day"); // 2025-10-01
date.add(2, "month"); // 2025-11-30
date.add(1, "year"); // 2026-09-30

// Subtract time
date.subtract(1, "day"); // 2025-09-29
date.subtract(2, "month"); // 2025-07-30

Comparison

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

date1.isBefore(date2); // true
date1.isAfter(date2); // false
date1.isSame(date2); // false

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

Query

const date = fdu("2025-09-30T14:30:45");

date.year(); // 2025
date.month(); // 8 (0-indexed, September)
date.date(); // 30
date.day(); // Day of week (0-6)
date.hour(); // 14
date.minute(); // 30
date.second(); // 45
date.millisecond(); // 0

Conversion

const date = fdu("2025-09-30T14:30:45");

// Check validity
date.isValid(); // true

// Convert to Date object
date.toDate(); // Date object

// Convert to ISO string
date.toISOString(); // '2025-09-30T14:30:45.000Z'

// Get timestamp
date.valueOf(); // 1727704245000

Localization

import { fdu, registerLocale, locale } from "@pyyupsk/fdu";
import { es } from "@pyyupsk/fdu/locale/es";

// Register locale
registerLocale("es", es);

// Set global locale
locale("es");

// Use locale on instance
const date = fdu("2025-09-30");
date.locale("es").format("dddd, D [de] MMMM [de] YYYY");
// 'martes, 30 de septiembre de 2025'

Key Features

  • Zero dependencies - Lightweight and fast
  • Immutable - All operations return new instances
  • Type-safe - Full TypeScript support
  • Locale support - Multiple built-in locales
  • Chainable API - Fluent method chaining
  • Tree-shakable - Import only what you need

Next Steps