npm.io
1.0.0 • Published 9 years ago

string-format-js

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0
Stars
19

string-format-js

License NPM version Build Status Coverage Status Downloads

Synopsis

String format function for javascript.

Code Example

%d
'%d'.format(10) === '10'
'%d, %d'.format(5, 10) === '5, 10'
'%d, %d and %d'.format(5, 10, 15) === '5, 10 and 15'
'%05d'.format(123) === '00123'
'%03d, %05d'.format(1, 123) === '001, 00123'
'[%5d]'.format(123) === '[ 123]'
'[%10d]'.format(123) === '[      123]'
'[%-5d]'.format(123) === '[123 ]'
'[%-10d]'.format(123) === '[123      ]'
%s
'This is a %s'.format('pen') === 'This is a pen'
'This is %s %s'.format('a', 'pen') === 'This is a pen'
'This %s %s %s'.format('is', 'a', 'pen') === 'This is a pen'
'[%5s]'.format('abc') === '[  abc]'
'[%12s]'.format('abc') === '[         abc]'
'[%-5s]'.format('abc') === '[abc  ]'
'[%-12s]'.format('abc') === '[abc         ]'
'[%.4s]'.format('abcde') === '[abcd]'
'[%.12s]'.format('abcdefghijklmn') === '[abcdefghijkl]'
'[%5.4s]'.format('abcde') === '[ abcd]'
'[%12.10s]'.format('abcdefghijklmnopq') === '[  abcdefghij]'
'[%-5.4s]'.format('abcde') === '[abcd ]'
'[%-12.10s]'.format('abcdefghijklmnopq') === '[  abcdefghij]'
'[%-5.4s]'.format('あいうえお') === '[あいうえ ]'
'%s'.format(true) === 'true'
'%s'.format('true') === 'true'
'%s'.format(false) === 'false'
'%s'.format('false') === 'false'
'%s'.format('$') === '$'
'%s'.format('$$') === '$$'
'%s'.format('__CODE_BLOCK_1__amp;') === '__CODE_BLOCK_1__amp;'
'%s'.format('

string-format-js

License NPM version Build Status Coverage Status Downloads

Synopsis

String format function for javascript.

Code Example

%d
'%d'.format(10) === '10'
'%d, %d'.format(5, 10) === '5, 10'
'%d, %d and %d'.format(5, 10, 15) === '5, 10 and 15'
'%05d'.format(123) === '00123'
'%03d, %05d'.format(1, 123) === '001, 00123'
'[%5d]'.format(123) === '[ 123]'
'[%10d]'.format(123) === '[      123]'
'[%-5d]'.format(123) === '[123 ]'
'[%-10d]'.format(123) === '[123      ]'
%s
'
) === '

string-format-js

License NPM version Build Status Coverage Status Downloads

Synopsis

String format function for javascript.

Code Example

%d
'%d'.format(10) === '10'
'%d, %d'.format(5, 10) === '5, 10'
'%d, %d and %d'.format(5, 10, 15) === '5, 10 and 15'
'%05d'.format(123) === '00123'
'%03d, %05d'.format(1, 123) === '001, 00123'
'[%5d]'.format(123) === '[ 123]'
'[%10d]'.format(123) === '[      123]'
'[%-5d]'.format(123) === '[123 ]'
'[%-10d]'.format(123) === '[123      ]'
%s
'
'%s'.format('
%o
'123 => %o'.format(123) === '123 => 173'
'0x7b => %o'.format(0x7b) === '0x7b => 173'
%b
'123 => %b'.format(123) === '123 => 1111011'
'0x7b => %b'.format(0x7b) === '0x7b => 1111011'
%x
'123 => %x'.format(123) === '123 => 7b'
%X
'123 => %X'.format(123) === '123 => 7B'
%u
'%u'.format(0x12345678 ^ 0xFFFFFFFF) === '3989547399'
'%u'.format(-1) === '4294967295'
%c
'%c'.format(97) === 'a'
'%c'.format(0x61) === 'a'
%f
'%f'.format(1.0) === '1.000000'
'%.2f'.format(1.0) === '1.00'
'[%10f]'.format(1.0) === '[1.00000000]'
'[%10.2f]'.format(1.0) === '[      1.00]'
'[%10.2f]'.format(1.2345) === '[      1.23]'
'[%-10.2f]'.format(1.0) === '[1.00      ]'
%e
'%e'.format(123) === '1.23e+2'
'%e'.format(123.45) === '1.2345e+2'
'%.5e'.format(123.45) === '1.23450e+2'
'[%15e]'.format(123.45) === '[1.2345000000e+2]'
'[%20e]'.format(12345678901.45) === '[1.23456789014500e+10]'
'[%15.2e]'.format(123.45) === '[        1.23e+2]'
'[%7.2e]'.format(123.45) === '[1.23e+2]'
'[%-15.2e]'.format(123.45) === '[1.23e+2        ]'
hash
'#{name}'.format({name:'Takashi Maeda'}) === 'Takashi Maeda'
'#{first} #{last}'.format({first:'Takashi', last:'Maeda'}) === 'Takashi Maeda'
'#{a} #{b}, #{c} #{d}'.format(a:'Easy', b:'come', c:'easy', d:'go'}) === 'Easy come, easy go'
'#{a} #{b}, #{a} #{c}'.format({a:'Easy', b:'come', c:'go'}) === 'Easy come, Easy go'
'#{a} #{a} #{a}'.format({a:'hello'}) === '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.

') === '$'' '[%5s]'.format('$') === '[ $]' '[%-5s]'.format('$') === '[$ ]' '[%.5s]'.format('abc$fg') === '[abc$]' '[%.4s]'.format('abc$fg') === '[abc$]' '[%5.5s]'.format('abc$fg') === '[abc$]' '[%5.4s]'.format('abc$fg') === '[ abc$]' '[%-5.5s]'.format('abc$fg') === '[abc$]' '[%-5.4s]'.format('abc$fg') === '[abc$ ]'
%o
__CODE_BLOCK_2__
%b
__CODE_BLOCK_3__
%x
__CODE_BLOCK_4__
%X
__CODE_BLOCK_5__
%u
__CODE_BLOCK_6__
%c
__CODE_BLOCK_7__
%f
__CODE_BLOCK_8__
%e
__CODE_BLOCK_9__
hash
__CODE_BLOCK_10__

Installation

node
__CODE_BLOCK_11__
bower
__CODE_BLOCK_12__

Tests

node
__CODE_BLOCK_13__
browser
__CODE_BLOCK_14__

License

This software is released under the MIT License, see LICENSE.txt.

Keywords