Skip to content

πŸ–¨οΈ @reliverse/repris is a modern, fast, and lightweight alternative to printj for printf-style string formatting in JavaScript and TypeScript.

License

Notifications You must be signed in to change notification settings

reliverse/repris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–¨οΈ Repris

πŸ’– Sponsor Development β€’ πŸ“¦ NPM β€’ 🌌 GitHub

@reliverse/repris is a modern, fast, and lightweight alternative to printj for printf-style string formatting in JavaScript and TypeScript.

Why Repris?

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

Installation

bun add @reliverse/repris
# bun β€’ pnpm β€’ yarn β€’ npm

API Overview

sprintf(fmt: string, ...args: any[]): string

Classic C-style formatting. Returns the formatted string.

vsprintf(fmt: string, argv: any[]): string

Like sprintf, but takes an array of arguments.

compileFormat(fmt: string, argMap?: FormatMap): string

Compiles a format string with named or positional arguments to a standard format string.

formatString(fmt: string, args: any[] | Record<string, unknown>, argMap?: FormatMap): string

Formats a string using either an array or an object of arguments, with optional named argument mapping.

Usage Examples

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

Format Specifiers

  • 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).

Flags and Features

  • Width, precision, left/right alignment, zero-padding, sign, alternate form (#), and more
  • Supports both positional (%2$s) and named arguments (%name$s via compileFormat)
  • Handles BigInt and large numbers safely

Advanced Usage

Named Arguments

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" }));

BigInt and Large Numbers

console.log(sprintf("%#llx", 0x1_ffff_ffff_fffn)); // 0x1FFFFFFFFFFF

Boolean and JSON

console.log(sprintf("%y", true)); // true
console.log(sprintf("%j", { foo: 42 })); // {"foo":42}

Use Cases

  • 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

Local Playground

git clone https://github.com/reliverse/repris
cd repris
bun i
bun dev

Check examples/e-main.ts for more examples.

Related

  • printj β€” classic printf for JS
  • sprintf-js β€” another printf implementation

Repris draws inspiration from these, but is designed for modern runtimes, with better type safety and performance.

πŸ›  Contributing

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 i

License

MIT Β© blefnk Nazar Kornienko
Part of the Reliverse ecosystem

About

πŸ–¨οΈ @reliverse/repris is a modern, fast, and lightweight alternative to printj for printf-style string formatting in JavaScript and TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published