string-format-js
Synopsis
String format function for javascript.
Code Example
%d
'%d' === '10''%d, %d' === '5, 10''%d, %d and %d' === '5, 10 and 15''%05d' === '00123''%03d, %05d' === '001, 00123''[%5d]' === '[ 123]''[%10d]' === '[ 123]''[%-5d]' === '[123 ]''[%-10d]' === '[123 ]'
%s
'This is a %s' === 'This is a pen''This is %s %s' === 'This is a pen''This %s %s %s' === 'This is a pen''[%5s]' === '[ abc]''[%12s]' === '[ abc]''[%-5s]' === '[abc ]''[%-12s]' === '[abc ]''[%.4s]' === '[abcd]''[%.12s]' === '[abcdefghijkl]''[%5.4s]' === '[ abcd]''[%12.10s]' === '[ abcdefghij]''[%-5.4s]' === '[abcd ]''[%-12.10s]' === '[ abcdefghij]''[%-5.4s]' === '[あいうえ ]''%s' === 'true''%s' === 'true''%s' === 'false''%s' === 'false''%s' === '$$''%s' === '$$$$''%s' === '$&''%s' === '$`''%s'
%o
'123 => %o' === '123 => 173''0x7b => %o' === '0x7b => 173'
%b
'123 => %b' === '123 => 1111011''0x7b => %b' === '0x7b => 1111011'
%x
'123 => %x' === '123 => 7b'
%X
'123 => %X' === '123 => 7B'
%u
'%u' === '3989547399''%u' === '4294967295'
%c
'%c' === 'a''%c' === 'a'
%f
'%f' === '1.000000''%.2f' === '1.00''[%10f]' === '[1.00000000]''[%10.2f]' === '[ 1.00]''[%10.2f]' === '[ 1.23]''[%-10.2f]' === '[1.00 ]'
%e
'%e' === '1.23e+2''%e' === '1.2345e+2''%.5e' === '1.23450e+2''[%15e]' === '[1.2345000000e+2]''[%20e]' === '[1.23456789014500e+10]''[%15.2e]' === '[ 1.23e+2]''[%7.2e]' === '[1.23e+2]''[%-15.2e]' === '[1.23e+2 ]'
hash
'#{name}' === 'Takashi Maeda''#{first} #{last}' === 'Takashi Maeda''#{a} #{b}, #{c} #{d}' === 'Easy come, easy go''#{a} #{b}, #{a} #{c}' === 'Easy come, Easy go''#{a} #{a} #{a}' === 'hello hello hello'
Installation
node
$ npm install string-format-js
bower
$ bower install string-format-js
Tests
node
$ grunt mochaTest
browser
$ grunt browserTest
License
This software is released under the MIT License, see LICENSE.txt.