-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
381e7b7
commit 77f7f60
Showing
15 changed files
with
3,028 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
root: true | ||
extends: silverwind | ||
extends: | ||
- silverwind | ||
- silverwind-typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
/.vscode | ||
/dist | ||
/node_modules | ||
/npm-debug.log* | ||
/yarn-error.log | ||
/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import ipRegex from "ip-regex"; | ||
|
||
type Options = { | ||
/** | ||
Only match an exact string. Useful with `RegExp#test()` to check if a string is an IP address. *(`false` matches any IP address in a string)* | ||
@default false | ||
*/ | ||
readonly exact?: boolean; | ||
} | ||
|
||
const defaultOpts: Options = {exact: false}; | ||
const v4str = `${ipRegex.v4().source}\\/(3[0-2]|[12]?[0-9])`; | ||
const v6str = `${ipRegex.v6().source}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`; | ||
|
||
// pre-compile only the exact regexes as global flag makes regex objects stateful | ||
const v4exact = new RegExp(`^${v4str}$`); | ||
const v6exact = new RegExp(`^${v6str}$`); | ||
const v46exact = new RegExp(`(?:^${v4str}$)|(?:^${v6str}$)`); | ||
|
||
const cidrRegex = ({exact}: Options = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g"); | ||
export const v4 = cidrRegex.v4 = ({exact}: Options = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g"); | ||
export const v6 = cidrRegex.v6 = ({exact}: Options = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g"); | ||
export default cidrRegex; |
Oops, something went wrong.