{"size": 1791, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "Berkmann18/hashmyjs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "Berkmann18/hashmyjs", "max_issues_repo_issues_event_min_datetime": "2017-12-31T11:00:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-07T21:27:31.000Z", "max_forks_repo_path": "index.js", "max_forks_repo_name": "Berkmann18/hashmyjs", "max_forks_repo_forks_event_min_datetime": "2018-08-13T07:10:29.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-01T09:34:53.000Z"}
{"max_stars_count": null, "max_issues_count": 986, "max_forks_count": 3, "avg_line_length": 31.4210526316, "max_line_length": 110, "alphanum_fraction": 0.6499162479}
'use strict';
/**
 * @description base64(SHA-256) text encoder inspired by {@link https://stackoverflow.com/a/38554505/5893085}.
 * @author Maximilian Berkmann
 * @module hashmyjs
 */
/* eslint-env es6, node */

const readIn = require('./src/stdin'),
  readFiles = require('./src/files');

/**
 * @description Start the hasher.
 * @param {string[]} [files=[]] List of files to go through
 * @param {Object} obj Configuration
 * @param {string} obj.format Format of the output (text, json, csv)
 * @param {string} obj.input Location of the input (any, stdin, args)
 * @param {string} obj.output Destination for the output (stdout, var, <i>filenames</i>)
 * @param {boolean} obj.prettify Prettify the output
 * @return {(undefined|string[]|string)} Data or nothing
 * @public
 * @example <caption>Reading from files or STDIN</caption>
 * run();
 * @example <caption>Reading from files</caption>
 * run(['index.js']);
 * run(['index.js'], {input: 'args'});
 * @example <caption>Reading from STDIN</caption>
 * run([]);
 * run([], {input: 'stdin'});
 * @example <caption>Reading from files with configurations</caption>
 * run(['index.js', 'index.css'], {format: 'json', output: 'index-hash.json', prettify: true});
 * @example <caption>Reading from STDIN with configurations</caption>
 * run([], {format: 'csv', input: 'stdin', prettify: true});
 */
const run = (files = [], { format = 'text', input = 'any', output = 'stdout', prettify = false } = {}) => {
  const opts = {
    prettify,
    outputDest: output,
    outputFormat: format
  };

  switch (input) {
  case 'stdin':
    return readIn(opts);
  case 'args':
    return readFiles(files, opts);
  default: //any
    return files.length ? readFiles(files, opts) : readIn(opts);
  }
};

module.exports = {
  run,
  readIn,
  readFiles
}
