forked from validatorjs/validator.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashing the many disparit commits into a single commit.
- Loading branch information
Daniel Guimaraes
committed
Jun 7, 2018
1 parent
0a9b52d
commit 2e6cc37
Showing
13 changed files
with
287 additions
and
19 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
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,47 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
|
||
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 _str$split = str.split('/'), | ||
_str$split2 = _slicedToArray(_str$split, 3), | ||
ip = _str$split2[0], | ||
subnet = _str$split2[1], | ||
err = _str$split2[2]; | ||
|
||
if (typeof err !== 'undefined') { | ||
return false; | ||
} | ||
|
||
if (!subnetMaybe.test(subnet)) { | ||
return false; | ||
} | ||
|
||
// Disallow preceding 0 i.e. 01, 02, ... | ||
if (subnet.length > 1 && subnet.startsWith('0')) { | ||
return false; | ||
} | ||
|
||
return (0, _isIP2.default)(ip) && subnet <= 32 && subnet >= 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
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 assertString from './util/assertString'; | ||
import isIP from './isIP'; | ||
|
||
const subnetMaybe = /^\d{1,2}$/; | ||
|
||
export default function isIPRange(str) { | ||
assertString(str); | ||
const [ip, subnet, err] = str.split('/'); | ||
|
||
if (typeof err !== 'undefined') { | ||
return false; | ||
} | ||
|
||
if (!subnetMaybe.test(subnet)) { | ||
return false; | ||
} | ||
|
||
// Disallow preceding 0 i.e. 01, 02, ... | ||
if (subnet.length > 1 && subnet.startsWith('0')) { | ||
return false; | ||
} | ||
|
||
return isIP(ip, 4) && subnet <= 32 && subnet >= 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
Oops, something went wrong.