1.0.0 • Published 6 years ago

expect-match v1.0.0

Weekly downloads
1
License
BSD-3-Clause
Repository
github
Last release
6 years ago

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).

1.0.0

6 years ago