@dra2020/baseclient 1.0.59 → 1.0.60

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/dist/csv/csv.d.ts CHANGED
@@ -1 +1,18 @@
1
- export {};
1
+ import * as Util from '../util/all';
2
+ export declare class ParseOne {
3
+ coder: Util.Coder;
4
+ fields: string[];
5
+ buf: Uint8Array;
6
+ n: number;
7
+ tok: Uint8Array;
8
+ toklen: number;
9
+ infield: boolean;
10
+ quote: number;
11
+ nwhite: number;
12
+ force: boolean;
13
+ constructor(coder: Util.Coder, line?: string);
14
+ set(line: string): void;
15
+ get length(): number;
16
+ pushtok(): void;
17
+ parse(): void;
18
+ }
package/lib/csv/csv.ts CHANGED
@@ -23,7 +23,7 @@ function isWhite(c: number): boolean
23
23
  return c === Space || c === Newline || c === Tab || c == CR;
24
24
  }
25
25
 
26
- class ParseOne
26
+ export class ParseOne
27
27
  {
28
28
  coder: Util.Coder;
29
29
  fields: string[]; // output
@@ -34,12 +34,15 @@ class ParseOne
34
34
  infield: boolean;
35
35
  quote: number;
36
36
  nwhite: number;
37
+ force: boolean;
37
38
 
38
39
  constructor(coder: Util.Coder, line?: string)
39
40
  {
40
41
  this.coder = coder;
41
42
  if (line)
42
43
  this.set(line);
44
+ else
45
+ this.fields = [];
43
46
  }
44
47
 
45
48
  set(line: string): void
@@ -52,18 +55,18 @@ class ParseOne
52
55
  this.infield = false;
53
56
  this.nwhite = 0;
54
57
  this.quote = 0;
58
+ this.force = false;
55
59
  this.parse();
56
60
  }
57
61
 
58
62
  get length(): number { return this.fields.length }
59
63
 
60
- pushtok(force: boolean): void
64
+ pushtok(): void
61
65
  {
62
66
  // Trim trailing whitespace
63
- if (!force)
64
- this.toklen -= this.nwhite;
67
+ this.toklen -= this.nwhite;
65
68
 
66
- if (this.toklen || force)
69
+ if (this.toklen || this.force)
67
70
  {
68
71
  this.fields.push(Util.u82s(this.coder, this.tok, 0, this.toklen));
69
72
  this.toklen = 0;
@@ -71,6 +74,7 @@ class ParseOne
71
74
  this.infield = false;
72
75
  this.nwhite = 0;
73
76
  this.quote = 0;
77
+ this.force = false;
74
78
  }
75
79
 
76
80
  parse(): void
@@ -79,13 +83,20 @@ class ParseOne
79
83
  {
80
84
  let c: number = this.buf[this.n++];
81
85
  if (this.quote && c === this.quote)
82
- this.pushtok(true);
86
+ {
87
+ this.quote = 0;
88
+ this.nwhite = 0;
89
+ }
83
90
  else if (c === Comma || c === Pipe)
84
- this.pushtok(true);
91
+ {
92
+ this.force = true;
93
+ this.pushtok();
94
+ this.force = true;
95
+ }
85
96
  else if (this.infield)
86
97
  {
87
98
  this.tok[this.toklen++] = c;
88
- if (isWhite(c))
99
+ if (!this.quote && isWhite(c))
89
100
  this.nwhite++;
90
101
  else
91
102
  this.nwhite = 0;
@@ -96,13 +107,15 @@ class ParseOne
96
107
  {
97
108
  this.quote = c;
98
109
  this.infield = true;
110
+ this.force = true;
99
111
  }
100
112
  else
101
113
  {
102
114
  this.infield = true;
103
115
  this.tok[this.toklen++] = c;
116
+ this.force = true;
104
117
  }
105
118
  }
106
- this.pushtok(false);
119
+ this.pushtok();
107
120
  }
108
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",