Package Exports
- @stdlib/error-tools-msg2id
- @stdlib/error-tools-msg2id/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stdlib/error-tools-msg2id) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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 ) );
}
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-2023. The Stdlib Authors.