-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
10 changed files
with
88 additions
and
109 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
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,18 +1,15 @@ | ||
"use strict"; | ||
|
||
const ipRegex = require("ip-regex"); | ||
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])`; | ||
|
||
// can not precompile the non-exact regexes because global flag makes the regex object stateful | ||
// which would require the user to reset .lastIndex on subsequent calls | ||
// 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}$)`); | ||
|
||
module.exports = ({exact} = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g"); | ||
module.exports.v4 = ({exact} = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g"); | ||
module.exports.v6 = ({exact} = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g"); | ||
const cidrRegex = ({exact} = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g"); | ||
export const v4 = cidrRegex.v4 = ({exact} = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g"); | ||
export const v6 = cidrRegex.v6 = ({exact} = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g"); | ||
export default cidrRegex; |
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,42 +1,32 @@ | ||
{ | ||
"name": "cidr-regex", | ||
"version": "3.1.1", | ||
"version": "4.0.3", | ||
"description": "Regular expression for matching IP addresses in CIDR notation", | ||
"author": "silverwind <[email protected]>", | ||
"contributors": [ | ||
"Felipe Apostol <[email protected]> (http://flipjs.io/)" | ||
], | ||
"repository": "silverwind/cidr-regex", | ||
"license": "BSD-2-Clause", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"cidr", | ||
"regex", | ||
"notation", | ||
"cidr notation", | ||
"prefix", | ||
"prefixes", | ||
"ip", | ||
"ip address" | ||
], | ||
"dependencies": { | ||
"ip-regex": "^4.1.0" | ||
"ip-regex": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "7.8.1", | ||
"eslint-config-silverwind": "18.0.8", | ||
"jest": "26.4.2", | ||
"tsd": "0.13.1", | ||
"updates": "10.3.6", | ||
"versions": "8.4.3" | ||
"eslint": "8.37.0", | ||
"eslint-config-silverwind": "65.1.3", | ||
"tsd": "0.28.1", | ||
"updates": "13.2.9", | ||
"versions": "10.4.2", | ||
"vitest": "0.29.8" | ||
} | ||
} |
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,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) | ||
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
|
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,16 +1,19 @@ | ||
{ | ||
"name": "ip-regex", | ||
"version": "4.3.0", | ||
"version": "5.0.0", | ||
"description": "Regular expression for matching IP addresses (IPv4 & IPv6)", | ||
"license": "MIT", | ||
"repository": "sindresorhus/ip-regex", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "[email protected]", | ||
"url": "sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
|
@@ -37,8 +40,8 @@ | |
"validate" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.19.1", | ||
"xo": "^0.47.0" | ||
} | ||
} |
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,9 +1,9 @@ | ||
"use strict"; | ||
const {v4, v6} = require("cidr-regex"); | ||
import {v4 as v4Re, v6 as v6Re} from "cidr-regex"; | ||
|
||
const re4 = v4({exact: true}); | ||
const re6 = v6({exact: true}); | ||
const re4 = v4Re({exact: true}); | ||
const re6 = v6Re({exact: true}); | ||
|
||
module.exports = str => re4.test(str) ? 4 : (re6.test(str) ? 6 : 0); | ||
module.exports.v4 = str => re4.test(str); | ||
module.exports.v6 = str => re6.test(str); | ||
const isCidr = str => re4.test(str) ? 4 : (re6.test(str) ? 6 : 0); | ||
export const v4 = isCidr.v4 = str => re4.test(str); | ||
export const v6 = isCidr.v6 = str => re6.test(str); | ||
export default isCidr; |
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,46 +1,32 @@ | ||
{ | ||
"name": "is-cidr", | ||
"version": "4.0.2", | ||
"version": "5.0.3", | ||
"description": "Check if a string is an IP address in CIDR notation", | ||
"author": "silverwind <[email protected]>", | ||
"contributors": [ | ||
"Felipe Apostol <[email protected]> (http://flipjs.io/)" | ||
], | ||
"repository": "silverwind/is-cidr", | ||
"license": "BSD-2-Clause", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"cidr", | ||
"regex", | ||
"notation", | ||
"cidr notation", | ||
"prefix", | ||
"prefixes", | ||
"ip", | ||
"ip address", | ||
"network" | ||
], | ||
"dependencies": { | ||
"cidr-regex": "^3.1.1" | ||
"cidr-regex": "4.0.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "7.10.0", | ||
"eslint-config-silverwind": "18.0.10", | ||
"jest": "26.4.2", | ||
"updates": "11.1.5", | ||
"versions": "8.4.3" | ||
}, | ||
"jest": { | ||
"verbose": false, | ||
"testTimeout": 10000 | ||
"eslint": "8.37.0", | ||
"eslint-config-silverwind": "65.1.3", | ||
"tsd": "0.28.1", | ||
"updates": "13.2.9", | ||
"versions": "10.4.2", | ||
"vitest": "0.29.8" | ||
} | ||
} |
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