@davidosborn/crypto-tax-calculator
Version:
A tool to calculate the capital gains of cryptocurrency assets for Canadian taxes
44 lines (36 loc) • 1.14 kB
JavaScript
;
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 transactions.
*/
class TransactionFilterStream 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 transaction.
* @param {Transaction} chunk The transaction.
* @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.asset)) this.push(chunk);
callback();
}
}
function _default(...args) {
return new TransactionFilterStream(...args);
}