Better name than section()?
/**
* Produces an array containing one or more configurable sections.
* @param {String|String[]} setting the desired section(s) of output to include. `null` or `undefined` to include all
* possible options.
* @param {Any[]} options possible sections to include in output.
* @return {Array<Any>} the items from the desired section(s)
* @example <caption>Usage with JSVerify</caption>
* static nameGenerator(setting) {
* return jsc.oneof(this.ensureGenerator(this.section(setting, {
* communicators: [ "bob", "jane", "carlos", "frank" ],
* attackers: [ "craig", "eve", "mallory", "sybil" ],
* government: "grace",
* aid: [ "faythe", "trent", "victor", "walter" ],
* })));
* }
*
* jsc.forall(nameGenerator(null), person => isPerson(person));
* jsc.forall(nameGenerator("attackers"), person => isAttacker(person));
* jsc.forall(nameGenerator([ "communicators", "aid" ]), person => isSafe(person));
* jsc.forall(nameGenerator([ "attackers", "government" ]), person => !trustworthy(person));
*/
static section(setting, options) {
if(setting !== null || setting === undefined) {
options = filter(options, (val, key) => Array.isArray(setting) ? setting.indexOf(key) > -1 : key === setting);
}
return union(map(options, (val) => Array.isArray(val) ? val : [ val ]));
}
Better name than
section()?