-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.hbs
51 lines (38 loc) · 1.2 KB
/
README.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!--
Copyright (c) 2020 Chris Watson
This software is released under the MIT License.
https://opensource.org/licenses/MIT
-->
# StringScan.js
[![view on npm](http://img.shields.io/npm/v/stringscan.svg)](https://www.npmjs.org/package/stringscan)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)
JavaScript implementation of Ruby/Crystal's StringScanner. Useful for writing tokenizers.
## Examples
```javascript
const StringScanner = require('stringscan')
const s = new StringScanner('This is an example string')
s.scan(/\w+/) // "This"
s.scan(/\w+/) // null
s.scan(/\s+/) // " "
s.scan(/\s+/) // null
s.scan(/\w+/) // "is"
s.eos() // false
s.scan(/\s+/) // " "
s.scan(/\w+/) // "an"
s.scan(/\s+/) // " "
s.scan(/\w+/) // "example"
s.scan(/\s+/) // " "
s.scan(/\w+/) // "string"
s.eos() // true
s.scan(/\s+/) // null
s.scan(/\w+/) // null
```
For more examples see the [examples](https://github.com/watzon/stringscan.js/tree/master/examples) directory.
## API Reference
{{#module name="stringscan"}}
{{>body~}}
{{>separator~}}
{{>members~}}
{{/module}}
* * *
© 2020 Chris Watson. Licensed under the MIT License. All rights reserved.