@santana-org/fmt
v0.2.0
Published
String and number formatting utilities for Santana Org CLIs — bytes, duration, relative time, truncate, wrap, pluralize
Maintainers
Readme
@santana-org/fmt
String and number formatting utilities for Santana Org CLIs.
Install
npm install @santana-org/fmtUsage
import {
formatBytes,
formatDuration,
formatRelative,
truncate,
wrap,
pluralize,
formatNumber,
formatPercent,
camelToKebab,
} from "@santana-org/fmt"
// bytes
formatBytes(1_500_000) // "1.5 MB"
formatBytes(1024, { binary: true }) // "1 KBi"
// duration
formatDuration(3_661_000) // "1 hr, 1 min, 1 sec"
formatDuration(3_661_000, { compact: true }) // "1h 1m 1s"
// relative time
formatRelative(new Date(Date.now() - 60_000)) // "1 minute ago"
formatRelative(new Date(Date.now() + 3_600_000)) // "in 1 hour"
// strings
truncate("hello world from cli", 12) // "hello world…"
truncate("hello world from cli", 12, { position: "middle" }) // "hello…m cli"
wrap("a long description that needs to wrap", 20)
pluralize(3, "file") // "3 files"
pluralize(1, "ox", "oxen") // "1 ox"
// numbers
formatNumber(1_234_567) // "1,234,567"
formatPercent(0.753) // "75.3%"
// case
camelToKebab("fooBarBaz") // "foo-bar-baz"