Comparing version 0.0.1 to 0.0.2
@@ -7,3 +7,3 @@ /* | ||
var proto = { | ||
version: '0.0.1', | ||
version: '0.0.2', | ||
Auto: function (ip, subnet, mask) { | ||
@@ -13,10 +13,8 @@ if (!ip || !subnet) { | ||
}; | ||
var sm = this.getMask(subnet,mask), | ||
subnet = sm[0], | ||
mask = sm[1]; | ||
if (mask && !isNaN(mask)) { | ||
if (this.isIPv4(ip) && this.isIPv4(subnet)) { | ||
return this.IPv4(ip,subnet,mask); | ||
} else if (this.isIPv6(ip) && this.isIPv6(subnet)) { | ||
return this.IPv6(ip,subnet,mask); | ||
var sm = this.getMask(subnet,mask); | ||
if (sm[0] && sm[1] && !isNaN(sm[1])) { | ||
if (this.isIPv4(ip)) { | ||
return this.__IPv4(ip,sm[0],sm[1]); | ||
} else { | ||
return this.__IPv6(ip,sm[0],sm[1]); | ||
}; | ||
@@ -27,5 +25,6 @@ }; | ||
IPv4: function (ip, subnet, mask) { | ||
var sm = this.getMask(subnet,mask), | ||
subnet = sm[0], | ||
mask = sm[1]; | ||
var sm = this.getMask(subnet,mask); | ||
return this.__IPv4(ip,sm[0],sm[1]); | ||
}, | ||
__IPv4: function (ip, subnet, mask) { | ||
if (this.isIPv4(ip) && this.isIPv4(subnet) && (mask && !isNaN(mask))) { | ||
@@ -40,5 +39,6 @@ return ((this.toInt(ip)&-1<<(32-mask)) == this.toInt(subnet)); | ||
IPv6: function (ip, subnet, mask) { | ||
var sm = this.getMask(subnet,mask), | ||
subnet = sm[0], | ||
mask = sm[1]; | ||
var sm = this.getMask(subnet,mask); | ||
return this.__IPv6(ip,sm[0],sm[1]); | ||
}, | ||
__IPv6: function (ip, subnet, mask) { | ||
if (this.isIPv6(ip) && this.isIPv6(subnet) && (mask && !isNaN(mask))) { | ||
@@ -56,3 +56,3 @@ var o = Array.apply(null,Array(Math.floor(mask/16))).map(function(_){ return 0xffff; }); | ||
isIPv6: function (ip) { | ||
return this.__isIPv6(this.expand(ip)); | ||
return !!(this.expand(ip)); | ||
}, | ||
@@ -107,7 +107,11 @@ __isIPv6: function (ip) { | ||
function Exporter (fn,plug) { | ||
if (typeof exports === 'undefined' && window) { | ||
window[plug] = fn(false); | ||
// This just seems silly... There HAS to be a better way! | ||
var isNode = (typeof process==='object' && process.toString()==='[object process]' && typeof exports!=='undefined'); | ||
// This also seems like there should be a better way... | ||
if (isNode) { | ||
module.exports = fn(isNode); | ||
} else { | ||
module.exports = fn(true); | ||
window[plug] = fn(isNode); | ||
}; | ||
}; |
{ | ||
"name": "insubnet", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "http://louist.github.io/inSubnet/", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -1,2 +0,2 @@ | ||
inSubnet (v0.0.1) | ||
inSubnet (v0.0.2) | ||
====== | ||
@@ -39,5 +39,5 @@ | ||
------ | ||
1) Figure out what should be in the TODO and then write it! (Done?) | ||
2) Write a better README! | ||
3) Write a simple HTTP example for CloudFlare. | ||
4) Everything else! | ||
- [x] Figure out what should be in the TODO and then write it! (Done!?) | ||
- [ ] Write a better README! | ||
- [x] Write a simple HTTP example for CloudFlare. (Look in ./examples/cloudflare.js) | ||
- [ ] Make "Exporter" better. |
20
test.js
@@ -26,2 +26,10 @@ var assert = require('assert'), | ||
try { | ||
assert(!inSubnet.Auto('192.168.255.32','2400:cb00::/32'),"192.168.255.32 should NOT be in 2400:cb00::/32."); | ||
pass++; | ||
} catch (e) { errors.push(e.message); }; | ||
try { | ||
assert(!inSubnet.Auto('2400:cb00::123','192.168.255.0/27'),"2400:cb00::123 should NOT be in 192.168.255.0/27."); | ||
pass++; | ||
} catch (e) { errors.push(e.message); }; | ||
try { | ||
assert(inSubnet.Auto('2400:cb00::123','2400:cb00::/32'),"2400:cb00::123 should be in 2400:cb00::/32."); | ||
@@ -34,2 +42,14 @@ pass++; | ||
} catch (e) { errors.push(e.message); }; | ||
try { | ||
assert(!inSubnet.Auto('Not an IP','2400:cb00::/32'),"This isn't even a valid IP!"); | ||
pass++; | ||
} catch (e) { errors.push(e.message); }; | ||
try { | ||
assert(!inSubnet.Auto('2400:cb00::123','Not a Subnet!'),"This isn't even a valid Subnet!"); | ||
pass++; | ||
} catch (e) { errors.push(e.message); }; | ||
try { | ||
assert(!inSubnet.Auto('Not an IP','Not a Subnet!/32'),"This isn't even a valid IP OR Subnet!"); | ||
pass++; | ||
} catch (e) { errors.push(e.message); }; | ||
console.log("[Subnet Validation] Number of errors found: "+errors.length+" - Tests passed: "+pass+" ("+((pass/(errors.length+pass)*100))+"%)"); | ||
@@ -36,0 +56,0 @@ errors.forEach(function(err) { console.log('\033[1;31mERROR:\033[0m '+err); }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17755
8
317
1