<commit_before>#!/usr/bin/env node

(function() {
    'use strict';
    
    var fs              = require('fs'),
        path            = require('path'),
        rendy           = require('rendy'),
        args            = process.argv.slice(2),
        arg             = args[0];
        
    if (!arg)
        usage();
    else if (/^(-v|--v)$/.test(arg))
        version();
    else if (/^(-h|--help)$/.test(arg))
        help();
    else
        checkFile(arg, function(error) {
           if (!error)
                main(arg);
            else
                console.error(error.message);
       });
    
    function main(name) {
        var socket,
            cwd         = process.cwd() + '/',
            filename    = path.normalize(cwd + name),
            DIR         = __dirname + '/../assets/',
            edward      = require('../'),
            http        = require('http'),
            express     = require('express'),
            io          = require('socket.io'),
            restafary   = require('restafary'),
            
            app         = express(),
            server      = http.createServer(app),
            
            port        =   process.env.PORT            ||  /* c9           */
                            process.env.app_port        ||  /* nodester     */
                            process.env.VCAP_APP_PORT   ||  /* cloudfoundry */
                            1337,
            ip          =   process.env.IP              ||  /* c9           */
                            '0.0.0.0';
        
        app .use(restafary({
                prefix: '/api/v1/fs'
            }))
            .use(express.static(DIR))
            .use(edward({
                minify: false
            }))
            .get('/file', function(req, res) {
                fs.readFile(name, 'utf8', function(error, data) {
                    if (error)
                        res .status(404)
                            .send(error.message);
                    else
                        res.send({
                            name: filename,
                            data: data
                        });
                });
            });
        
        server.listen(port, ip),
        
        socket      = io.listen(server),
        edward.listen(socket);
        
        console.log('url: http://' + ip + ':' + port);
    }
    
    function checkFile(name, callback) {
        var ERROR_ENOENT    = 'Error: no such file or directory: \'{{ name }}\'',
            ERROR_ISDIR     = 'Error: \'{{ name }}\' is directory';
        
        fs.stat(name, function(error, stat) {
            var msg;
            
            if (error && error.code === 'ENOENT')
                msg = ERROR_ENOENT;
            else if (stat.isDirectory())
                msg = ERROR_ISDIR;
                
            if (msg)
                error.message = rendy(msg, {
                    name: arg
                });
            
            callback(error);
        });
    }
    
    function version() {
        console.log('v' + info().version);
    }
    
    function info() {
        return require('../package');
    }
    
    function usage() {
        var msg = 'Usage: ' + info().name + ' [filename]';
        console.log(msg);
    }
    
    function help() {
        var bin         = require('../json/bin');
            
        usage();
        console.log('Options:');
        
        Object.keys(bin).forEach(function(name) {
            var line = '  ' + name + ' ' + bin[name];
            console.log(line);
        });
    }
})();
<commit_msg>fix(edward) checkFile: error is null<commit_after>#!/usr/bin/env node

(function() {
    'use strict';
    
    var fs              = require('fs'),
        path            = require('path'),
        rendy           = require('rendy'),
        args            = process.argv.slice(2),
        arg             = args[0];
        
    if (!arg)
        usage();
    else if (/^(-v|--v)$/.test(arg))
        version();
    else if (/^(-h|--help)$/.test(arg))
        help();
    else
        checkFile(arg, function(error) {
           if (!error)
                main(arg);
            else
                console.error(error.message);
       });
    
    function main(name) {
        var socket,
            cwd         = process.cwd() + '/',
            filename    = path.normalize(cwd + name),
            DIR         = __dirname + '/../assets/',
            edward      = require('../'),
            http        = require('http'),
            express     = require('express'),
            io          = require('socket.io'),
            restafary   = require('restafary'),
            
            app         = express(),
            server      = http.createServer(app),
            
            port        =   process.env.PORT            ||  /* c9           */
                            process.env.app_port        ||  /* nodester     */
                            process.env.VCAP_APP_PORT   ||  /* cloudfoundry */
                            1337,
            ip          =   process.env.IP              ||  /* c9           */
                            '0.0.0.0';
        
        app .use(restafary({
                prefix: '/api/v1/fs'
            }))
            .use(express.static(DIR))
            .use(edward({
                minify: false
            }))
            .get('/file', function(req, res) {
                fs.readFile(name, 'utf8', function(error, data) {
                    if (error)
                        res .status(404)
                            .send(error.message);
                    else
                        res.send({
                            name: filename,
                            data: data
                        });
                });
            });
        
        server.listen(port, ip),
        
        socket      = io.listen(server),
        edward.listen(socket);
        
        console.log('url: http://' + ip + ':' + port);
    }
    
    function checkFile(name, callback) {
        var ERROR_ENOENT    = 'Error: no such file or directory: \'{{ name }}\'',
            ERROR_ISDIR     = 'Error: \'{{ name }}\' is directory';
        
        fs.stat(name, function(error, stat) {
            var msg;
            
            if (error && error.code === 'ENOENT')
                msg = ERROR_ENOENT;
            else if (stat.isDirectory())
                msg = ERROR_ISDIR;
                
            if (msg)
                error = {
                    message: rendy(msg, {
                        name: arg
                    })
                };
            
            callback(error);
        });
    }
    
    function version() {
        console.log('v' + info().version);
    }
    
    function info() {
        return require('../package');
    }
    
    function usage() {
        var msg = 'Usage: ' + info().name + ' [filename]';
        console.log(msg);
    }
    
    function help() {
        var bin         = require('../json/bin');
            
        usage();
        console.log('Options:');
        
        Object.keys(bin).forEach(function(name) {
            var line = '  ' + name + ' ' + bin[name];
            console.log(line);
        });
    }
})();

{'fraction_non_alphanumeric': 0.1375479978058146, 'fraction_numerical': 0.004662643993417444, 'mean_word_length': 0.9207268896497235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3544854', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1904, 'n_words': 359}