diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-05-04 12:15:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-04 12:15:59 +0200 |
commit | 776dc9e3166dfc3735bd72be3acd26ebc6a591f5 (patch) | |
tree | ff0968c366537455aa1d7bfc42dff81549016e31 /README.md | |
parent | 02629b84de23bdc5896ac4b357e2f16dfb3996ec (diff) | |
parent | c4d1648ca6c3ac005b75c3b3b0bb79e664bead75 (diff) |
Merge pull request #6 from jow-/printf-improvements
String format improvements
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -898,7 +898,11 @@ libc's `printf()` implementation, namely it allows the `d`, `i`, `o`, `u`, `x`, `X`, `e`, `E`, `f`, `F`, `g`, `G`, `c` and `s` conversions. Additionally, an ucode specific `J` format is implemented, which causes the -corresponding value to be formatted as JSON string. +corresponding value to be formatted as JSON string. By prefixing the `J` format +letter with a precision specifier, the resulting JSON output will be pretty +printed. A precision of `0` will use tabs for indentation, any other positive +precision will use that many spaces for indentation while a negative or omitted +precision specifier will turn off pretty printing. Other format specifiers such as `n` or `z` are not accepted and returned verbatim. Format specifiers including `*` and `$` directives are rejected as @@ -911,6 +915,20 @@ well. printf("%c%c%c\n", 65, 98, 99); // Abc printf("%g\n", 10 / 3.0); // 3.33333 printf("%J", [1,2,3]); // [ 1, 2, 3 ] + + printf("%.J", [1,2,3]); + // [ + // 1, + // 2, + // 3 + // ] + + printf("%.2J", [1,2,3]); + // [ + // 1, + // 2, + // 3 + // ] %} ``` |