@sangaman/xud
Version:
Exchange Union Daemon
34 lines • 1.44 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
/** Helper methods for interacting with the [[Address]] type. */
const addressUtils = {
/**
* Create an [[Address]] using the remote host and port of a socket.
*/
fromSocket: (socket) => {
const { remoteAddress, remotePort } = socket;
assert_1.default(remoteAddress, 'socket must have a remoteAddress value');
assert_1.default(remotePort, 'socket must have a remotePort value');
return { host: remoteAddress, port: remotePort };
},
/**
* Create an [[Address]] from a string.
* @param addressString a string in the "{host}:{port}" format
* @param port a port number to use if no port is specified in the string, defaults to 8885
*/
fromString: (addressString, port = 8885) => {
const arr = addressString.split(':');
return {
host: arr[0],
port: arr[1] ? parseInt(arr[1], 10) : port,
};
},
/** Convert an [[Address]] to a string in the "{host}:{port}" format. */
toString: (address) => `${address.host}:${address.port}`,
};
exports.default = addressUtils;
//# sourceMappingURL=addressUtils.js.map