From 170a913fdf64c6082e18df58ead75c77a63515c9 Mon Sep 17 00:00:00 2001 From: karissa Date: Sun, 20 May 2018 16:39:57 -0500 Subject: [PATCH] use patched output fot neat log --- neat-screen.js | 2 +- output.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 output.js diff --git a/neat-screen.js b/neat-screen.js index 9e4ca29..a0cf32e 100644 --- a/neat-screen.js +++ b/neat-screen.js @@ -1,5 +1,5 @@ var neatLog = require('neat-log') -var output = require('neat-log/output') +var output = require('./output') var strftime = require('strftime') var Commander = require('./commands.js') var chalk = require('chalk') diff --git a/output.js b/output.js new file mode 100644 index 0000000..ad8c2fe --- /dev/null +++ b/output.js @@ -0,0 +1,19 @@ +module.exports = trim + +function trim (s) { + if (!/^\r?\n/.test(s)) return s + return deindent(s) +} + +function deindent (s) { + if (!/^\r?\n/.test(s)) return s + var indent = (s.match(/\n([ ]+)/m) || [])[1] || '' + s = indent + s + return s.split('\n') + .map(l => replace(indent, l)) + .join('\n') +} + +function replace (prefix, line) { + return line.slice(0, prefix.length) === prefix ? line.slice(prefix.length) : line +}