https://github.com/yash-singh1/randomgen-parser
RandomGen syntax parser
https://github.com/yash-singh1/randomgen-parser
Last synced: 2 months ago
JSON representation
RandomGen syntax parser
- Host: GitHub
- URL: https://github.com/yash-singh1/randomgen-parser
- Owner: Yash-Singh1
- License: mit
- Created: 2021-02-27T23:23:45.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-13T13:08:34.000Z (over 1 year ago)
- Last Synced: 2025-03-18T12:55:43.481Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 113 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `randomgen-parser`
Parses [RandomGen](http://orteil.dashnet.org/randomgen/).
## Installation
```sh
npm install randomgen-parser
```## API
### Importing
```js
const RandomGenParser = require('randomgen-parser');
```### Using
The `randomgen-parser` module exports a class. The constructor accepts two arguments. The first one is the string to parse. The second one is optional and is the string to parse. The results of the parsing will be stored at the `parsed` property of the object. Here are some more functions:
```js
const RandomGenParser = require('randomgen-parser');new RandomGenParser('').parsed;
// -> [ { type: "newline", raw: "", stringValue: "", interpretedValue: "", pos: { line: 1, column: 0 }, afterLinebreak: null } ]let parser = new RandomGenParser('$hello world\na\nb\nc\n');
parser.setString('$hello world\na\nb\nc\nd\n');
parser.reparse();
```Here is the format of the config:
```json5
{
linebreaks: String
}
```For more information on the functions given and the types, look at the [types](index.d.ts).
### Extending
The `randomgen-parser` module allows to extend and create plugins for it. An example plugin that would use `#` instead of `//` for line comments is:
```js
module.exports = {
lineCommentStart: '#',
lineCommentValueReg: /^[\s\uFEFF\xA0]*#(.*)$/
};
```The exported object must contain properties that are intended to be edited of the class.
## Development
Run the following to convert typescript to javascript:
```sh
npm run build
```