Copy utils from cytube-common and remove dep

The `cytube-common` module was created as part of a now-defunct
experiment and since then has just remained a crufty container for a few
utils.  Moved the utils to the main repo and removed the dependency.
This commit is contained in:
Calvin Montgomery 2017-07-19 20:47:02 -07:00
parent e780e7dadb
commit ff3ececc36
13 changed files with 358 additions and 9 deletions

View file

@ -0,0 +1,19 @@
import toml from 'toml';
import fs from 'fs';
/** @module cytube-common/configuration/configloader */
/**
* Load a toml file and pass the results to a configuration
* constructor.
*
* @param {function} constructor Constructor to call with the loaded data
* @param {string} filename Path to the toml file to load
* @returns {Object} Configuration object constructed from the provided constructor
* @throws {SyntaxError} Errors propagated from toml.parse()
*/
export function loadFromToml(constructor, filename) {
const rawContents = fs.readFileSync(filename).toString('utf8');
const configData = toml.parse(rawContents);
return new (constructor)(configData);
}