new Environment( [config])
Constructor.
This will define the following default properties, if not supplied on the
config argument:
- host
data.solarnetwork.net- protocol
https- port
443
These properties correspond to those on the window.location object when
running in a browser. Thus to construct an environment based on the location
of the current page you can create an instance like this:
const env = new Environment(window.location);
Extends:
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
config |
Object |
<optional> |
an optional set of properties to start with |
Extends
Methods
-
enabled(key)
-
Test if a key is truthy.
Parameters:
Name Type Description keystring the key to test
- Inherited From:
Returns:
trueif the key is enabled- Type
- boolean
-
toggle(key, enabled)
-
Set or toggle the enabled status of a given key.
If the
enabledparameter is not passed, then the enabled status will be toggled to its opposite value.Parameters:
Name Type Description keystring they key to set
enabledboolean the optional enabled value to set
- Inherited From:
Returns:
this object to allow method chaining
-
useTls()
-
Check if TLS is in use via the
httpsprotocol.Returns:
trueif theprotocolis set tohttps- Type
- boolean
-
value(key [, newValue])
-
Get or set a configuration value.
Parameters:
Name Type Argument Description keystring The key to get or set the value for
newValueobject <optional>
If defined, the new value to set for the given
key. Ifnullthen the value will be removed.- Inherited From:
Returns:
If called as a getter, the associated value for the given
key, otherwise this object.- Type
- object
-
values( [newMap])
-
Get or set multiple properties.
Parameters:
Name Type Argument Description newMapobject <optional>
a map of values to set
- Inherited From:
Returns:
if called as a getter, all properties of this object copied into a simple object; otherwise this object
- Type
- object