このコミットが含まれているのは:
Lukasz Sielski 2016-04-28 14:50:01 +01:00
コミット a6fbbc45a9
3個のファイルの変更84行の追加78行の削除

0
cli.js ノーマルファイル → 実行可能ファイル
ファイルの表示

ファイルの表示

@ -1,13 +1,12 @@
(function () {
"use strict";
var typeOf = require('remedial').typeOf
;
var typeOf = require('remedial').typeOf,
maxText = 60,
wrap = require('wordwrap')(maxText);
function stringify(data) {
var handlers
, indentLevel = ''
;
var handlers, indentLevel = '';
handlers = {
"undefined": function () {
@ -15,27 +14,36 @@
// as this may have unintended consequences
// For arrays, however, this behavior seems appropriate
return 'null';
}
, "null": function () {
},
"null": function () {
return 'null';
}
, "number": function (x) {
},
"number": function (x) {
return x;
}
, "boolean": function (x) {
},
"boolean": function (x) {
return x ? 'true' : 'false';
}
, "string": function (x) {
// to avoid the string "true" being confused with the
// the literal `true`, we always wrap strings in quotes
},
"string": function (x) {
var output = '|';
if (x.length <= maxText && x.indexOf('\n') === -1) {
return JSON.stringify(x);
}
, "date": function(x) {
var text = wrap(x).split(/\\n|\n/);
indentLevel = indentLevel.replace(/$/, ' ');
text.forEach(function (y) {
output += '\n' + indentLevel + y;
});
indentLevel = indentLevel.replace(/ /, '');
return output;
},
"date": function (x) {
return x.toJSON();
}
, "array": function (x) {
var output = ''
;
},
"array": function (x) {
var output = '';
if (0 === x.length) {
output += '[]';
@ -45,8 +53,7 @@
indentLevel = indentLevel.replace(/$/, ' ');
x.forEach(function (y) {
// TODO how should `undefined` be handled?
var handler = handlers[typeOf(y)]
;
var handler = handlers[typeOf(y)];
if (!handler) {
throw new Error('what the crap: ' + typeOf(y));
@ -58,10 +65,9 @@
indentLevel = indentLevel.replace(/ /, '');
return output;
}
, "object": function (x) {
var output = ''
;
},
"object": function (x) {
var output = '';
if (0 === Object.keys(x).length) {
output += '{}';
@ -70,9 +76,8 @@
indentLevel = indentLevel.replace(/$/, ' ');
Object.keys(x).forEach(function (k) {
var val = x[k]
, handler = handlers[typeOf(val)]
;
var val = x[k],
handler = handlers[typeOf(val)];
if ('undefined' === typeof val) {
// the user should do
@ -92,8 +97,8 @@
indentLevel = indentLevel.replace(/ /, '');
return output;
}
, "function": function () {
},
"function": function () {
// TODO this should throw or otherwise be ignored
return '[object Function]';
}

ファイルの表示

@ -27,7 +27,8 @@
},
"test": "echo 'error no test'; exit 1",
"dependencies": {
"remedial": "1.x"
"remedial": "1.x",
"wordwrap": "^1.0.0"
},
"devDependencies": {},
"preferGlobal": true