Check object key
Standardized way to check an objects key, setting defaults, timing out etc.
Installation
npm i check-object-key
Usage
Load up library like so:
'use strict'; const checkKey = ;
Basic usage, check if if key exists
const obj = 'foo': 'bar'; ;
Basic usage, set default value if key does not exist
const obj = {}; ;
Basic usage, check key against list ov validValues
const obj = 'foo': 'nein'; ;
Works async as well
const obj = {}; ; ;
Full documentation on parameters
options.obj: object - Object to have its keys checked
options.objectKey: string - object key name
options.default: any - The default value if it does not exist
options.defaultLabel: string - What to print in the log as the default value (will default to "default" if it is a string)
options.retries: integer - used internally. Set to 10+ to have the method immediately set the default value or fail if the key does not exist