mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-11 02:03:59 +08:00
The export-alias rewrite skipped a whole function when a let or const anywhere inside it declared the alias's name, so the function's other references to the alias kept the alias name after its declaration was removed. A function now shadows the alias only through its parameters, its own name, its vars and the declarations directly in its body; a block, case block, catch clause or for loop shadows it through its own declarations, and the walk skips just that scope.
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
var ip = exports;
|
|
|
|
ip.isPrivate = function(addr) {
|
|
return /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
|
/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr);
|
|
};
|
|
|
|
ip.isLoopback = function(addr) {
|
|
return /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(addr) ||
|
|
/^::1$/.test(addr);
|
|
};
|
|
|
|
ip.isPublic = function(addr) {
|
|
return !ip.isPrivate(addr) && !ip.isLoopback(addr);
|
|
};
|
|
|
|
ip.toLong = function(addr) {
|
|
var n = 0;
|
|
addr.split('.').forEach(function(octet) {
|
|
n <<= 8;
|
|
n += parseInt(octet, 10);
|
|
});
|
|
return n >>> 0;
|
|
};
|
|
|
|
ip.isV4Format = function(ip) {
|
|
return /^(\d{1,3}\.){3,3}\d{1,3}$/.test(ip);
|
|
};
|
|
|
|
ip.normalize = function(ip) {
|
|
var trimmed = ip.trim();
|
|
return trimmed.toLowerCase();
|
|
};
|
|
|
|
ip.classify = function(addr) {
|
|
if (addr.indexOf(':') !== -1) {
|
|
let ip = addr.toLowerCase();
|
|
return 'v6 ' + ip;
|
|
}
|
|
return ip.isPrivate(addr) ? 'private' : 'public';
|
|
};
|
|
|
|
ip.countPrivate = function(addrs) {
|
|
var n = 0;
|
|
for (const ip of addrs) if (/^10\./.test(ip)) n++;
|
|
return n + (ip.isLoopback(addrs[0]) ? 100 : 0);
|
|
};
|