-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Showing
8 changed files
with
77 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import ipRegex from "ip-regex"; | ||
const defaultOpts = { 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])`; | ||
const v4exact = new RegExp(`^${v4str}$`); | ||
const v6exact = new RegExp(`^${v6str}$`); | ||
const v46exact = new RegExp(`(?:^${v4str}$)|(?:^${v6str}$)`); | ||
const cidrRegex = ({ exact } = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g"); | ||
const v4 = cidrRegex.v4 = ({ exact } = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g"); | ||
const v6 = cidrRegex.v6 = ({ exact } = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g"); | ||
export { | ||
cidrRegex as default, | ||
v4, | ||
v6 | ||
}; |
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,11 @@ | ||
import { v4 as v4$1, v6 as v6$1 } from "cidr-regex"; | ||
const re4 = v4$1({ exact: true }); | ||
const re6 = v6$1({ exact: true }); | ||
const isCidr = (str) => re4.test(str) ? 4 : re6.test(str) ? 6 : 0; | ||
const v4 = isCidr.v4 = (str) => re4.test(str); | ||
const v6 = isCidr.v6 = (str) => re6.test(str); | ||
export { | ||
isCidr as default, | ||
v4, | ||
v6 | ||
}; |
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
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