Skip to main content
Home
This release is 40 versions behind 1.0.8 — the latest version of @std/fmt. Jump to latest

Utilities for formatting values, such as adding colors to text, formatting durations, printf utils, formatting byte numbers.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 years ago (0.204.0)

Printf for Deno

This is very much a work-in-progress. I'm actively soliciting feedback. What immediately follows are points for discussion.

  • What useful features are available in other languages apart from Golang and C?

  • behaviour of %v verb. In Golang, this is a shortcut verb to "print the default format" of the argument. It is currently implemented to format using toString in the default case and inspect if the %#v alternative format flag is used in the format directive. Alternatively, %V could be used to distinguish the two.

    inspect output is not defined, however. This may be problematic if using this code on other platforms (and expecting interoperability). To my knowledge, no suitable specification of object representation aside from JSON and toString exist. ( Aside: see "Common object formats" in the "Console Living Standard" which basically says "do whatever" )

  • %j verb. This is an extension particular to this implementation. Currently not very sophisticated, it just runs JSON.stringify on the argument. Consider possible modifier flags, etc.

  • < verb. This is an extension that assumes the argument is an array and will format each element according to the format (surrounded by [] and separated by comma) (< Mnemonic: pull each element out of array)

  • how to deal with more newfangled JavaScript features (generic Iterables, Map and Set types, typed Arrays, ...)

  • the implementation is fairly rough around the edges:

  • currently contains little in the way of checking for correctness. Conceivably, there will be a 'strict' form, e.g. that ensures only Number-ish arguments are passed to %f flags.

  • assembles output using string concatenation instead of utilizing buffers or other optimizations. It would be nice to have printf / sprintf / fprintf (etc) all in one.

  • float formatting is handled by toString() and to toExponential along with a mess of Regexp. Would be nice to use fancy match.

  • some flags that are potentially applicable ( POSIX long and unsigned modifiers are not likely useful) are missing, namely %q (print quoted), %U (unicode format)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.