Skip to content
A matcher library for beater.
TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.gitignore
.travis.yml
LICENSE
README.md
package-lock.json
package.json
tsconfig.json

README.md

beater-matcher

A matcher library for beater.

Installation

$ npm install --save-dev beater-matcher

Usage

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

Badges

npm version Travis CI

License

MIT

Author

bouzuya <m@bouzuya.net> (https://bouzuya.net/)

You can’t perform that action at this time.