Merge branch '3.0' of https://github.com/calzoneman/sync into 3.0
[KisSync.git] / src / configuration / configloader.js
blob604151fbef037c967b8ed2ef9f75308ef01ba9e0
1 import toml from 'toml';
2 import fs from 'fs';
4 /** @module cytube-common/configuration/configloader */
6 /**
7 * Load a toml file and pass the results to a configuration
8 * constructor.
10 * @param {function} constructor Constructor to call with the loaded data
11 * @param {string} filename Path to the toml file to load
12 * @returns {Object} Configuration object constructed from the provided constructor
13 * @throws {SyntaxError} Errors propagated from toml.parse()
15 export function loadFromToml(constructor, filename) {
16 const rawContents = fs.readFileSync(filename).toString('utf8');
17 const configData = toml.parse(rawContents);
18 return new (constructor)(configData);