π Sponsor Development β’ π¦ NPM β’ π GitHub
@reliverse/repris is a modern, fast, and lightweight alternative to printj for printf-style string formatting in JavaScript and TypeScript.
Repris brings C-style printf/sprintf/vsprintf formatting to JavaScript/TypeScript, with support for positional and named arguments, BigInt, and advanced format specifiers. It's designed for speed, correctness, and compatibility, making it ideal for CLI tools, logs, and any situation where you need precise, flexible string formatting.
- β‘ Blazing-fast & lightweight β zero bloat, minimal dependencies, runtime-safe
- π¨οΈ C-style printf/vsprintf β familiar format strings, including width, precision, flags, and more
- π’ BigInt & number support β safely formats large integers and floats
- π§© Named & positional arguments β flexible APIs for both array and object-based formatting
- π‘οΈ Cross-platform & runtime-ready β works in Node.js, Bun, Deno, browsers, and more
- π― Drop-in alternative to printj β but faster, safer, and more modern
bun add @reliverse/repris
# bun β’ pnpm β’ yarn β’ npmClassic C-style formatting. Returns the formatted string.
Like sprintf, but takes an array of arguments.
Compiles a format string with named or positional arguments to a standard format string.
Formats a string using either an array or an object of arguments, with optional named argument mapping.
import { sprintf, vsprintf, formatString, compileFormat } from "@reliverse/repris";
// Classic usage:
const fmt = "%-date$s %-type$s: %message$s";
const compiled = compileFormat(fmt); // "% -1$s %-2$s: %4$s"
const out = vsprintf(compiled, ["2025-04-26", "ERROR", "unused", "Disk full"]);
console.log(out); // "2025-04-26 ERROR: Disk full"
// Alternative usage with named arguments:
console.log(
formatString(fmt, {
date: "2025-04-26",
type: "ERROR",
message: "Disk full",
}),
); // "2025-04-26 ERROR: Disk full"
// Exact 64-bit integer and alt-form binary:
console.log(sprintf("%#llx", 0x1_ffff_ffff_fffn)); // 0x1FFFFFFFFFFF
console.log(sprintf("%#B", 42)); // 0B101010- Strings:
%s - Integers:
%d,%i,%u,%o,%x,%X,%b,%B - Floats:
%f,%F,%e,%E,%g,%G - Char:
%c - Boolean:
%y,%Y(true/false or yes/no) - JSON:
%j,%J - Width, precision, flags, and positional arguments are supported (see below).
- Width, precision, left/right alignment, zero-padding, sign, alternate form (
#), and more - Supports both positional (
%2$s) and named arguments (%name$sviacompileFormat) - Handles BigInt and large numbers safely
You can use named arguments in your format strings by compiling them first:
const fmt = "%-date$s %-type$s: %message$s";
const compiled = compileFormat(fmt); // "% -1$s %-2$s: %4$s"
console.log(vsprintf(compiled, ["2025-04-26", "ERROR", "unused", "Disk full"]));
// Or use formatString for object-based formatting:
console.log(formatString(fmt, { date: "2025-04-26", type: "ERROR", message: "Disk full" }));console.log(sprintf("%#llx", 0x1_ffff_ffff_fffn)); // 0x1FFFFFFFFFFFconsole.log(sprintf("%y", true)); // true
console.log(sprintf("%j", { foo: 42 })); // {"foo":42}- CLI log formatting
- Pretty-printing data for terminal or file output
- Generating reports or tabular data
- Any situation where you need robust, C-style string formatting in JS/TS
git clone https://github.com/reliverse/repris
cd repris
bun i
bun devCheck examples/e-main.ts for more examples.
printjβ classic printf for JSsprintf-jsβ another printf implementation
Repris draws inspiration from these, but is designed for modern runtimes, with better type safety and performance.
We'd love your help! Bug? Feature? Example? PR it!
Or hop into Discord to discuss formatting, printf, and Reliverse tools π
git clone https://github.com/reliverse/repris
cd repris
bun iMIT Β© blefnk Nazar Kornienko
Part of the Reliverse ecosystem