expect-match

1.0.0 • Public • Published

expect-match

A throwing variant of str.match. If the string matches the pattern, it acts just like the regular .match. Otherwise it turns this:

const [, a] = 'foo'.match(/^(\d+)$/);
// TypeError: Cannot read property 'Symbol(Symbol.iterator)' of "foo".match

Into this:

const expectMatch = require('expect-match');
const [, b] = expectMatch('foo', /^(\d+)$/);
// TypeError: String did not match pattern

For convenience it also exposes an error code (ENOMATCH).

Readme

Keywords

none

Package Sidebar

Install

npm i expect-match

Weekly Downloads

0

Version

1.0.0

License

BSD-3-Clause

Last publish

Collaborators

  • jkrems