@dra2020/baseclient 1.0.136 → 1.0.137
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/baseclient.js +43 -0
- package/dist/baseclient.js.map +1 -1
- package/dist/csv/all.d.ts +1 -0
- package/dist/csv/csvparseline.d.ts +1 -0
- package/lib/csv/all.ts +1 -0
- package/lib/csv/csvparseline.ts +35 -0
- package/package.json +1 -1
package/dist/csv/all.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function csvParseLine(s: string): string[];
|
package/lib/csv/all.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const reField = /^\s*("([^"]*(?:""[^"]*)*)"|[^,|]*)\s*[|,]?/;
|
|
2
|
+
const reQuote = /^"/;
|
|
3
|
+
const reAddOne = /[|,]$/;
|
|
4
|
+
|
|
5
|
+
export function csvParseLine(s: string): string[]
|
|
6
|
+
{
|
|
7
|
+
let fields: string[] = [];
|
|
8
|
+
|
|
9
|
+
s = s.trim();
|
|
10
|
+
let addOne = reAddOne.test(s);
|
|
11
|
+
while (s)
|
|
12
|
+
{
|
|
13
|
+
const match = reField.exec(s);
|
|
14
|
+
if (match)
|
|
15
|
+
{
|
|
16
|
+
let field = match[1];
|
|
17
|
+
if (reQuote.test(field))
|
|
18
|
+
{
|
|
19
|
+
// if quoted string, convert quoted double-quotes to single quote
|
|
20
|
+
field = field.slice(1, -1).replace(/""/g, '"');
|
|
21
|
+
// and remove optional start and end double quote
|
|
22
|
+
field = field.replace(/^["]?/, '').replace(/["]?$/, '');
|
|
23
|
+
}
|
|
24
|
+
fields.push(field);
|
|
25
|
+
s = s.substring(match[0].length);
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
s = null;
|
|
29
|
+
}
|
|
30
|
+
// Handle trailing separator
|
|
31
|
+
if (addOne)
|
|
32
|
+
fields.push('');
|
|
33
|
+
return fields;
|
|
34
|
+
}
|
|
35
|
+
|