UNPKG

@spalger/kibana

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

33 lines (27 loc) 1.04 kB
define(function (require) { var Ipv4Address = require('ui/utils/Ipv4Address'); var NUM_BITS = 32; function throwError(mask) { throw Error('Invalid CIDR mask: ' + mask); } function CidrMask(mask) { var splits = mask.split('\/'); if (splits.length !== 2) throwError(mask); this.initialAddress = new Ipv4Address(splits[0]); this.prefixLength = Number(splits[1]); if (this.prefixLength < 1 || this.prefixLength > NUM_BITS) throwError(mask); } CidrMask.prototype.getRange = function () { var variableBits = NUM_BITS - this.prefixLength; var fromAddress = this.initialAddress.valueOf() >> variableBits << variableBits >>> 0; // >>> 0 coerces to unsigned var numAddresses = Math.pow(2, variableBits); return { from: new Ipv4Address(fromAddress).toString(), to: new Ipv4Address(fromAddress + numAddresses - 1).toString() }; }; CidrMask.prototype.toString = function () { return this.initialAddress.toString() + '/' + this.prefixLength; }; return CidrMask; });