Skip to main content

js-common

A focused set of TypeScript utilities for the everyday JavaScript/Node.js work almost every project repeats — date math, string formatting, array/object helpers, validation, UUIDs, retries, sleeps, currency, and so on. Each module ships as a separate subpath so your bundler only includes what you actually import.

  • Ultra-lightweight — main bundle ~277 B; individual modules ~50–200 B.
  • Tree-shakeable — named subpath exports; the root entry is intentionally empty.
  • TypeScript-first — strict types, generics preserved, JSDoc-rich in your IDE.
  • CLI includednpx @rtorcato/js-common@latest --help for terminal use.

Install

npm install @rtorcato/js-common

Requirements: Node.js ≥ 22. TypeScript ≥ 5.0 is optional but recommended — every public API ships with strict types and JSDoc.

Use globally (CLI)

npm install -g @rtorcato/js-common
# or run ad-hoc without installing
npx @rtorcato/js-common@latest --help

See the CLI guide for available commands.

Quick start

Import named functions from a subpath export to keep your bundle tiny:

import { today, daysBetween } from '@rtorcato/js-common/date'
import { sum, average } from '@rtorcato/js-common/numbers'
import { capitalize } from '@rtorcato/js-common/strings'
import { generateUUID } from '@rtorcato/js-common/uuid'

today() // "2026-06-12"
daysBetween('2026-01-01', '2026-06-12') // 162
sum([1, 2, 3, 4, 5]) // 15
average([10, 20, 30]) // 20
capitalize('hello world') // "Hello world"
generateUUID() // "f47ac10b-58cc-4372-a567-0e02b2c3d479"

Always import from a subpath — never from the package root:

// ✅ Adds ~50–200 bytes
import { today } from '@rtorcato/js-common/date'

// ❌ Root entry is empty by design — this resolves to nothing
import { today } from '@rtorcato/js-common'

See Tree-shaking & imports for the full explanation.

What's in the box

  • 45+ subpath modules, one concern per module — see the Module overview.
  • Strict TypeScript — generics preserved end-to-end; any avoided in public APIs.
  • JSDoc on every public function — hover docs in VS Code, JetBrains, and Cursor.
  • Minimal runtime deps — only date-fns, date-fns-tz, luxon, pino, uuid, short-uuid, zod. CLI-only packages live in optionalDependencies.
  • Tested — Vitest with coverage; CI runs on every commit.

Highlights

AreaSubpathExample helpers
Dates & timedate, datetime, timetoday, daysBetween, formatRelative, nowIso, unixTimestamp
Numbers & mathnumbers, math, currencysum, average, roundTo, clamp, formatCurrency
Stringsstrings, formatting, regexslugify, truncate, capitalize, removeEmojis
Collectionsarrays, objects, sets, mapsunique, chunk, groupBy, deepMerge, pick, omit
Asyncpromises, sleep, abortController, functionsretry, timeout, delay, debounce, throttle
Validationvalidation, emails, url, uuidisValidEmail, isValidUrl, generateUUID
Systemenv, os, node, process, systemenvironment, platform, runtime info
Otherjson, fetch, file, logger, security, i18n, htmlsafeJsonParse, isStrongPassword, …

See the full module overview for the complete list.

Design principles

  • Small surface, no kitchen sink. Each module covers one concern. If something needs a heavyweight dependency (locale-aware date formatting, IANA timezones, schema validation across HTTP boundaries), reach for a dedicated library (date-fns, luxon, zod).
  • Subpath imports are the contract. The package root re-exports nothing — you always import from @rtorcato/js-common/<module> so tree-shaking is automatic.
  • Strict TS, no implicit any in public APIs. Generic helpers preserve narrow types through the call.

Next steps

Project