just.defaults(value, defaultValueopt, opts) → {value}
Defaults to defaultValue if value looks like defaultValue.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Any | Any value. | ||||||||||||||||||||
defaultValue [optional] | Any | A value with a desired type for value. If an object literal is given, all the keys of value will default to his corresponding key in this object. | ||||||||||||||||||||
opts | object | Some options.Properties
|
Returns:
value if it looks like defaultValue or defaultValue otherwise.
- Type
- value
Examples
just.defaults([1, 2], {a: 1}); // {a: 1}
just.defaults({}, null); // null: null is not an object literal.
just.defaults([], null, {'checkLooks': false}); // []: null is an object.
just.defaults(null, {}); // {}: null is not an object literal.
just.defaults(null, []); // []: null is not an Array.
just.defaults(1, NaN); // 1 (NaN is an instance of a Number)
just.defaults({'a': 1, 'b': 2}, {'a': 'some string'}, {'ignoreDefaultKeys': false}); // {'a': 'some string', 'b': 2}
just.defaults({'a': 1}, {'b': 2}, {'ignoreDefaultKeys': false}); // {'a': 1, 'b': 2}
just.defaults({'a': 1}, {'b': 2}, {'ignoreDefaultKeys': true}); // {'a': 1}
just.defaults(1, null, {'ignoreNull': false}) // null (1 is not an object)
just.defaults(1, null, {'ignoreNull': true}) // 1
just.defaults(undefined, null, {'ignoreNull': true}) // null
just.defaults({a: 1}, {a: null}, {'ignoreNull': true}) // {a: 1}