@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/csv/all.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './csv';
2
+ export * from './csvparseline';
@@ -0,0 +1 @@
1
+ export declare function csvParseLine(s: string): string[];
package/lib/csv/all.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './csv';
2
+ export * from './csvparseline';
@@ -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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.136",
3
+ "version": "1.0.137",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",