ledger-cli
Advanced tools
Comparing version 0.0.3 to 0.0.4
/*global exports, require */ | ||
(function () { | ||
var csv = require('fast-csv'), | ||
var csv = require('csv'), | ||
Stream = require('stream').Stream; | ||
@@ -19,6 +19,6 @@ | ||
csv(process.stdout) | ||
.on('data', this.parse.bind(this)) | ||
.once('end', this.end.bind(this)) | ||
.parse(); | ||
csv() | ||
.from.stream(process.stdout) | ||
.on('record', this.parse.bind(this)) | ||
.once('end', this.end.bind(this)); | ||
@@ -30,6 +30,8 @@ process.stderr.on('data', this.error.bind(this)); | ||
Balance.prototype.parse = function(data) { | ||
Balance.prototype.parse = function(data, index) { | ||
try { | ||
var total = this.parseAmount(data[0].toString()); | ||
var obj = { | ||
total: data[0], | ||
total: total, | ||
account: { | ||
@@ -48,3 +50,15 @@ fullname: data[1], | ||
Balance.prototype.end = function() { | ||
// Parse an amount from a given string such as £-1,000.00 | ||
Balance.prototype.parseAmount = function(data) { | ||
var currency = data.match(/^.*[^\.,\-\s0-9]/)[0]; | ||
var amount = parseFloat(data.replace(currency, '').replace(',', '').trim()); | ||
return { | ||
currency: currency, | ||
amount: amount, | ||
formatted: data | ||
} | ||
}; | ||
Balance.prototype.end = function(count) { | ||
this.output.emit('end'); | ||
@@ -51,0 +65,0 @@ }; |
/*global exports, require */ | ||
(function () { | ||
var csv = require('fast-csv'), | ||
var csv = require('csv'), | ||
Stream = require('stream').Stream; | ||
@@ -34,6 +34,6 @@ | ||
csv(process.stdout) | ||
.on('data', this.parse.bind(this)) | ||
.once('end', this.end.bind(this)) | ||
.parse(); | ||
csv() | ||
.from.stream(process.stdout) | ||
.on('record', this.parse.bind(this)) | ||
.once('end', this.end.bind(this)); | ||
@@ -45,3 +45,3 @@ process.stderr.on('data', this.error.bind(this)); | ||
Register.prototype.parse = function(data) { | ||
Register.prototype.parse = function(data, index) { | ||
try { | ||
@@ -86,3 +86,3 @@ if (data[0].length !== 0) { | ||
Register.prototype.end = function() { | ||
Register.prototype.end = function(count) { | ||
this.emitCurrent(); | ||
@@ -89,0 +89,0 @@ this.output.emit('end'); |
{ | ||
"name": "ledger-cli", | ||
"homepage": "https://github.com/slashdotdash/node-ledger", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "API for the ledger command-line interface (ledger-cli.org).", | ||
@@ -35,5 +35,5 @@ "repository": { | ||
"lodash": "~1.0.1", | ||
"fast-csv": "0.0.0" | ||
"csv": "~0.2.9" | ||
}, | ||
"readmeFilename": "README.md" | ||
} |
@@ -31,2 +31,14 @@ # ledger-cli | ||
// JSON object for each entry | ||
entry = { | ||
total: { | ||
currency: '£', | ||
amount: 1000, | ||
formatted: '£1,000.00' | ||
}, | ||
account: { | ||
fullname: 'Assets:Checking', | ||
shortname: 'Assets:Checking', | ||
depth: 2, | ||
} | ||
} | ||
}) | ||
@@ -33,0 +45,0 @@ .once('end', function(){ |
@@ -39,3 +39,7 @@ var ledger = require('../lib/ledger'), | ||
expect(balances[0]).toBeBalance({ | ||
total: '£1,000.00', | ||
total: { | ||
currency: '£', | ||
amount: 1000, | ||
formatted: '£1,000.00' | ||
}, | ||
account: { | ||
@@ -50,4 +54,8 @@ fullname: 'Assets:Checking', | ||
it("should parse second balance", function() { | ||
expect(balances[1]).toBeBalance({ | ||
total: '£-1,000.00', | ||
expect(balances[1]).toBeBalance({ | ||
total: { | ||
currency: '£', | ||
amount: -1000, | ||
formatted: '£-1,000.00' | ||
}, | ||
account: { | ||
@@ -54,0 +62,0 @@ fullname: 'Income:Salary', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17415
436
64
+ Addedcsv@~0.2.9
+ Addedcsv@0.2.9(transitive)
- Removedfast-csv@0.0.0
- Removedcomb@0.1.91(transitive)
- Removedcommander@12.1.0(transitive)
- Removedfast-csv@0.0.0(transitive)
- Removedit@0.0.5(transitive)