msg2id
Return a two-character error identifier corresponding to a provided error message.
Usage
var msg2id = require( '@stdlib/error/tools/msg2id' );
msg2id( msg )
Returns a two-character error identifier corresponding to a provided error message.
var v = msg2id( 'invalid value. `%s` must be a number. Value: `%s`.' );
// e.g., returns '6d'
If provided an unrecognized error message, the function returns null
.
var v = msg2id( 'beep boop baz' );
// returns null
Examples
var msg2id = require( '@stdlib/error/tools/msg2id' );
var list;
var v;
var i;
list = [
'invalid argument. First argument must be a number and not `NaN`. Value: `%s`.',
'invalid argument. First argument must be a positive integer. Value: `%s`.'
];
for ( i = 0; i < list.length; i++ ) {
v = list[ i ];
console.log( 'msg: "%s". id: "%s".', v, msg2id( v ) );
}
CLI
Usage
Usage: stdlib-msg2id [options] <msg>
Options:
-h, --help Print this message.
-V, --version Print the package version.
Examples
$ stdlib-msg2id 'invalid value. `%s` must be a number. Value: `%s`.'
6d