@onzipper/nb-common-libs
v1.0.1
Published
> A tiny, dependency-free set of TypeScript utilities, split into subpath modules so you only import what you use.
Readme
@onzipper/nb-common-libs

A tiny, dependency-free set of TypeScript utilities, split into subpath modules so you only import what you use.
- Zero dependencies — nothing is pulled into your tree
- Typed — declarations are bundled, no
@types/…needed - Subpath exports —
…/datetimeis imported separately from the root - ESM + CommonJS — works with
import,require(), and every major bundler
Install
npm install @onzipper/nb-common-libsUsage
import { sum, capitalize } from "@onzipper/nb-common-libs";
import { getDate } from "@onzipper/nb-common-libs/datetime";
// Numbers
sum(2, 3);
//=> 5
sum(-1, 1);
//=> 0
// Strings — only the first character is touched
capitalize("hello");
//=> "Hello"
capitalize("hello world");
//=> "Hello world"
// Dates — a fresh Date on every call
getDate();
//=> 2026-08-11T03:24:11.482ZCommonJS works identically:
const { sum, capitalize } = require("@onzipper/nb-common-libs");
const { getDate } = require("@onzipper/nb-common-libs/datetime");API
sum(a, b)
Returns: number
Adds two numbers together.
a
Type: number
b
Type: number
sum(2, 3);
//=> 5
sum(-1, 1);
//=> 0
// Ordinary IEEE-754 float behaviour applies — this is not rounded for you
sum(0.1, 0.2);
//=> 0.30000000000000004Extra arguments are ignored, so sum can be handed straight to reduce:
[1, 2, 3, 4].reduce(sum);
//=> 10
// Pass an initial value to stay safe on a possibly-empty array
[].reduce(sum, 0);
//=> 0capitalize(str)
Returns: string
Upper-cases the first character of a string. The rest of the string is left exactly as-is, so existing casing is preserved rather than lower-cased.
str
Type: string
capitalize("hello");
//=> "Hello"
// Only the first character changes — not every word
capitalize("hello world");
//=> "Hello world"
// The tail is preserved, not lower-cased
capitalize("hELLO");
//=> "HELLO"
// Accented characters are handled
capitalize("ñandu");
//=> "Ñandu"Values with no leading letter come back unchanged, so it is safe to call on arbitrary input:
capitalize("");
//=> ""
capitalize("123abc");
//=> "123abc"
capitalize("😀 hi");
//=> "😀 hi"One caveat worth knowing: leading whitespace counts as the first character, so trim first if the input may be padded.
capitalize(" hi");
//=> " hi"
capitalize(" hi".trim());
//=> "Hi"getDate()
Returns: Date
Returns a new Date for the current date and time. Each call produces a distinct object, so a returned value can be mutated without affecting anything else.
const now = getDate();
now instanceof Date;
//=> true
now.toISOString();
//=> "2026-08-11T03:24:11.482Z"
getDate() === getDate();
//=> false — a fresh instance every timeExamples
Normalising user input before display:
import { capitalize } from "@onzipper/nb-common-libs";
const name = capitalize(form.firstName.trim());
// " somchai " -> "Somchai"Totalling a cart, then stamping the order:
import { capitalize, sum } from "@onzipper/nb-common-libs";
import { getDate } from "@onzipper/nb-common-libs/datetime";
const items = [
{ label: "coffee", price: 120 },
{ label: "pastry", price: 85 },
{ label: "juice", price: 65 },
];
const order = {
total: items.map((item) => item.price).reduce(sum, 0),
//=> 270
placedAt: getDate(),
labels: items.map((item) => capitalize(item.label)),
//=> ["Coffee", "Pastry", "Juice"]
};Routing getDate through one place means tests can stub the clock in a single spot instead of every new Date() call site:
jest.mock("@onzipper/nb-common-libs/datetime", () => ({
getDate: () => new Date("2026-01-01T00:00:00Z"),
}));Subpath exports
Each module has its own specifier, so importing dates never pulls in the rest:
| Import specifier | Exports |
| ----------------------------------- | ------------------- |
| @onzipper/nb-common-libs | sum, capitalize |
| @onzipper/nb-common-libs/datetime | getDate |
TypeScript
Type declarations ship with the package — there is no separate @types/… to install, and types resolve for every subpath automatically.
The code is compiled to CommonJS targeting ES2020, and the exports map declares types, require, and default conditions. That means it resolves from ESM import, CommonJS require(), and bundlers including webpack, Turbopack, Vite, and Rollup.
If your tsconfig.json uses "moduleResolution" of "node16", "nodenext", or "bundler", subpath types work with no extra configuration.
Requirements
- Node.js 12 or newer — required by the
exportsfield
License
ISC
