Class: Opts

@lumjs/core/opt.Opts(…sources)

A class for handling options with multiple sources.

Constructor

new Opts(…sources)

Build an Opts instance.

Parameters:
Name Type Attributes Description
sources object <repeatable>

Initial sources of options.

The order of sources matters, as the ones added later will override the ones added earlier. Keep that in mind when adding sources.

Source:

Methods

_err(msg, info, errClassopt) → {object}

Handle an error

Parameters:
Name Type Attributes Default Description
msg string

A summary of the error.

info object

Debugging information for the logs.

errClass function <optional>
TypeError

Constructor for an Error class. Used if fatal errors are enabled.

Source:
Throws:

An error of errClass class, if fatal mode is enabled.

Type
Error
Returns:

this

Type
object

add(…sources) → {object}

Add new sources of options.

Parameters:
Name Type Attributes Description
sources object | string <repeatable>

Sources and positions.

If this is an object then it's a source of options to add. This is the most common way of using this.

If this is a string then it's assumed to be nested property of the current from() source, and if that property exists and is an object, it will be used as the source to add. If it does not exist, then the behaviour will depend on the values of the strict() and fatal() modifiers.

Source:
Returns:

this

Type
object

at(pos) → {object}

Set the position/offset to add new sources at.

This will affect subsequent calls to the add() method.

Parameters:
Name Type Description
pos number

The position/offset value.

  • A value of -1 uses Array#push(src)); end of array.
  • A value of 0 uses Array#unshift(src); start of array.
  • Any value > 0 uses Array#splice(pos, 0, src); offset from start.
  • Any value < -1 uses Array#splice(pos+1, 0, src); offset from end.

The default value if none is specified is -1.

Source:
Throws:

An invalid value was passed while fatal was true.

Type
TypeError
Returns:

this

Type
object

clear() → {object}

Remove all current sources. Resets compiled options data.

Source:
Returns:

this

Type
object

fatal(val) → {object}

Set the fatal error handling setting.

Default is false, so errors will be logged, but not thrown.

Parameters:
Name Type Description
val boolean

Should errors be fatal?

Source:
Returns:

this

Type
object

from(source) → {object}

Set the object to look for nested properties in.

This will affect subsequent calls to the add() method.

Parameters:
Name Type Description
source object | number | boolean

Source definition

  • If this is an object it will be used as the object directly.
  • If this is a number it is the position of one of our data sources. Negative numbers count from the end of the list of sources.
  • If this is true then the compiled options data at the time of the call to this method will be used.
  • If this is false then the next time a string value is passed to add() the options will be compiled on demand, and that object will be used until the next call to from().

If this is not specified, then it defaults to false.

Source:
Throws:

An invalid value was passed while fatal was true.

Type
TypeError
Returns:

this

Type
object

get(opt, argsopt) → {*}

Get an option value from our compiled data sources.

This uses the get() function, but instead of using positional arguments, it supports an object of named options instead.

Parameters:
Name Type Attributes Description
opt string

The name of the option to get.

args object <optional>

Optional arguments for get().

Properties
Name Type Attributes Default Description
default * <optional>

defvalue argument.

null boolean <optional>
true

allowNull argument.

lazy boolean <optional>
false

isLazy argument.

lazyThis object | function <optional>

lazyThis argument. If this is defined, args.lazy will be set to true.

lazyArgs Array <optional>

lazyArgs argument. If this is defined, args.lazy will be set to true.

Source:
Returns:

The output of the get() function.

Type
*

remove(…sources) → {object}

Remove existing sources of options.

Parameters:
Name Type Attributes Description
sources object <repeatable>

Sources to remove.

Source:
Returns:

this

Type
object

strict(val) → {object}

Set the strict property check setting.

Default is false, we don't care about non-existent properties.

Parameters:
Name Type Description
val boolean

Should non-existant properties be an error?

Source:
Returns:

this

Type
object