README
ToC
Sections |
---|
Semantic Versioning |
Installation |
Usage |
Semantic Versioning
- If you're not familiar with semantic versioning; or, just need some brushing up, head on over to http://semver.org/.
Installation
Using command line:
Navigate to your project's root.
Type the following command:
$ npm i --save utility-tool
- Include the module in each script used.
const utilityTool = require('utility-tool');
Usage
debug(msg = null, obj = null, errLevel = 1, httpCode = null)
Important
- When starting your application from command line, you must include the argument:
DEBUG=true
Example Usage:
$ DEBUG=true npm start
Description
- Displays robust debug messages in terminal.
Code Examples
Display an Error Message:
utilityTool.debug('there was an error');
Example Result:
Thurs 8:29:15 AMthere was an errorDisplay a Success Message:
utilityTool.debug('there was not an error', null, 0);
Example Result:
Thurs 8:30:54 AMthere was not an error
Parameters
msg - String, default null
- A message to print to the console.
obj - Object, default null
An object to print to the console.
Is converted to JSON.
errLevel - Integer, default 1
- If errLevel is not a truthy value, msg will have a green background, else it will have a red background.
httpCode - Integer, default null
- Will append the httpCode to msg.
isNumber(n, failure, success)
Description
- Tests to see if a variable is a number.
Code Example
utilityTool.isNumber(5, (n) =>{ utilityTool.debug(`${n} is not a number`); }, (n) => { utilityTool.debug(`${n} is a number`); });
Parameters
n - required, Mixed
- The variable to test.
failure(n) - required, Function
n will be the value that was tested.
What to do if n is not a number.
success(n) - required, Function
n will be the value that was tested.
What to do if n is a number.