banker
Version:
Downloads transactions and balances from online banking websites using Zombie.js.
49 lines (42 loc) • 1.27 kB
JavaScript
var BigNumber = require('bignumber.js'),
events = require('events'),
Lazy = require('lazy');
exports.readLines = function(stream, cb, done) {
var data = null;
if (typeof stream == 'string' || Buffer.isBuffer(stream)) {
data = stream;
stream = new events.EventEmitter();
}
Lazy(stream)
.lines
.map(function(line) {
line = String(line).replace(/\r$/, '');
cb(null, line);
})
.join(function() {
if (typeof done == 'function') {
done(null);
}
});
if (data) {
stream.emit('data', data);
stream.emit('end');
}
};
BigNumber.prototype.toJSON = function() {
return this.toString();
};
exports.decimal = function(num) {
if (typeof num == 'undefined' || num === null) {
return null;
}
num = num.replace(/[\s$,]/g, '');
if (/^\(.*\)$/.test(num)) {
// BigNumber doesn't like negative numbers formatted like (1.25)
num = '-' + num.substring(1, num.length - 1);
} else if (/-$/.test(num)) {
// BigNumber doesn't like negative numbers formatted like 1.25-
num = '-' + num.substring(0, num.length - 1);
}
return BigNumber(num);
};