ag-common 0.0.717 → 0.0.718

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.
@@ -1,3 +1,9 @@
1
1
  export declare function loadCsvAsJson<T extends Record<string | number, any>>(p: {
2
2
  fileData: string;
3
+ opt?: {
4
+ typeOverrides?: {
5
+ headerName: string;
6
+ type: 'string' | 'number';
7
+ }[];
8
+ };
3
9
  }): T[];
@@ -9,7 +9,12 @@ function loadCsvAsJson(p) {
9
9
  if (lines[0].split(',').length === 1 && lines[0].split(';').length > 1) {
10
10
  sep = ';';
11
11
  }
12
- const headers = lines[0].split(sep);
12
+ const headers = lines[0]
13
+ .split(sep)
14
+ .map((s) => {
15
+ var _a, _b, _c;
16
+ return [s, (_c = (_b = (_a = p.opt) === null || _a === void 0 ? void 0 : _a.typeOverrides) === null || _b === void 0 ? void 0 : _b.find((s1) => s1.headerName === s)) === null || _c === void 0 ? void 0 : _c.type];
17
+ });
13
18
  const jsonData = lines.slice(1).map((line) => {
14
19
  const values = [];
15
20
  let inQuote = false;
@@ -33,13 +38,17 @@ function loadCsvAsJson(p) {
33
38
  if (v === '-') {
34
39
  //ignore
35
40
  }
36
- else if ((0, math_1.isNumber)(v)) {
41
+ else if (headers[i][1] === 'string') {
42
+ //@ts-ignore
43
+ obj[headers[i][0]] = v.toString();
44
+ }
45
+ else if (headers[i][1] === 'number' || (0, math_1.isNumber)(v)) {
37
46
  //@ts-ignore
38
- obj[headers[i]] = Number(v);
47
+ obj[headers[i][0]] = Number(v);
39
48
  }
40
49
  else {
41
50
  //@ts-ignore
42
- obj[headers[i]] = v;
51
+ obj[headers[i][0]] = v;
43
52
  }
44
53
  }
45
54
  return obj;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.717",
2
+ "version": "0.0.718",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",