UNPKG

@davidosborn/crypto-tax-calculator

Version:

A tool to calculate the capital gains of cryptocurrency assets for Canadian taxes

44 lines (36 loc) 1.18 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _stream = _interopRequireDefault(require("stream")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * A stream that filters the trades by their assets. */ class TradeFilterStream extends _stream.default.Transform { /** * Initializes a new instance. * @param {object} [options] The options. * @param {Set.<string>} [options.assets] The assets to retain. */ constructor(options) { super({ objectMode: true }); this._options = options; } /** * Filters a trade by its assets. * @param {Trade} chunk The trade. * @param {string} encoding The encoding type (always 'Buffer'). * @param {function} callback A callback for when the transformation is complete. */ async _transform(chunk, encoding, callback) { if (!this._options.assets || this._options.assets.has(chunk.baseAsset) || this._options.assets.has(chunk.quoteAsset)) this.push(chunk); callback(); } } function _default(...args) { return new TradeFilterStream(...args); }