<commit_before>require('colors');
var fs = require('fs');
var path = require('path');
var request = require('request');
var log = require('npmlog');

var error = require('../lib/error');

exports = module.exports = shrinkwrap;
 
exports.usage =
function usage(name, args) {
    args.usage('nsp shrinkwrap');
};
 
function shrinkwrap(args) {
  //console.log('→ New issues'.green);
    var file = path.resolve(process.cwd(), 'npm-shrinkwrap.json');
    // Check if file exists
    fs.exists(file, function (exists) {
        if (!exists) {
            return error('Can\'t load ' + file + '\nMake sure you have run \'npm shrinkwrap\'');
        }    
        fs.createReadStream(file).pipe(
            request({
                url: 'https://nodesecurity.io/validate/shrinkwrap',
                method: 'post',
                headers: {
                    'content-type': 'application/json'
                }
            }, function (err, response, body) {
                // review results
                console.log(body);<commit_msg>pretty printing of output<commit_after>require('colors');
var fs = require('fs');
var path = require('path');
var request = require('request');
var log = require('npmlog');
var table = require('text-table');
var color = require('cli-color');
var ansiTrim = require('cli-color/lib/trim');

var error = require('../lib/error');

exports = module.exports = shrinkwrap;
 
exports.usage =
function usage(name, args) {
    args.usage('nsp shrinkwrap');
};
 
function shrinkwrap(args) {
  //console.log('→ New issues'.green);
    var file = path.resolve(process.cwd(), 'npm-shrinkwrap.json');
    // Check if file exists
    fs.exists(file, function (exists) {
        if (!exists) {
            return error('Can\'t load ' + file + '\nMake sure you have run \'npm shrinkwrap\'');
        }    
        fs.createReadStream(file).pipe(
            request({
                url: 'https://nodesecurity.io/validate/shrinkwrap',
                method: 'post',
                headers: {
                    'content-type': 'application/json'
                },
                json: true
            }, function (err, response, body) {
                if (body && body.length > 0) {
                    // Pretty output
                    var opts = {
                        align: [ 'l', 'c', 'c', 'l' ],
                        stringLength: function (s) { return ansiTrim(s).length; }
                    };

                    var h = [
                        [
                            color.underline('Name'), color.underline('Installed'), color.underline('Patched'), color.underline('Vulnerable Dependency')
                        ]
                    ];
                    body.forEach(function (module) {
                        h.push([module.module, module.version, module.advisory.patched_versions, module.dependencyOf.join(' > ')]);
                    });
                    var t = table(h, opts);
                    console.error(t);
                    process.exit(1);
                } else {
                    console.error(color.green("No vulnerable modules found"));
                    process.exit(0);              
                }
{'fraction_non_alphanumeric': 0.14375, 'fraction_numerical': 0.0009375, 'mean_word_length': 1.665278934221482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '622643', 'n_tokens_mistral': 888, 'n_tokens_neox': 825, 'n_words': 193}