UNPKG

kucoin-universal-sdk

Version:
51 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubInfo = void 0; const EMPTY_ARGS_STR = "EMPTY_ARGS"; class SubInfo { constructor(prefix, args, callback) { this.prefix = prefix; this.args = args; this.callback = callback; } toId() { let argsStr; if (!this.args.length) { argsStr = EMPTY_ARGS_STR; } else { const sortedArgs = this.args.slice().sort(); argsStr = sortedArgs.join(","); } return `${this.prefix}@@${argsStr}`; } static fromId(id, callback = null) { const parts = id.split("@@"); if (parts.length !== 2) { throw new Error(`SubInfo.fromId: invalid id format: ${id}`); } const prefix = parts[0]; let args; if (parts[1] === EMPTY_ARGS_STR) { args = []; } else { args = parts[1].split(","); } return new SubInfo(prefix, args, callback); } topics() { if (!this.args.length) { return [this.prefix]; } return this.args.map(arg => `${this.prefix}:${arg}`); } subTopic() { if (!this.args.length) { return this.prefix; } return `${this.prefix}:${this.args.join(",")}`; } } exports.SubInfo = SubInfo; //# sourceMappingURL=sub.js.map