UNPKG

plywood

Version:
52 lines (51 loc) 1.34 kB
var Ip = (function () { function Ip(parameters) { this.ip = parameters.ip; } Ip.isIp = function (candidate) { if (String(candidate).includes('/')) { candidate = candidate.split('/')[0]; } return (/^(\d+)\.(\d+?)\.(\d+?)\.(\d+?)$/.test(candidate) || /^([\da-zA-Z]+):([\da-zA-Z]+):([\da-zA-Z]+):([\da-zA-Z]+):*$/.test(candidate)); }; Ip.fromString = function (ipString) { return new Ip({ ip: ipString, }); }; Ip.fromJS = function (parameters) { if (typeof parameters !== 'object') { throw new Error('unrecognizable Ip'); } return new Ip({ ip: parameters.ip, }); }; Ip.prototype.toJSON = function () { return this.toJS(); }; Ip.prototype.equals = function (other) { return other instanceof Ip && other.ip === this.ip; }; Ip.prototype.valueOf = function () { return { type: Ip.type, ip: this.ip, }; }; Ip.prototype.toJS = function () { var js = { type: Ip.type, ip: this.ip, }; return js; }; Ip.prototype.toString = function () { return this.ip; }; Ip.type = 'IP'; return Ip; }()); export { Ip }; var check = Ip;