sinhala-datetime
v1.0.7
Published
Sinhala date and time formatter with TypeScript support
Maintainers
Readme
Sinhala (සිංහල) DateTime Formatter
sinhala-datetime
A lightweight Sinhala (සිංහල) date and time formatter with full TypeScript support. Format JS Date objects into readable Sinhala strings, including time with AM/PM.
✨ Features
- Converts
Dateto Sinhala (days/months) - Supports AM/PM time formatting
- Returns fallback string for invalid dates
- ESM, CJS, and TypeScript support
📦 Installation
Using npm
npm install sinhala-datetimeUsing pnpm
pnpm add sinhala-datetime🚀 Usage
Import the formatter
import { formatSinhalaDate } from "sinhala-datetime";Format a Date
// Format current date
const now = new Date();
console.log(formatSinhalaDate(now));
// Date without time
const dateOnly = new Date("2025-07-09T00:00:00");
console.log(formatSinhalaDate(dateOnly));
// ➤ බදාදා, 9 ජූලි 2025
// Date with AM time
const dateAM = new Date("2025-07-09T09:15:00");
console.log(formatSinhalaDate(dateAM, { showTime: true }));
// ➤ බදාදා, 9 ජූලි 2025 9:15 පෙ.ව.
// Date with PM time
const datePM = new Date("2025-07-09T15:45:00");
console.log(formatSinhalaDate(datePM, { showTime: true }));
// ➤ බදාදා, 9 ජූලි 2025 3:45 ප.ව.
// Midnight time
const midnight = new Date("2025-07-09T00:00:00");
console.log(formatSinhalaDate(midnight, { showTime: true }));
// ➤ බදාදා, 9 ජූලි 2025 12:00 පෙ.ව.
// Invalid date fallback
const invalid = new Date("not-a-date");
console.log(formatSinhalaDate(invalid));
// ➤ වලංගු නොවන දිනයකි📘 API
formatSinhalaDate(date: Date): stringParameters:
date: JS Date object
Returns:
Sinhala-formatted date string or fallback if invalid.
🧪 Run Tests
# Make sure you have Jest installed
pnpm add -D jest @types/jest ts-jest
pnpm test🛠 Build CJS + ESM
# Make sure you have TypeScript and tsc-alias installed
pnpm add -D typescript ts-jest
pnpm build📁 Structure
sinhala-datetime/
├── dist/ # Compiled output
├── src/ # Main source code
│ ├── libs/ # Formatting logic
│ ├── types/ # TypeScript types
│ ├── utils/ # Helper functions
│ └── index.ts # Library entry
├── tests/ # Unit tests
├── package.json # Project metadata
├── README.md # Documentation
├── tsconfig.*.json # TypeScript configs
└── jest.config.ts # Testing config📄 License
MIT © Lakshan Rukantha
🙌 Contribute
Contributions are welcome! Please open an issue or submit a pull request.
