https://github.com/silverwind/timerel
Teeny-tiny relative date formatting
https://github.com/silverwind/timerel
Last synced: about 1 year ago
JSON representation
Teeny-tiny relative date formatting
- Host: GitHub
- URL: https://github.com/silverwind/timerel
- Owner: silverwind
- Created: 2022-07-29T20:02:03.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T19:12:01.000Z (about 2 years ago)
- Last Synced: 2024-04-14T09:49:35.216Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 807 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# timerel
[](https://www.npmjs.org/package/timerel) [](https://www.npmjs.org/package/timerel) [](https://bundlephobia.com/package/timerel) [](https://packagephobia.com/result?p=timerel)
`timerel` formats dates to short english relative format `5 mins ago` and does so around [11 times faster](./bench.ts) than [its competition](https://github.com/hustcc/timeago.js).
## Usage
```ts
import {timerel} from "timerel";
console.log(timerel(Date.now() - 1e6));
// => 16 mins ago
```
## API
### timerel(date, opts?)
- `date` *String, Number or Date*: The date to format.
#### Options
- `now` *String, Number or Date*: The date to compare to. Default: `Date.now()`.
- `noAffix` *Boolean*: Whether to omit `ago` and `in` affixes. Default: `false`.
- `times` *Array*: A custom time table that overrides the built-in one.
- `nowThreshold` *Number*: Number of milliseconds below which to output `"now"`. Default: 2000.
- `nowString` *String*: String to output for now. Default: `"now"`.
- `unknownString` *String*: String to output for invalid dates. Default: `String(date)`.
- `aliases` *Boolean*: Use aliases like "yesterday" instead of "1 day ago". Default: `false`.
- `aliasesMap` *Object*: A custom aliases object to use instead of the built-in one.
- `longUnits` *Boolean*: Use minutes/secoonds instead of mins/secs. Default: `false`.
© [silverwind](https://github.com/silverwind), distributed under BSD licence