Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adam-robson/nowandthen
https://github.com/adam-robson/nowandthen
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/adam-robson/nowandthen
- Owner: Adam-Robson
- License: mit
- Created: 2024-12-12T12:01:57.000Z (20 days ago)
- Default Branch: main
- Last Pushed: 2024-12-12T14:08:02.000Z (20 days ago)
- Last Synced: 2024-12-12T14:22:10.904Z (20 days ago)
- Language: TypeScript
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[top](#readme-top)
---
---
![logo](./nowandthen.svg "nowandthen logo")
# nowandthen
## Description
A lightweight library for working with dates. Supports Common & ES Modules. Written in TypeScript.
---
## Features
- format dates
- get the current date
- calculate days difference
- Add or subtract days from a date.
- Identify weekends.
- Start of the week calculation.---
## Installation
Install via npm:
```sh
npm install nowandthen
```---
## Usage
### ES Modules
```js
import { currentDate, formatDate } from "nowandthen";console.log(getCurrentDate()); // "2024-12-11"
console.log(formatDate(new Date(), "MM/DD/YYYY")); // "12/11/2024"
```### CommonJS
```js
const { currentDate, formatDate } = require("nowandthen");console.log(getCurrentDate()); // "2024-12-11"
console.log(formatDate(new Date(), "MM/DD/YYYY")); // "12/11/2024"
```---
## API Reference
`currentDate()`: Returns the current date in YYYY-MM-DD format.
`formatDate(date: Date, format: string)`: Formats a Date object into a
specific format.Supported tokens:
• YYYY: Year
• MM: Month
• DD: DayExample:
```js
formatDate(new Date(), "MM/DD/YYYY"); // "12/11/2024"
````differenceInDays(date1: Date, date2: Date)`: Returns the number of days
between two dates.`addDays(date: Date, days: number)`: Adds a specified number of days to a date.
---
## Benchmarks
Run benchmarks to measure performance:
```sh
node benchmarks/benchmark.js
```---
## Contributing
Feel free to open issues or submit pull requests.
## License
MIT
---