Comparing version 0.0.3 to 0.0.4
#!/usr/bin/env node | ||
// var args = process.argv.slice(2) | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
var readline = require('readline'); | ||
var beautify = require("json-beautify"); | ||
var fileName = argv['_'][0] | ||
var inputStream; | ||
if(typeof fileName === 'string'){ | ||
inputStream = require('fs') | ||
.createReadStream(fileName) | ||
} else { | ||
inputStream = process.stdin | ||
} | ||
var colors = require('colors'); | ||
colors.setTheme({ | ||
@@ -18,6 +27,2 @@ silly: 'grey', | ||
var fs = require('fs'); | ||
var beautify = require("json-beautify"); | ||
var fileName = argv['_'][0] | ||
console.log(argv) | ||
var orOptions = argv['o'] | ||
@@ -32,10 +37,5 @@ if(orOptions && typeof orOptions === 'string' ) | ||
var file = fs.readFileSync(fileName).toString() | ||
function removeDuplicateFilter(item, pos, self) { | ||
return self.indexOf(item) == pos; | ||
} | ||
function printBlock(item) { | ||
function beautifyJson(item) { | ||
var splitted = item.split('\n.\n') | ||
@@ -64,4 +64,2 @@ var header = splitted[0] | ||
} | ||
} | ||
@@ -80,9 +78,23 @@ | ||
var res = file | ||
.split('\n\n') | ||
.filter(removeDuplicateFilter) | ||
var rl = readline.createInterface({ | ||
input: inputStream, | ||
// output: process.stdout | ||
}); | ||
var alreadyPrintedBlocks = []; | ||
var curBlock; | ||
var lastLine; | ||
rl.on('line', function (line) { | ||
if(!line && !lastLine.index){ | ||
// console.log('\n ########### \n') | ||
if(alreadyPrintedBlocks.indexOf(curBlock) === -1 ){ | ||
alreadyPrintedBlocks.push(curBlock) | ||
printBlock(curBlock) | ||
} | ||
curBlock = "" | ||
} else { | ||
curBlock += '\n'+line | ||
} | ||
res | ||
.forEach(beautifyJson) | ||
lastLine = line | ||
}); |
{ | ||
"name": "j_utils", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
2938
4
89