<commit_before>var gutil       = require('gulp-util');
var path        = require('path');
var through     = require('through2');
var chalk       = require('chalk');
var Q           = require("q");
var request     = require('request');
var fs          = require("fs");

// Colors
var errorbold   = chalk.bold.red;
var error       = chalk.bold.red;
var allgood     = chalk.green;
var allgoodbold = chalk.bold.green;
var gray        = chalk.gray;

function slang(file, opt) {
    // if no options passed, create options object
    if (!opt) opt = {};

    // Set defaults for options
    var HOST        = opt.host || 'localhost';
    var PORT        = opt.port || 4502;
    var USER        = opt.username || 'admin';
    var PASS        = opt.password || '<PASSWORD>';
    var deferred    = Q.defer();
    var URL;


    // if jcr_root is in file system path, remove before setting destination
    var destPath = file.path;
    if (path.dirname(destPath).indexOf('jcr_root/') !== -1) {
        destPath = destPath.substring(path.dirname(destPath)
            .indexOf('jcr_root/') + 9);
    }

    // create full URL for curl path
    URL = 'http://' + USER + ':' + PASS + '@' +
        HOST + ':' + PORT + '/' + path.dirname(destPath) + ".json";

    var options = {
        url: URL,
        method: 'POST',
        headers: {
            'Accept': 'application/json'
        }
    };

    function optionalCallback (err, httpResponse, responseBody) {


        if (err) {
            return deferred.reject( err );
        }

        try{

            var response = JSON.parse( responseBody );

            var status      = response['status.code'] ? response['status.code'] : 201;
            var message     = response['status.message'] ? response['status.message'] : 'File Created';
            var location    = response.location ? response.location : file.path;

            if (status === 200 || status === 201 ) {
                gutil.log( allgoodbold('File Upload Successful to port ') + allgood(PORT) + allgood(" : ") +
                    allgood(status) + ' - ' + allgood(message));
                gutil.log(gray('Uploaded To: ') + gray(location));
            } else {
                gutil.log(errorbold('File Upload Failed: ') +
                    error(status) + ' - ' + error(message));
            }

        }catch(err){

            // generic error most often given with username and password
            gutil.log(errorbold('File Upload Failed - Check Username and Password'));

        }

        deferred.resolve( responseBody );

    };

    var r = request( options , optionalCallback ).auth("admin","admin");

    var form = r.form();

    form.append('*', fs.createReadStream( file.path ) );
    form.append('@TypeHint', "nt:file");


    return deferred.promise;
}

module.exports = slang;
<commit_msg>updated to use user defined credentials<commit_after>var gutil       = require('gulp-util');
var path        = require('path');
var through     = require('through2');
var chalk       = require('chalk');
var Q           = require("q");
var request     = require('request');
var fs          = require("fs");

// Colors
var errorbold   = chalk.bold.red;
var error       = chalk.bold.red;
var allgood     = chalk.green;
var allgoodbold = chalk.bold.green;
var gray        = chalk.gray;

function slang(file, opt) {
    // if no options passed, create options object
    if (!opt) opt = {};

    // Set defaults for options
    var HOST        = opt.host || 'localhost';
    var PORT        = opt.port || 4502;
    var USER        = opt.username || 'admin';
    var PASS        = opt.password || '<PASSWORD>';
    var deferred    = Q.defer();
    var URL;


    // if jcr_root is in file system path, remove before setting destination
    var destPath = file.path;
    if (path.dirname(destPath).indexOf('jcr_root/') !== -1) {
        destPath = destPath.substring(path.dirname(destPath)
            .indexOf('jcr_root/') + 9);
    }

    // create full URL for curl path
    URL = 'http://' + USER + ':' + PASS + '@' +
        HOST + ':' + PORT + '/' + path.dirname(destPath) + ".json";

    var options = {
        url: URL,
        method: 'POST',
        headers: {
            'Accept': 'application/json'
        }
    };

    function optionalCallback (err, httpResponse, responseBody) {


        if (err) {
            return deferred.reject( err );
        }

        try{

            var response = JSON.parse( responseBody );

            var status      = response['status.code'] ? response['status.code'] : 201;
            var message     = response['status.message'] ? response['status.message'] : 'File Created';
            var location    = response.location ? response.location : file.path;

            if (status === 200 || status === 201 ) {
                gutil.log( allgoodbold('File Upload Successful to port ') + allgood(PORT) + allgood(" : ") +
                    allgood(status) + ' - ' + allgood(message));
                gutil.log(gray('Uploaded To: ') + gray(location));
            } else {
                gutil.log(errorbold('File Upload Failed: ') +
                    error(status) + ' - ' + error(message));
            }

        }catch(err){

            // generic error most often given with username and password
            gutil.log(errorbold('File Upload Failed - Check Username and Password'));

        }

        deferred.resolve( responseBody );

    };

    var r = request( options , optionalCallback ).auth(USER,PASS);

    var form = r.form();

    form.append('*', fs.createReadStream( file.path ) );
    form.append('@TypeHint', "nt:file");


    return deferred.promise;
}

module.exports = slang;

{'fraction_non_alphanumeric': 0.14235500878734622, 'fraction_numerical': 0.00562390158172232, 'mean_word_length': 2.0047518479408657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '6373928', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1595, 'n_words': 427}