Skip to content

Avaray/datr

Repository files navigation

🕘 DATR

Dates should be sortable and human-readable at the same time. Unix timestamps are sortable but unreadable. Most date strings are readable but not sortable. YYYYMMDDHHMMSSms is both - common among developers, yet never formally standardized.

Useful for console logging, generating IDs, naming files, and more.

Module Installation

NPM

npm i datr

PNPM

pnpm add datr

BUN

bun i datr

DENO

deno add npm:datr

Module Usage

import datr from 'datr';

typeof datr();
// string

datr();
// 20260508

datr({ precision: 'seconds' });
// 20260508104700

datr({ precision: 'ms', separator: '-' });
// 20260508-104700-001

datr({ date: '2026-05-08', precision: 'seconds' });
// 20260508000000

Options

The datr function accepts an optional options object:

Option Type Default Description
precision 'day' | 'seconds' | 'ms' 'day' Smallest unit in the output.
separator string '' String inserted between blocks.
date Date | string | number new Date() Date to format (Date object, ISO string, or timestamp).

CLI installation

NPM

npm i -g datr

PNPM

pnpm add -g datr

BUN

bun i -g datr

DENO

deno i -g datr

CLI usage

datr
# 20260508

datr --precision seconds
# 20260508104700

datr --precision ms --separator -
# 20260508-104700-001

datr --date 2026-05-08 --precision seconds
# 20260508000000

datr --version
# 4.0.0

datr --help
# Usage: datr [options] ...

All options also support short flags: -p, -s, -d, -v, and -h.

datr -d "$(date)" -p ms -s -
# 20260508-104700-222

CLI usage without installation

NPM

npx datr

PNPM

pnx datr

BUN

bunx datr

DENO

deno run npm:datr

Migrating from v3

The API has changed from positional arguments to a single options object.

v3 (Positional) v4 (Object)
datr() datr()
datr(1) datr({ precision: 'seconds' })
datr(2) datr({ precision: 'ms' })
datr(2, '-') datr({ precision: 'ms', separator: '-' })

Contributors