mirror of
https://github.com/samsonjs/format.git
synced 2026-03-25 08:45:53 +00:00
add JSON support (%j)
This commit is contained in:
parent
35d4cf5f4f
commit
a2f2c59869
2 changed files with 6 additions and 1 deletions
|
|
@ -97,6 +97,9 @@
|
|||
tmp = String(parseFloat(nextArg()).toFixed(precision || 6));
|
||||
result += leadingZero ? tmp : tmp.replace(/^0/, '');
|
||||
break;
|
||||
case 'j': // JSON
|
||||
result += JSON.stringify(nextArg());
|
||||
break;
|
||||
case 'o': // number in octal
|
||||
result += '0' + parseInt(nextArg(), 10).toString(8);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ var tests = [
|
|||
[['%.2f', 3.14159], '3.14'],
|
||||
[['%0.2f', 3.14159], '3.14'],
|
||||
[['%.2f', 0.1234], '.12'],
|
||||
[['%0.2f', 0.1234], '0.12']
|
||||
[['%0.2f', 0.1234], '0.12'],
|
||||
[['foo %j', 42], 'foo 42'],
|
||||
[['foo %j', '42'], 'foo "42"']
|
||||
];
|
||||
tests.forEach(function(spec) {
|
||||
var args = spec[0];
|
||||
|
|
|
|||
Loading…
Reference in a new issue