Skip to content
printf-like formatting for JavaScript http://samhuri.net/proj/format
JavaScript Makefile
Find file
Latest commit 4f89809 @samsonjs Merge pull request #7 from chocolateboy/json
add JSON support (%j)
Failed to load latest commit information.
.gitignore add gitignore
Makefile fix test-minify target in Makefile
Readme.md better support for floating point precision (closes #6)
component.json better support for floating point precision (closes #6)
format-min.js work in browsers out of the box
format.js add JSON support (%j)
package.json better support for floating point precision (closes #6)
test_format.js

Readme.md

format

printf, sprintf, and vsprintf for JavaScript

Installation

npm install format

The code works in browsers as well, you can copy these functions into your project or otherwise include them with your other JavaScript.

Usage

var format = require('format')
  , printf = format.printf
  , vsprintf = format.vsprintf
  // or if you want to keep it old school
  , sprintf = format

// Print 'hello world'
printf('%s world', 'hello')

var what = 'life, the universe, and everything'
format('%d is the answer to %s', 42, what)
// => '42 is the answer to life, the universe, and everything'

vsprintf('%d is the answer to %s', [42, what])
// => '42 is the answer to life, the universe, and everything'

Supported format specifiers: b, c, d, f, o, s, x, and X.

See man 3 printf or man 1 printf for details.

Precision is supported for floating point numbers.

License

Copyright 2010 - 2014 Sami Samhuri sami@samhuri.net

MIT license

Something went wrong with that request. Please try again.