0.2.1 • Published 3 months ago

@stdlib/error-tools-msg2id v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

msg2id

NPM version Build Status Coverage Status

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


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

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2024. The Stdlib Authors.