Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ledger-cli

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ledger-cli - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

30

lib/commands/balance.js
/*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',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc