Options
Definition*:
1. Options must be a string that specifies
the path to the options file.
2. Options must be an object that specifies the type
such as 'parser' followed by additional options for
that type.
Note*:
Every plugin created must offer default options and must
be responsible with letting the developers know about the options
for your plugin (through GitHub, etc).
Optify
class
new Optify()
This class sets the options used for the plugins
class Optify {
constructor(options) {
log.debug(`class: ${Optify.name}`, `process: constructor`);
this.options = {};
var settings;
try {
if (_.isPlainObject(options) && !_.isEmpty(options))
this.options = options;
else if (_.isString(options)) {
// Normalize the string and if it ends in yml replace it
options = path.normalize(options.replace('yml', 'yaml'));
// Load the json or javascript file
if (/\.json/.test(options) || /\.js/.test(options)) {
settings = require(options);
this.options = settings;
} else if (/\.yaml/.test(options)) {
// Load yaml
settings = yaml.safeLoad(fs.readFileSync(options, 'utf8'));
this.options = settings;
} else if (/\.toml/.test(options)) {
// Load toml
settings = toml.parse(fs.readFileSync(options, 'utf8'));
this.options = settings;
} else {
throw new Error
('Oops! Did you forget to add the extension? \n' +
'The supported extensions are .json, .js, .toml, and .yaml.');
}
} else this.options = settings || {};
} catch (error) {
log.error(`class: ${Optify.name}`,
`error: ${error.stack || error.toString()}`);
}
}
}
optify
function
optify()
Option name | Type | Description |
---|---|---|
options | object | The options to parse |
return | object | The parsed options |
Returns the parsed options after
creating an instance of Optify
function optify(options) {
'use strict';
return new Optify(options).options;
}
export default optify;