8000 Merge branch 'feature/publish-to-npm' into develop · wimpyprogrammer/strings-to-regex@8adc16a · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8adc16a

Browse files
Merge branch 'feature/publish-to-npm' into develop
2 parents 9943332 + 89fccec commit 8adc16a

14 files changed

+116
-7114
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ end_of_line = lf
99
insert_final_newline = true
1010
indent_style = tab
1111

12-
[{package.json,yarn.lock}]
12+
[package.json]
1313
indent_style = space
1414
indent_size = 2

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/coverage/
22
/demo/lib/
3+
/demo/webpack.config.js
34
/lib/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package-lock.json
2+
13
coverage/
24
demo/lib/
35
lib/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.publishrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"validations": {
3+
"vulnerableDependencies": false,
4+
"uncommittedChanges": true,
5+
"untrackedFiles": true,
6+
"sensitiveData": true,
7+
"branch": "master",
8+
"gitTag": true
9+
},
10+
"confirm": true,
11+
"publishCommand": "npm publish",
12+
"publishTag": "latest",
13+
"prePublishScript": "npm run publish-please-prereqs",
14+
"postPublishScript": false
15+
}

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# strings-to-regex
2+
3+
[![npm package](https://badge.fury.io/js/strings-to-regex.svg)](https://badge.fury.io/js/strings-to-regex)
4+
![node version](https://img.shields.io/node/v/strings-to-regex.svg)
5+
![npm type definitions](https://img.shields.io/npm/types/strings-to-regex)
6+
[![Build Status](https://travis-ci.org/wimpyprogrammer/strings-to-regex.svg?branch=master)](https://travis-ci.org/wimpyprogrammer/strings-to-regex)
7+
[![codecov](https://codecov.io/gh/wimpyprogrammer/strings-to-regex/branch/master/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/strings-to-regex)
8+
[![Known Vulnerabilities](https://snyk.io/test/github/wimpyprogrammer/strings-to-regex/badge.svg)](https://snyk.io/test/github/wimpyprogrammer/strings-to-regex)
9+
10+
Generate a compact Regular Expression that matches a finite set.
11+
12+
Have you ever seen a dense Regular Expression like this one to match the 50 US state abbreviations?
13+
14+
```regexp
15+
/(A(L|K|Z|R)|C(A|O|T)|DE|FL|GA|HI|I(D|L|N|A)|K(S|Y)|LA|M(E|D|A|I|N|S|O|T)|N(E|V|H|J|M|Y|C|D)|O(H|K|R)|PA|RI|S(C|D)|T(N|X)|UT|V(T|A)|W(A|V|I|Y))/
16+
```
17+
18+
This library generates patterns like that to match a list of strings you provide.
19+
20+
_To reverse this process and list which strings a Regular Expression would match, try [`regex-to-strings`](https://www.npmjs.com/package/regex-to-strings)._
21+
22+
## <a href="https://www.wimpyprogrammer.com/strings-to-regex/">Demo</a>
23+
24+
## API
25+
26+
### `condense(arrayOfStrings)`
27+
28+
Generate a Regular Expression to match all strings in `arrayOfStrings`. Respects the casing of the strings. Returns a [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) object.
29+
30+
```js
31+
import { condense } from 'strings-to-regex';
32+
33+
const stringsToMatch = ['foo', 'foobar', 'Foo', 'fooBarBaz'];
34+
const matcher = condense(stringsToMatch);
35+
console.log(matcher); // /(foo(|bar|BarBaz)|Foo)/
36+
```
37+
38+
---
39+
40+
### `condenseIgnoreCase(arrayOfStrings)`
41+
42+
A variation of `condense()` that ignores the casing of the strings. Returns a [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) object.
43+
44+
```js
45+
import { condenseIgnoreCase } from 'strings-to-regex';
46+
47+
const stringsToMatch = ['foo', 'foobar', 'Foo', 'fooBarBaz'];
48+
const matcher = condenseIgnoreCase(stringsToMatch);
49+
console.log(matcher); // /foo(|bar(|baz))/i
50+
```

demo/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@
7272
/>
7373
</svg>
7474
</a>
75+
<a
76+
href="https://www.npmjs.com/package/strings-to-regex"
77+
title="See strings-to-regex on npm"
78+
>
79+
<img
80+
alt="See strings-to-regex on npm"
81+
src="https://badge.fury.io/js/strings-to-regex.svg"
82+
/>
83+
</a>
7584
</div>
7685
</nav>
7786

demo/src/demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function generatePattern(words: string): RegExp {
4141
return pattern;
4242
}
4343

44-
let clearSuccessIndicatorHandle: NodeJS.Timeout;
44+
let clearSuccessIndicatorHandle: number;
4545
function displayPattern(pattern: RegExp): void {
4646
$output.value = pattern.toString();
4747
$output.dispatchEvent(new Event('input'));
@@ -50,7 +50,7 @@ function displayPattern(pattern: RegExp): void {
5050
$output.classList.add('is-valid');
5151

5252
clearTimeout(clearSuccessIndicatorHandle);
53-
clearSuccessIndicatorHandle = setTimeout(
53+
clearSuccessIndicatorHandle = window.setTimeout(
5454
() => $output.classList.remove('is-valid'),
5555
1000
5656
);

demo/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
justify-content: inherit;
33
}
44

5+
.navbar > .container > * {
6+
margin-right: 1rem;
7+
}
8+
59
.navbar svg {
610
background-color: black;
711
border-radius: 50%;

demo/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
]
1111
},
1212
"extends": "../tsconfig.json",
13-
"include": ["../src", "./src", "./webpack.config.js"]
13+
"include": ["../src", "./src"]
1414
}

0 commit comments

Comments
 (0)
0