sinhala-datetime
Version:
Sinhala date and time formatter with TypeScript support
133 lines (96 loc) • 4.23 kB
Markdown
# Sinhala (සිංහල) DateTime Formatter
## sinhala-datetime
[](https://www.npmjs.com/package/sinhala-datetime)
[](https://github.com/LakshanRukantha/sinhala-datetime/releases)
[](https://github.com/LakshanRukantha/sinhala-datetime/actions/workflows/publish.yml)
[](https://github.com/LakshanRukantha/sinhala-datetime/commits/main)
[](https://github.com/LakshanRukantha/sinhala-datetime/stargazers)
[](https://github.com/LakshanRukantha/sinhala-datetime/network/members)
[](https://github.com/LakshanRukantha/sinhala-datetime/graphs/contributors)
[](https://github.com/LakshanRukantha/sinhala-datetime/pulls)
[](https://github.com/LakshanRukantha/sinhala-datetime/issues)
### 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 `Date` to Sinhala (days/months)
- Supports AM/PM time formatting
- Returns fallback string for invalid dates
- ESM, CJS, and TypeScript support
## 📦 Installation
### Using npm
```bash
npm install sinhala-datetime
```
### Using pnpm
```bash
pnpm add sinhala-datetime
```
## 🚀 Usage
### Import the formatter
```typescript
import { formatSinhalaDate } from "sinhala-datetime";
```
### Format a Date
```typescript
// 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
```typescript
formatSinhalaDate(date: Date): string
```
### Parameters:
- `date`: JS Date object
### Returns:
Sinhala-formatted date string or fallback if invalid.
## 🧪 Run Tests
```bash
# Make sure you have Jest installed
pnpm add -D jest @types/jest ts-jest
pnpm test
```
## 🛠 Build CJS + ESM
```bash
# Make sure you have TypeScript and tsc-alias installed
pnpm add -D typescript ts-jest
pnpm build
```
## 📁 Structure
```bash
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.