Skip to content

string

Tries to match a given string.

Available since: v1.0.0-alpha.1

Type declaration

const string: (searchString: string, name?: string) => Parser;

Example

In this example we are going to parse two arbitrary words separated by a space.

import { sequenceOf, whitespace, word } from "rudus";
const parser = sequenceOf([whitespace(), word(), whitespace()]);
const result = parser.run(`\nHello\n`);

The result of the parser above will be:

{
"input": "\nHello World\n",
"isError": false,
"offset": 7,
"result": ["\n", "Hello", "\n"]
}