onia
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

onia

npm version types size coverage vulnerabilities License

small set of monadic parser combinators.

Installation

$ npm i onia

Usage

import onia, {regex, alpha, map, many, sequence, optional} from 'onia';

const digit = map(
    regex(/\d/g, 'digit'),
    (digit) => parseInt(digit),
    'digit'
);
const digits = map(
    many(digit),
    (digit) => parseInt(digit.join('')),
    'digits'
);
const whitespace = alpha(' ', 'whitespace');
const operator = regex(/[+-]/g, 'operator');
const expression = map(
    sequence([digits, optional(whitespace), operator, optional(whitespace), digits] as const),
    ([left, , operator, , right]) => [left, operator, right] as const,
    'expression'
);


const result = onia('123 + 321', term);
// result === [123, '+', 321]

Disclaimer

This project is still in early development and is subject to change.

Licence

MIT License, see LICENSE

Readme

Keywords

none

Package Sidebar

Install

npm i onia

Weekly Downloads

7

Version

0.2.0

License

MIT

Unpacked Size

16.5 kB

Total Files

15

Last publish

Collaborators

  • sovrin