@stdlib/error-tools-msg2id
v0.2.2
Published
Return a two-character error identifier corresponding to a provided error message.
Downloads
4,058
Readme
msg2id
Return a two-character error identifier corresponding to a provided error message.
Installation
npm install @stdlib/error-tools-msg2id
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 ) );
}
See Also
@stdlib/error-tools-msg2id-cli
: CLI package for use as a command-line utility.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.