arginfo
Install
$ npm install arginfo
Usage
Calling arginfo(arg)
returns a string representation of arg
using node.js' util.inspect
. It prefixes the value with the type of the argument (whether it is a primitive type or a built-in object) such that the formatting is consistent across all built-in types:
arginfo(2);
arginfo({});
arginfo('?');
arginfo(true);
arginfo(/org/);
arginfo(new Set());
arginfo(new String(''));
arginfo(new Error('wtf'));
Example
var arginfo = require('arginfo');
function test(str) {
if('string' !== typeof str) {
console.error('test expects string. instead got: '+arginfo(str));
}
}
Settings
By default, arginfo will call util.inspect
with a depth
of null
. To limit the inspection depth of printing object properties, use arginfo.depth
. eg:
var arginfo = require('arginfo');
arginfo.depth(1);
arginfo({
a: {
b: {
c:'d'
}
}
});
Types
Primitive types:
- boolean
- number
- string
- object
- function
- symbol
Built-in objects:
- Boolean
- Number
- String
- Array
- Error
- RegExp
- Date
- Map
- Set
- WeakMap
- WeakSet
- Promise
- Generator
- DataView
- ArrayBuffer