-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #842 from excelciordan/master
Add isIPRange validator
- Loading branch information
Showing
9 changed files
with
123 additions
and
2 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
node_modules | ||
coverage | ||
package-lock.json | ||
yarn.lock | ||
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 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,40 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = isIPRange; | ||
|
||
var _assertString = require('./util/assertString'); | ||
|
||
var _assertString2 = _interopRequireDefault(_assertString); | ||
|
||
var _isIP = require('./isIP'); | ||
|
||
var _isIP2 = _interopRequireDefault(_isIP); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var subnetMaybe = /^\d{1,2}$/; | ||
|
||
function isIPRange(str) { | ||
(0, _assertString2.default)(str); | ||
var parts = str.split('/'); | ||
|
||
// parts[0] -> ip, parts[1] -> subnet | ||
if (parts.length !== 2) { | ||
return false; | ||
} | ||
|
||
if (!subnetMaybe.test(parts[1])) { | ||
return false; | ||
} | ||
|
||
// Disallow preceding 0 i.e. 01, 02, ... | ||
if (parts[1].length > 1 && parts[1].startsWith('0')) { | ||
return false; | ||
} | ||
|
||
return (0, _isIP2.default)(parts[0], 4) && parts[1] <= 32 && parts[1] >= 0; | ||
} | ||
module.exports = exports['default']; |
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,25 @@ | ||
import assertString from './util/assertString'; | ||
import isIP from './isIP'; | ||
|
||
const subnetMaybe = /^\d{1,2}$/; | ||
|
||
export default function isIPRange(str) { | ||
assertString(str); | ||
const parts = str.split('/'); | ||
|
||
// parts[0] -> ip, parts[1] -> subnet | ||
if (parts.length !== 2) { | ||
return false; | ||
} | ||
|
||
if (!subnetMaybe.test(parts[1])) { | ||
return false; | ||
} | ||
|
||
// Disallow preceding 0 i.e. 01, 02, ... | ||
if (parts[1].length > 1 && parts[1].startsWith('0')) { | ||
return false; | ||
} | ||
|
||
return isIP(parts[0], 4) && parts[1] <= 32 && parts[1] >= 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
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
Large diffs are not rendered by default.
Oops, something went wrong.