|
1 | | -#JavaScript |
2 | | -JavaScript implementation of SRL. |
| 1 | +#SRL-JavaScript |
| 2 | + |
| 3 | +JavaScript implementation of[Simple Regex](https://simple-regex.com/):tada::tada::tada: |
| 4 | + |
| 5 | +[](https://badge.fury.io/js/srl) |
| 6 | +[](https://travis-ci.org/SimpleRegex/SRL-JavaScript) |
| 7 | +[](https://codecov.io/gh/SimpleRegex/SRL-JavaScript) |
| 8 | + |
| 9 | +>Because of the JavaScript regex engine, there is something different from[Simple Regex](https://simple-regex.com/) |
| 10 | +- NOT support`as` to assign capture name. |
| 11 | +- NOT support`if already had/if not already had` |
| 12 | +- NO`firstMatch`, since in JavaScript`lazy` means non-greedy (matching the fewest possible characters). |
| 13 | + |
| 14 | +##Installation |
| 15 | + |
| 16 | +```sh |
| 17 | +npm install srl |
| 18 | +``` |
| 19 | + |
| 20 | +##Usage |
| 21 | + |
| 22 | +Class SRL accepts a Simple Regex Language string as input, and return the builder for the query. |
| 23 | + |
| 24 | +The builder can agent`test/exec` method to the generated regex object. Or you can use`get()` to take the generated regex object. |
| 25 | + |
| 26 | +```js |
| 27 | +constSRL=require('srl') |
| 28 | +constquery=newSRL('letter exactly 3 times') |
| 29 | +constregex=query.get()// /[a-z]{3}/ |
| 30 | + |
| 31 | +query.test('aaa')// true |
| 32 | +query.exec('aaa')// [ 'aaa', index: 0, input: 'aaa' ] |
| 33 | + |
| 34 | +query |
| 35 | + .digit() |
| 36 | + .neverOrMore() |
| 37 | + .mustEnd() |
| 38 | + .get()// /[a-z]{3}[0-9]*$/ |
| 39 | +``` |
| 40 | + |
| 41 | +Required Node 6.0+ for the ES6 support, Or you can use[Babel](http://babeljs.io/) to support Node below 6.0. |
| 42 | + |
| 43 | +Using[Webpack](http://webpack.github.io) and[babel-loader](https://github.com/babel/babel-loader) to pack it if want to use in browsers. |
| 44 | + |
| 45 | +##Development |
| 46 | + |
| 47 | +First, clone repo and init submodule for test. |
| 48 | + |
| 49 | +SRL-JavaScript depends on[Mocha](http://mochajs.org) and[Istanbul](https://github.com/gotwarlost/istanbul) to test code. You can use them like this: |
| 50 | + |
| 51 | +```sh |
| 52 | +npm install |
| 53 | + |
| 54 | +npmtest# test |
| 55 | +npm run coverage# Get coverage locally |
| 56 | +``` |
| 57 | + |
| 58 | +How to write Rules, see:[Test-Rules](https://github.com/SimpleRegex/Test-Rules). |
| 59 | + |
| 60 | +##License |
| 61 | + |
| 62 | +SRL-JavaScript is published under the MIT license. See LICENSE for more information. |