git ssb

0+

Rômulo Alves / money-block



Tree: 5d6d0b006184c1e4af203d97238bda40d3ac0cad

Files: 5d6d0b006184c1e4af203d97238bda40d3ac0cad / src / helpers / block.js

886 bytesRaw
1const IGNORE_GROUP_IN_BALANCE = '-';
2
3function getValue(line) {
4 const blockType = getBlockType(line);
5 if (![blockTypes.EARNING, blockTypes.EXPENSE].includes(blockType)) {
6 throw Error('Line does not have value format: ' + line);
7 }
8
9 const parts = line.trim().split(' ');
10
11 if (parts.length < 2) {
12 throw Error('Line not in right format: ' + line);
13 }
14
15 const value = parts[1];
16
17 if (isNaN(value)) {
18 throw Error('Wrong value to line: ' + line);
19 }
20
21 const num = Number(value);
22
23 return blockType === blockTypes.EARNING ? num : num * -1;
24}
25module.exports.getValue = getValue;
26
27function ignoreGroupInBalance(groupLine) {
28 const blockType = getBlockType(groupLine);
29
30 if (blockType !== blockTypes.GROUP) {
31 throw Error('Line is not a group');
32 }
33
34 return groupLine[1] === IGNORE_GROUP_IN_BALANCE;
35}
36module.exports.ignoreGroupInBalance = ignoreGroupInBalance;
37

Built with git-ssb-web