├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE-MIT.txt ├── README.md ├── cli.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = tab 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [{README.md,package.json,.travis.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Installed npm modules 2 | node_modules 3 | 4 | # Folder view configuration files 5 | .DS_Store 6 | Desktop.ini 7 | 8 | # Thumbnail cache files 9 | ._* 10 | Thumbs.db 11 | 12 | # Files that might appear on external disks 13 | .Spotlight-V100 14 | .Trashes 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4" 4 | - "5" 5 | -------------------------------------------------------------------------------- /LICENSE-MIT.txt: -------------------------------------------------------------------------------- 1 | Copyright Mathias Bynens 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # regex-trie-cli [![Build status](https://travis-ci.org/mathiasbynens/regex-trie-cli.svg?branch=master)](https://travis-ci.org/mathiasbynens/regex-trie-cli) 2 | 3 | regex-trie-cli is a command-line interface for [regex-trie](https://github.com/alexeld/regex-trie). Easily create regular expression patterns based on a list of strings to match from the command line! 4 | 5 | ## Installation 6 | 7 | ```bash 8 | $ npm install -g regex-trie-cli 9 | ``` 10 | 11 | ## Usage 12 | 13 | ``` 14 | $ regex-trie --help 15 | 16 | Usage 17 | $ regex-trie string1 string2 string3 … 18 | 19 | Examples 20 | $ regex-trie foo bar baz qux quux corge grault 21 | (?:foo|ba[rz]|qu(?:x|ux)|corge|grault) 22 | ``` 23 | 24 | ## Author 25 | 26 | | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") | 27 | |---| 28 | | [Mathias Bynens](https://mathiasbynens.be/) | 29 | 30 | ## License 31 | 32 | _regex-trie-cli_ is available under the [MIT](https://mths.be/mit) license. 33 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | const meow = require('meow'); 6 | const RegexTrie = require('regex-trie'); 7 | 8 | const cli = meow(` 9 | Usage 10 | $ regex-trie string1 string2 string3 … 11 | 12 | Examples 13 | $ regex-trie foo bar baz qux quux corge grault 14 | (?:foo|ba[rz]|qu(?:x|ux)|corge|grault) 15 | `); 16 | 17 | if (cli.input.length == 0) { 18 | console.error('Please supply some strings to be matched.'); 19 | process.exit(1); 20 | } 21 | 22 | const trie = new RegexTrie(); 23 | console.log( 24 | trie.add(cli.input).toString() 25 | ); 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "regex-trie-cli", 3 | "version": "1.0.0", 4 | "description": "Create regular expression patterns based on a list of strings to be matched.", 5 | "homepage": "https://github.com/mathiasbynens/regex-trie-cli", 6 | "bin": { 7 | "regex-trie": "cli.js" 8 | }, 9 | "engines": { 10 | "node": ">=4" 11 | }, 12 | "files": [ 13 | "LICENSE-MIT.txt", 14 | "cli.js" 15 | ], 16 | "keywords": [ 17 | "regex", 18 | "regexp", 19 | "trie" 20 | ], 21 | "license": "MIT", 22 | "author": { 23 | "name": "Mathias Bynens", 24 | "url": "https://mathiasbynens.be/" 25 | }, 26 | "repository": { 27 | "type": "git", 28 | "url": "https://github.com/mathiasbynens/regex-trie-cli.git" 29 | }, 30 | "bugs": "https://github.com/mathiasbynens/regex-trie-cli/issues", 31 | "dependencies": { 32 | "meow": "^3.7.0", 33 | "regex-trie": "^1.0.4" 34 | }, 35 | "devDependencies": { 36 | "ava": "*", 37 | "execa": "^0.2.2" 38 | }, 39 | "scripts": { 40 | "test": "ava" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import execa from 'execa'; 3 | 4 | test(async t => { 5 | t.is( 6 | (await execa('./cli.js', 'foo bar baz qux quux corge grault'.split(' '))).stdout, 7 | '(?:foo|ba[rz]|qu(?:x|ux)|corge|grault)' 8 | ); 9 | }); 10 | --------------------------------------------------------------------------------