From 1d29ce243d703aa4faff9ec6408fc0b1111551c9 Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Sat, 17 Jan 2015 19:44:06 +0000 Subject: [PATCH] add %j as an alias for %O same as util.format and many other implementations --- .gitignore | 1 + README.md | 1 + package.json | 7 +++++-- src/sprintf.js | 10 ++++++---- test/test.js | 3 +++ 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/README.md b/README.md index ec852a9..31fbbb6 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The placeholders in the format string are marked by "%" and are followed by one * e — print a float as scientific notation * u — print an integer as an unsigned decimal number * f — print a float as is + * j — print JSON of an object * o — print an integer as an octal number * O — print JSON of an object * s — print a string as is diff --git a/package.json b/package.json index 4b33c56..ee9c164 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha" }, "repository": { "type": "git", @@ -15,5 +15,8 @@ }, "author": "Alexandru Marasteanu (http://alexei.ro/)", "license": "BSD", - "readmeFilename": "README.md" + "readmeFilename": "README.md", + "devDependencies": { + "mocha": "^2.1.0" + } } diff --git a/src/sprintf.js b/src/sprintf.js index d778839..f1593ea 100644 --- a/src/sprintf.js +++ b/src/sprintf.js @@ -31,7 +31,7 @@ sprintf.chr_repeat = function(chr, n){ if (r && r.length>=n) return r.slice(0, n); r = chr; - for (; r.length