Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sprint

GlitchMr3.8k0.3.1

Complex sprintf() implementation

sprintf, format, snprintf, printf, fprintf, vprintf, vfprintf, vsprintf, vsnprintf, vasprintf, print, echo

readme

sprint is implementation of sprintf function from C++. If it is ran in Node.js envirnoment then it's used as module, otherwise module inserts sprint() function into global object (usually window).

Usage:

var sprint = require('sprint').sprint;
// Will return "b a"
console.log(sprint('%2$s %1$s', 'a', 'b'));

All standard format placeholders are supported with the exception of %p (lack of pointers in JavaScript) and %n (lack of references in JavaScript).

In addition, following not standard features are supported:

  • n$ - number of the parameter allowing the parameters to be used multiple times or displayed in different order. It's not in C99, but it's POSIX entension, so support for it is already common.
  • %b and %B - a binary number
  • %D, %U, %O - practially their lowercase variants. Inserted in this list just because of their usage in Perl's printf() implementation.

For more information, read documentation of sprintf() in other programming languages.

changelog

2012-10-02 v0.3.1

  • Sprint now works with CoffeeLint
  • Added Python style %r modifier
  • The replace function doesn't use ... anymore.

2012-03-17 v0.3.0

  • Added CHANGELOG (this file)
  • Fixed unsigned integers. Hexadecimal, octal and binary now always work like unsigned values, unlike previous behavior.
  • Added integer sizes.
  • Fixed left "0" character aligning with strings.
  • Added Travis CI testing. It's currently experimental and might be removed in future, but hopefully it will inform about test failures in older version of Node.js.

2012-03-16 v0.2.3

  • Fixed %u modifier to be actually unsigned. Format can now be integer.
  • On Node.js, you can now do require('sprint')('%s', 'TEST')

2012-03-16 v0.2.2

  • Repackaged in order to fix #2.

2012-03-11 v0.2.1

  • Fixed sprint to work in IE.

2012-03-11 v0.2.0

  • Precision mixed with prefix (%#.4x) now works properly.
  • Fixed "Padding left using "0" characters". Previously, the behavior which was tested was invalid. It's now using correct behavior.
  • Vectors support added
  • Negative zero is now detected

2012-03-11 v0.1.1

  • Fixed array support test. Previously, it failed.

2012-03-10 v0.1.0

  • First release of sprint.