Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crlf option #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ function printHelp() {
w(' inspect: node.js `util.inspect` output');
w(' -i Shortcut for `-o inspect`');
w(' -j Shortcut for `-o json`');
w(' --crlf Output Windows style CRLF for line breaks as opposed to LF');
w(' -0, -2, -4 Set indentation to the given value w/o setting MODE.');
w(' -0 => -o jsony-0');
w(' -4 => -o jsony-4');
Expand Down Expand Up @@ -291,6 +292,7 @@ function parseArgv(argv) {
jsonIndent: 2,
array: null,
delim: ' ',
crlf: false,
lookupDelim: '.',
items: false,
outputKeys: false,
Expand Down Expand Up @@ -381,6 +383,9 @@ function parseArgv(argv) {
throw new Error('unknown output mode: "' + name + '"');
}
break;
case '--crlf':
parsed.crlf = true;
break;
case '-0':
parsed.jsonIndent = 0;
break;
Expand Down Expand Up @@ -1077,6 +1082,9 @@ function printDatasets(datasets, filename, headers, opts) {
var output = stringifyDatum(dataset[0], opts, isTTY);
var sep = dataset[1];
if (output && output.length) {
if (opts.crlf) {
output = output.replace(/\n/g, "\r\n");
}
write(output);
write(sep);
} else if (dataset[2]) {
Expand Down