Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avaray/datr
This package generates a date in a programmer-friendly format
https://github.com/avaray/datr
bun bunjs date development devops format formatting node node-js nodejs npm time timestamp timestamps uncommon
Last synced: 6 days ago
JSON representation
This package generates a date in a programmer-friendly format
- Host: GitHub
- URL: https://github.com/avaray/datr
- Owner: Avaray
- License: mit
- Created: 2018-12-12T16:23:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-23T10:36:06.000Z (9 months ago)
- Last Synced: 2024-03-24T06:42:20.982Z (8 months ago)
- Topics: bun, bunjs, date, development, devops, format, formatting, node, node-js, nodejs, npm, time, timestamp, timestamps, uncommon
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/datr
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🕘 DATR
This package will help you generate a date in a programmer-friendly format.
It might be useful for console logging, generating IDs, naming files, etc.## The Idea
Let's treat the **Date** as a **number**. It's all about increasing that **number**.
[Unix time](https://en.wikipedia.org/wiki/Unix_time) does that, but it's not human-readable.
The solution is to start with [YMD](https://en.wikipedia.org/wiki/Date_format_by_country#/media/File:Date_format_by_country_3.svg), add hours to it, and include milliseconds as the smallest unit.
The end result is the format **YYYYMMDDHHMMSSms**.
Many people use such a format. However, it has never been standardized.## DATR takes two arguments
### First, optional argument is `precision`
The argument sets the precision we want to see in output.
`0` - Year, Month, Day (default)
`1` - Year, Month, Day, Hour, Minute, Second
`2` - Year, Month, Day, Hour, Minute, Second, Millisecond### Second, optional argument is `separator`
You can pass a string separator to separate **blocks** and make the output more readable.
In examples below you can see dots and hyphens.## [Module](https://nodejs.org/api/esm.html#introduction) Installation
By using [NPM](https://docs.npmjs.com/cli-documentation/install)
```bash
npm i datr
```By using [PNPM](https://pnpm.io/cli/add)
```bash
pnpm add datr
```By using [BUN](https://bun.sh/docs/cli/add)
```bash
bun i datr
```## [Module](https://nodejs.org/api/esm.html#introduction) Usage
```js
import datr from 'datr';console.log(typeof datr());
// stringconsole.log(datr());
// 20221230console.log(datr(1));
// 20221230183500console.log(datr(2));
// 20221230183500001console.log(datr(2, '.'));
// 20221230.183500.001console.log(datr(2, '-'));
// 20221230-183500-001
```## [CLI](https://en.wikipedia.org/wiki/Command-line_interface) installation
By using [NPM](https://docs.npmjs.com/cli/v10/commands/npm-install#global)
```bash
npm i -g datr
```By using [PNPM](https://pnpm.io/cli/add#--global--g)
```bash
pnpm add -g datr
```By using [BUN](https://bun.sh/docs/cli/add#global)
```bash
bun i -g datr
```## [CLI](https://en.wikipedia.org/wiki/Command-line_interface) usage
```bash
datr
# 20221230datr 1
# 20221230183500datr 2
# 20221230183500001datr 2 .
# 20221230.183500.001datr 2 -
# 20221230-183500-001
```## [CLI](https://en.wikipedia.org/wiki/Command-line_interface) usage without installation
By using [NPM](https://docs.npmjs.com/cli/v10/commands/npx)
```bash
npx datr
```By using [PNPM](https://pnpm.io/cli/dlx)
```bash
pnpm dlx datr
```By using [BUN](https://bun.sh/docs/cli/bunx)
```bash
bunx datr
```