beater-matcher
Version:
A matcher library for beater.
87 lines (66 loc) • 1.61 kB
Markdown
A matcher library for [beater][bouzuya/beater].
[]: https://github.com/bouzuya/beater
```
$ npm install --save-dev beater-matcher
```
```javascript
import assert from 'assert';
import {
any,
anyArray,
anyNumber,
anyString,
anyObject,
match,
matchString,
partialObject,
} from 'beater-matcher';
const value = {
a: 123,
b: 'abc',
c: [1, 2, 3],
d: { a: 1, b: 2, c: 3 }
};
// (basic matchers)
// value as matcher
assert(match(value, value));
// (pre-defined matchers)
// any matcher
assert(match(value, any()));
// anyXXX matcher
assert(match(
value,
{
a: anyNumber(),
b: anyString(),
c: anyArray(),
d: anyObject()
}
));
// partialObject and matchString matcher
assert(match(value, partialObject({ b: matchString(/^ab/) })));
// (custom matcher)
const abcMatcher = defineMatcher(
(value: unknown): boolean => {
return typeof value === 'string' && value.startsWith('ABC');
}
);
assert(match('ABCDEF', abcMatcher));
```
[![npm version][npm-badge-url]][npm-url]
[![Travis CI][travis-ci-badge-url]][travis-ci-url]
[]: https://img.shields.io/npm/v/beater-matcher
[]: https://www.npmjs.com/package/beater-matcher
[]: https://img.shields.io/travis/bouzuya/beater-matcher
[]: https://travis-ci.org/bouzuya/beater-matcher
[](LICENSE)
[][user] <[m@bouzuya.net][email]> ([https://bouzuya.net/][url])
[]: https://github.com/bouzuya
[]: mailto:m@bouzuya.net
[]: https://bouzuya.net/