shelving/util/constantsmodule

Named constants for common numeric magnitudes, time durations, whitespace characters, and control symbols. Import these instead of magic numbers to keep code readable and consistent.

  • Time constants (SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR) are in milliseconds, matching the Date API.
  • MONTH is 30 days and YEAR is 365 days — fixed approximations, not calendar-aware.
  • The three special symbols (ABORT, NONE, SKIP) are unique symbols, safe to use as sentinel values in union types.

Usage

Time durations

ts
import { SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from "shelving/util";

const cache = new Map();
setTimeout(() => cache.clear(), 5 * MINUTE);

const expiresAt = Date.now() + 30 * DAY;

Numeric magnitudes

ts
import { THOUSAND, TEN_THOUSAND, HUNDRED_THOUSAND, MILLION, BILLION, TRILLION } from "shelving/util";

const limit = 2 * MILLION;

Whitespace characters

ts
import { NBSP, THINSP, NNBSP } from "shelving/util";

// Non-breaking space — prevents line breaks between words
const label = `100${NBSP}km`;

// Narrow non-breaking space — conventional between a number and its unit
const formatted = `42${NNBSP}°C`;

Control symbols

ts
import { ABORT, NONE, SKIP } from "shelving/util";

function process(value: unknown): string | typeof ABORT {
  if (cancelled) return ABORT;
  return String(value);
}

Status icons

ts
import { WAITING, SUCCESS, FAILURE, UP, DOWN, LEFT, RIGHT } from "shelving/util";

console.log(`${SUCCESS} Done`);
console.log(`${FAILURE} Failed`);

Constants

Go

THOUSANDconstant

One thousand.

Go

TEN_THOUSANDconstant

Ten thousand.

Go

HUNDRED_THOUSANDconstant

Hundred thousand.

Go

MILLIONconstant

One million.

Go

BILLIONconstant

One billion.

Go

TRILLIONconstant

One trillion.

Go

SECONDconstant

One second in milliseconds.

Go

MINUTEconstant

One minute in milliseconds.

Go

HOURconstant

One hour in milliseconds.

Go

DAYconstant

One day in milliseconds.

Go

WEEKconstant

One week in milliseconds.

Go

MONTHconstant

One month in milliseconds.

Go

YEARconstant

One year in milliseconds.

Go

NBSPconstant

Non-breaking space (U+00A0).

Go

THINSPconstant

Thin space (U+2009).

Go

NNBSPconstant

Non-breaking narrow space (U+202F, goes between numbers and their corresponding units).

Go

ABORTconstant

The ABORT symbol indicates something was manually aborted.

ABORT: unique symbol
Go

NONEconstant

The NONE symbol indicates something is nothing.

NONE: unique symbol
Go

SKIPconstant

The SKIP symbol indicates something should be silently skipped.

SKIP: unique symbol
Go

WAITINGconstant

Waiting/ellipsis icon character (⋯).

Go

SUCCESSconstant

Success/check icon character (✓).

Go

FAILUREconstant

Failure/cross icon character (✗).

Go

UPconstant

Up arrow icon character (↑).

Go

DOWNconstant

Down arrow icon character (↓).

Go

RIGHTconstant

Right arrow icon character (→).

Go

LEFTconstant

Left arrow icon character (←).