Observable Options
A simple library for defining and managing options. It lets you register options, nest options, observe changes, reset to default value and define alias names.
Install
npm install --save-dev observable-options
API
Register options
const options = ; // registers new option in options list and sets a default value: `John`options; // registers multiple and nested optionsoptions;
Set and get values
// Change age valueoptions; // Change nested option valueoptions; // get valueoptions;options;
Observe changes
options; options; // observes any changes in optionsoptions; // observes any changes in caroptions; // add and remove observerlet { console;}; options; // remove observeroptions; // Observes multiple optionsoptions; // remove observeroptions;
Disable observers on set
// starts denying observersoptions; options;options; options; // denies observer on setoptions;
Reset to default
// resets age to defaultoptions; // 34 // resets a nested optionoptions; // red // resets all options of caroptions; // resets all optionsoptions;
Inject values
Sets multiple values to the options even if some of the options were not registered yet. It is useful when you need to set all options before any other action in your script.
// injects new values to the optionslet values = name: "Jane" age: 26 vegetarian: true car: name: "Fiat 500" color: "blue" ; options; // you can register "vegetarian" even later after value injectionoptions;
Alias
options;options; // set and get value by aliasoptions;options; options; // aliases are supported for value injection toooptions;options; let values = name: "Jane" zipCode: 23301; options;
Check for option existence
options; // trueoptions; // trueoptions; // false