Environment value parser module
- Source:
Methods
(static) boolean(val) → {boolean}
Convert a value to a boolean
Parameters:
Name | Type | Description |
---|---|---|
val |
* | value to convert |
- Source:
Returns:
true if val equals "true"
- Type
- boolean
Example
parser.boolean('true') // true
parser.boolean('false') // false
parser.boolean('123') // false
(static) buffer(val) → {Buffer}
Convert a value to a Buffer
Parameters:
Name | Type | Description |
---|---|---|
val |
* | value to convert |
- Source:
Returns:
value as Buffer
- Type
- Buffer
Example
parser.buffer('_ag3WU77') // new Buffer('_ag3WU77')
(static) buffer64(val) → {Buffer}
Convert a value to a base64 Buffer
Parameters:
Name | Type | Description |
---|---|---|
val |
* | value to convert |
- Source:
Returns:
value as Buffer
- Type
- Buffer
Example
parser.buffer64('DjiZ7AWTeNh38zoQiZ76gw==') // new Buffer('DjiZ7AWTeNh38zoQiZ76gw==', 'base64')
(static) float(def) → {function}
Create a function that calls `parseFloat()` and handles `NaN` by returning a given default value.
Parameters:
Name | Type | Description |
---|---|---|
def |
number | default value in case of non number |
- Source:
Returns:
function to convert a value to a number
- Type
- function
Example
parser.float(200)('4.2') // 4.2
parser.float(1.3)('wasd') // 1.3
(static) int(def) → {function}
Create a function that calls `parseInt(_, 10)` and handles `NaN` by returning a given default value.
Parameters:
Name | Type | Description |
---|---|---|
def |
number | default value in case of non number |
- Source:
Returns:
function to convert a value to a number
- Type
- function
Example
parser.int(200)('100') // 100
parser.int(42)('wasd') // 42
(static) objectInt(field, def) → {function}
Parameters:
Name | Type | Description |
---|---|---|
field |
String | Object field to parse |
def |
number | Default value in case of NaN |
- Source:
Returns:
Function to convert an object to a number
- Type
- function
Example
parser.objectInt('width', 200)({height: 100}); //200
parser.objectInt('height', 200)({height: 100}); //100