<commit_before>// Filename: scrounge_opts.js  
// Timestamp: 2015.12.19-23:35:28 (last modified)
// Author(s): bumblehead <<EMAIL>>

var fs = require('fs'),
    path = require('path'),
    util = require('util'),
    
    scrounge_file = require('./scrounge_file');

var scrounge_opts = module.exports = (function (o) {

  o = function (opts) {
    return o.get(opts);
  };

  o.ispathexist = function (filepath) {
    return scrounge_file.isexist(filepath);
  };

  o.getasbool = function (val, defval) {
    if (String(val) === 'true')  defval = true;
    if (String(val) === 'false') defval = false;    

    return defval ? true : false;    
  };

  o.getasstring = function (val, defval) {
    if (typeof val === 'string' && val) defval = val;

    return String(defval);
  };

  o.getasarr = function (val, defval) {
    if (Array.isArray(val))      defval = val;
    if (typeof val === 'string') defval = val.split(',');

    return defval;
  };

  o.getassuffixed = function (pathval, suffix) {
    var extn = path.extname(pathval),
        base = path.basename(pathval, extn),
        dir = path.dirname(pathval);

    return path.join(dir, base + '.tpl' + extn);
  };

  o.get = function (opt) {
    var finopt = {};

    // all options optional
    opt = opt || {};
    
    finopt.inputpath  = o.getasstring(opt.inputpath, './');
    finopt.outputpath = o.getasstring(opt.outputpath, './www_');
    finopt.publicpath = o.getasstring(opt.publicpath, './');

    finopt.tplextnarr = ['.mustache'];
    finopt.cssextnarr = ['.css', '.less'];
    finopt.jsextnarr  = ['.js'];    

    finopt.typearr    = o.getasarr(opt.typearr, []);
    finopt.treearr    = o.getasarr(opt.treearr, []);
    finopt.skippatharr = o.getasarr(opt.skippatharr, []);    
    finopt.treetype   = /full/.test(opt.treetype) ? 'full' : 'small';
    
    finopt.isconcat   = o.getasbool(opt.isconcatenated, true);
    finopt.iscompress = o.getasbool(opt.iscompressed, false);
    finopt.issilent   = o.getasbool(opt.issilent, false);
    finopt.isupdate   = o.getasbool(opt.isupdateonly, false);
    finopt.istpl      = o.getasbool(opt.istpl, false);    
    finopt.browser    = o.getasbool(opt.isbrowser, true);    
      
    finopt.basepage   = o.getasstring(opt.basepage, '');
    finopt.basepagein = o.getasstring(opt.basepagein, finopt.basepage);    

    finopt.preprocessarr = [
      ['.js', function (opts, filename, str, fn) {
        try {
          fn(null, uglifyjs.minify(str, { fromString: true }).code);<commit_msg>Update scrounge_opts.js<commit_after>// Filename: scrounge_opts.js  
// Timestamp: 2015.12.19-23:35:28 (last modified)
// Author(s): bumblehead <<EMAIL>>

var fs = require('fs'),
    path = require('path'),
    util = require('util'),
    
    scrounge_file = require('./scrounge_file');

var scrounge_opts = module.exports = (function (o) {

  o = function (opts) {
    return o.get(opts);
  };

  o.ispathexist = function (filepath) {
    return scrounge_file.isexist(filepath);
  };

  o.getasbool = function (val, defval) {
    if (String(val) === 'true')  defval = true;
    if (String(val) === 'false') defval = false;    

    return defval ? true : false;    
  };

  o.getasstring = function (val, defval) {
    if (typeof val === 'string' && val) defval = val;

    return String(defval);
  };

  o.getasarr = function (val, defval) {
    if (Array.isArray(val))      defval = val;
    if (typeof val === 'string') defval = val.split(',');

    return defval;
  };

  o.getassuffixed = function (pathval, suffix) {
    var extn = path.extname(pathval),
        base = path.basename(pathval, extn),
        dir = path.dirname(pathval);

    return path.join(dir, base + '.tpl' + extn);
  };

  o.get = function (opt) {
    var finopt = {};

    // all options optional
    opt = opt || {};
    
    finopt.inputpath  = o.getasstring(opt.inputpath, './');
    finopt.outputpath = o.getasstring(opt.outputpath, './www_');
    finopt.publicpath = o.getasstring(opt.publicpath, './');

    finopt.tplextnarr = ['.mustache'];
    finopt.cssextnarr = ['.css', '.less'];
    finopt.jsextnarr  = ['.js'];    

    finopt.typearr    = o.getasarr(opt.typearr, []);
    finopt.treearr    = o.getasarr(opt.treearr, []);
    finopt.skippatharr = o.getasarr(opt.skippatharr, []);    
    finopt.treetype   = /full/.test(opt.treetype) ? 'full' : 'small';
    
    finopt.isconcat   = o.getasbool(opt.isconcatenated, true);
    finopt.iscompress = o.getasbool(opt.iscompressed, false);
    finopt.issilent   = o.getasbool(opt.issilent, false);
    finopt.isupdate   = o.getasbool(opt.isupdateonly, false);
    finopt.istpl      = o.getasbool(opt.istpl, false);    
    finopt.browser    = o.getasbool(opt.isbrowser, true);    
    finopt.iscircular = o.getasbool(opt.iscircular, false);
    
    finopt.basepage   = o.getasstring(opt.basepage, '');
    finopt.basepagein = o.getasstring(opt.basepagein, finopt.basepage);    

    finopt.preprocessarr = [
      ['.js', function (opts, filename, str, fn) {
        try {
          fn(null, uglifyjs.minify(str, { fromString: true }).code);
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.005496662740478995, 'mean_word_length': 2.825075075075075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6774468', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1851, 'n_words': 339}