VDL Plugin SDK

getOptionBool

Import from @varavel/vdl-plugin-sdk/utils/options.

function getOptionBool(
   options, 
   key, 
   defaultValue
): boolean;

Returns a boolean option using common truthy and falsy string values.

Accepted truthy values: true, 1, yes, on, enable, enabled, y.

Accepted falsy values: false, 0, no, off, disable, disabled, n.

Invalid values fall back to the provided default.

Parameters

ParameterTypeDescription
optionsRecord<string, string> | undefinedPlugin options record.
keystringOption name to read.
defaultValuebooleanValue returned when the option is missing or invalid.

Returns

boolean

The parsed boolean value, or the default when parsing fails.

Example

getOptionBool({ watch: "yes" }, "watch", false);
// returns true