Make composable text matchers.
yarn add tamcher --save
import { mm } from 'tamcher';
let mNumber = mm.mr(/^(\d*)(.*)/s, 'number'); // returns a matcher
mNumber('333') // returns { number: '333' }
See esra for an example use of this library, that parses chess PGN files.
import { mm } from 'tamcher';
mm.mr(/regex/, matcherType)
Match a regex
Regex Format Regex has to match the rest of the string at the end, so it has to be in this format: /^Extra(YourCapturingGroup)Extra(.*)/s
mm.mseq3([matcher, matcher, matcher], reducer)
Match three matchers in sequence:
reducer
is a Reducer that defines how to combine the three matchers.
mm.mstar(matcher)
Match a matcher greedily
mm.mgroup(matcher, mm.oneMatcherNode(matcherType))
Group a matcher into an object
See matchmaker.ts for all matchers.
You can make a reducer for selecting matchers like this: _ => _[0]
.
import { rr } from 'tamcher';
rr.fFirstTwo(matcherType)
Array of first two matchers wrapped to an object with key matcherType
.
rr.fLastTwo(matcherType)
rr.fAll(matcherType)
Array all matchers
See reducers.ts for all reducers.