parser-de-notas-de-corretagem 0.0.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,7 +75,7 @@ Easing the PITA of making IRRF
75
75
 
76
76
  ## Usage
77
77
 
78
- ### Full example
78
+ ### Full NodeJS example
79
79
  ```Typescript
80
80
  import fs from 'fs';
81
81
  import path from 'path';
@@ -91,7 +91,7 @@ async function main() {
91
91
  // Get all negotiation notes inside a PDF, even with password
92
92
  const possiblePDFpasswords: string[] = ['123', '456'];
93
93
  let pdfPath = path.join(__dirname, 'note.pdf');
94
- let parseResult = await assets.parseNote(pdfPath, possiblePDFpasswords);
94
+ let parseResult = await assets.parseNote(path.basename(pdfPath), fs.readFileSync(pdfPath), possiblePDFpasswords);
95
95
 
96
96
  // Merge all negotiation notes
97
97
  let allDeals: Deal[][] = [];
package/notes-parser.d.ts CHANGED
@@ -1,92 +1,69 @@
1
- /**
2
- * Deal made in a `NegotiationNote` type
3
- */
1
+ /** Deal made in a `NegotiationNote` type */
4
2
  export interface Deal {
5
- /**
6
- * Deal type
7
- */
3
+ /** Deal type */
8
4
  type: 'buy' | 'sell';
9
- /**
10
- * Stock/FII code
11
- */
5
+ /** Stock/FII code */
12
6
  code: string;
13
- /**
14
- * Amount bought/sold
15
- */
7
+ /** Amount bought/sold */
16
8
  quantity: number;
17
- /**
18
- * Average value bought/sold with fees applied
19
- */
9
+ /** Average value bought/sold with fees applied */
20
10
  average: string;
21
- /**
22
- * Total amount bought/sold with fees applied
23
- */
11
+ /** Total amount bought/sold with fees applied */
24
12
  price: string;
25
- /**
26
- * Deal date in format yyyy-MM-dd
27
- */
13
+ /** Deal date in format yyyy-MM-dd */
28
14
  date: string;
29
- /**
30
- * Asset's CNPJ
31
- */
15
+ /** Asset's CNPJ */
32
16
  cnpj: string;
33
17
  }
34
- /**
35
- * A parsed Negotiation Note type
36
- */
18
+ /** A parsed Negotiation Note type */
37
19
  export declare class NegotiationNote {
38
- /**
39
- * Negotiation note number
40
- */
20
+ /** Negotiation note number */
41
21
  number: string;
42
- /**
43
- * The total amount bought with fees applied
44
- */
22
+ /** The total amount bought with fees applied */
45
23
  buyTotal: string;
46
- /**
47
- * The total amount sold with fees applied
48
- */
24
+ /** The total amount sold with fees applied */
49
25
  sellTotal: string;
50
- /**
51
- * The total amount of buy fees
52
- */
26
+ /** The total amount of buy fees */
53
27
  buyFees: string;
54
- /**
55
- * The total amount of sell fees
56
- */
28
+ /** The total amount of sell fees */
57
29
  sellFees: string;
58
- /**
59
- * The total amount of fees
60
- */
30
+ /** The total amount of fees */
61
31
  fees: string;
62
- /**
63
- * Negotiation note date in format yyyy-MM-dd
64
- */
32
+ /** Negotiation note date in format yyyy-MM-dd */
65
33
  date: string;
66
- /**
67
- * Negotiation note holder
68
- */
34
+ /** Negotiation note holder */
69
35
  holder: string;
70
- /**
71
- * Array of deals with buys and sells
72
- */
36
+ /** Array of deals with buys and sells */
73
37
  deals: Deal[];
74
38
  }
75
- /**
76
- * Possible date formats to be used
77
- */
39
+ /** Possible date formats to be used */
78
40
  export type DateFormat = "dd/MM/yyyy" | "yyyy-MM-dd";
79
- /**
80
- * Brokerage notes parser
81
- */
41
+ /** Wrong password error */
42
+ export declare class WrongPassword extends Error {
43
+ }
44
+ /** Empty document error */
45
+ export declare class EmptyDocument extends Error {
46
+ }
47
+ /** Document without note number error */
48
+ export declare class MissingNoteNumber extends Error {
49
+ }
50
+ /** Document without holder error */
51
+ export declare class MissingHolder extends Error {
52
+ }
53
+ /** Document without date error */
54
+ export declare class MissingDate extends Error {
55
+ }
56
+ /** Missing Buy or Sell sums */
57
+ export declare class MissingBuyOrSellSums extends Error {
58
+ }
59
+ /** Unknown Asset error error */
60
+ export declare class UnknownAsset extends Error {
61
+ }
62
+ /** Brokerage notes parser */
82
63
  export declare class NoteParser {
83
- /**
84
- * Path to the JSON data file
85
- */
64
+ /** Path to the JSON data file */
86
65
  private stockParser;
87
- /**
88
- * The date format used. Default is "dd/MM/yyyy"
89
- */
66
+ /** The date format used. Default is `dd/MM/yyyy` */
90
67
  private dateFormat;
91
68
  /**
92
69
  * Instantiate a new `NoteParser`
@@ -102,10 +79,11 @@ export declare class NoteParser {
102
79
  setDateFormat(format: DateFormat): void;
103
80
  /**
104
81
  * Read and parse a given PDF negotiation note by its full path
105
- * @param noteFullPath the full path to the PDF note to be parsed
82
+ * @param name PDF name
83
+ * @param content PDF content
106
84
  * @returns an `Array` of `NegotiationNote`
107
85
  */
108
- parseNote(noteFullPath: string, possiblePasswords?: string[]): Promise<NegotiationNote[]>;
86
+ parseNote(noteName: string, content: Uint8Array, possiblePasswords?: string[]): Promise<NegotiationNote[]>;
109
87
  /**
110
88
  * Add stock definition
111
89
  * @param code stock code