-
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.
Merge pull request #22 from sTdobTs/dev
增加 ipv4 校验
- Loading branch information
Showing
14 changed files
with
388 additions
and
120 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
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,33 @@ | ||
|
||
## isIpv4(val) | ||
|
||
#### 描述: | ||
|
||
校验 `val` 是否为 ipv4 | ||
|
||
#### 参数: | ||
|
||
val,任意类型 | ||
|
||
#### 说明: | ||
|
||
若参数 `val` 是 ipv4, 则返回 true, 否则返回 false | ||
|
||
#### 示例: | ||
|
||
```javascript | ||
jxmValidator.ipv4('192.168.1.1'); // => true | ||
jxmValidator.ipv4('0.0.0.0'); // => true | ||
jxmValidator.ipv4('0.0.0.1'); // => true | ||
jxmValidator.ipv4('01.1.1.1'); // => true | ||
jxmValidator.ipv4('255.255.255.255'); // => true | ||
|
||
jxmValidator.ipv4('127.0.0.1'); // => true | ||
jxmValidator.ipv4('127.0.0'); // => false | ||
jxmValidator.ipv4('127.a.0.1'); // => false | ||
jxmValidator.ipv4('127..0.1'); // => false | ||
|
||
jxmValidator.ipv4('111.111.111.256'); // => false | ||
|
||
jxmValidator.ipv4(192); // => false | ||
``` |
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,33 @@ | ||
|
||
## isIpv4(val) | ||
|
||
#### 描述: | ||
|
||
校验 `val` 是否为 ipv4 | ||
|
||
#### 参数: | ||
|
||
val,任意类型 | ||
|
||
#### 说明: | ||
|
||
若参数 `val` 是 ipv4, 则返回 true, 否则返回 false | ||
|
||
#### 示例: | ||
|
||
```javascript | ||
jxmValidator.ipv4('192.168.1.1'); // => true | ||
jxmValidator.ipv4('0.0.0.0'); // => true | ||
jxmValidator.ipv4('0.0.0.1'); // => true | ||
jxmValidator.ipv4('01.1.1.1'); // => true | ||
jxmValidator.ipv4('255.255.255.255'); // => true | ||
|
||
jxmValidator.ipv4('127.0.0.1'); // => true | ||
jxmValidator.ipv4('127.0.0'); // => false | ||
jxmValidator.ipv4('127.a.0.1'); // => false | ||
jxmValidator.ipv4('127..0.1'); // => false | ||
|
||
jxmValidator.ipv4('111.111.111.256'); // => false | ||
|
||
jxmValidator.ipv4(192); // => false | ||
``` |
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,23 @@ | ||
|
||
var _isString = require('./isString'); | ||
var REGEX_ENUM = require('./internal/enum/regexEnum'); | ||
|
||
/** | ||
* 校验参数 `val` 是否为 ipv4 | ||
* | ||
* 若参数 `val` 是 ipv4, 则返回 true, 否则返回 false | ||
* | ||
* @param {*} val 待校验的参数 | ||
* @return {Boolean} 返回校验结果 | ||
* @version 0.0.6 | ||
* @since 0.0.6 | ||
*/ | ||
function _isIpv4(val) { | ||
if (!_isString(val)) { | ||
return false; | ||
} | ||
|
||
return REGEX_ENUM.IPV4_REX.test(val); | ||
} | ||
|
||
module.exports = _isIpv4; |
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,65 @@ | ||
|
||
const isIpv4 = require('../src/isIpv4'); | ||
const chai = require('chai'); | ||
const should = chai.should; | ||
|
||
chai.use(require('chai-things')); | ||
should(); | ||
|
||
// Test | ||
describe('isIpv4 test', function() { | ||
// '192.168.1.1' | ||
it(`isIpv4('192.168.1.1') === true`, function() { | ||
isIpv4('192.168.1.1').should.equal(true); | ||
}); | ||
|
||
// '0.0.0.0' | ||
it(`isIpv4('0.0.0.0') === true`, function() { | ||
isIpv4('0.0.0.0').should.equal(true); | ||
}); | ||
|
||
// '0.0.0.1' | ||
it(`isIpv4('0.0.0.1') === true`, function() { | ||
isIpv4('0.0.0.1').should.equal(true); | ||
}); | ||
|
||
// '01.1.1.1' | ||
it(`isIpv4('01.1.1.1') === true`, function() { | ||
isIpv4('01.1.1.1').should.equal(true); | ||
}); | ||
|
||
// '255.255.255.255' | ||
it(`isIpv4('255.255.255.255') === true`, function() { | ||
isIpv4('255.255.255.255').should.equal(true); | ||
}); | ||
|
||
// '127.0.0.1' | ||
it(`isIpv4('127.0.0.1') === true`, function() { | ||
isIpv4('127.0.0.1').should.equal(true); | ||
}); | ||
|
||
// '127.0.0' | ||
it(`isIpv4('127.0.0') === false`, function() { | ||
isIpv4('127.0.0').should.equal(false); | ||
}); | ||
|
||
// '127.a.0.1' | ||
it(`isIpv4('127.a.0.1') === false`, function() { | ||
isIpv4('127.a.0.1').should.equal(false); | ||
}); | ||
|
||
// '127..0.1' | ||
it(`isIpv4('127..0.1') === false`, function() { | ||
isIpv4('127..0.1').should.equal(false); | ||
}); | ||
|
||
// '111.111.111.256' | ||
it(`isIpv4('111.111.111.256') === false`, function() { | ||
isIpv4('111.111.111.256').should.equal(false); | ||
}); | ||
|
||
// 192 | ||
it(`isIpv4(192) === false`, function() { | ||
isIpv4(192).should.equal(false); | ||
}); | ||
}); |
Oops, something went wrong.