@nu-art/ts-common 0.99.3 → 0.99.6

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/index.d.ts CHANGED
@@ -37,3 +37,4 @@ export * from './utils/filter-tools';
37
37
  export * from './validator/validator';
38
38
  export * from './consts/consts';
39
39
  export * from './modules/CliParamsModule';
40
+ export * from './modules/csv-serializer';
package/index.js CHANGED
@@ -70,4 +70,5 @@ __exportStar(require("./utils/filter-tools"), exports);
70
70
  __exportStar(require("./validator/validator"), exports);
71
71
  __exportStar(require("./consts/consts"), exports);
72
72
  __exportStar(require("./modules/CliParamsModule"), exports);
73
+ __exportStar(require("./modules/csv-serializer"), exports);
73
74
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/main/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AAErC,gDAA8B;AAC9B,wDAAsC;AACtC,qDAAmC;AACnC,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AAEtC,qDAAmC;AACnC,sDAAoC;AACpC,qEAAmD;AACnD,mEAAiD;AACjD,oEAAkD;AAClD,kEAAgD;AAChD,mEAAiD;AACjD,yDAAuC;AACvC,uDAAqC;AACrC,sDAAoC;AACpC,0DAAwC;AAExC,iEAA+C;AAE/C,mDAAiC;AAEjC,gDAA8B;AAC9B,gDAA8B;AAC9B,uDAAqC;AACrC,uDAAqC;AACrC,iEAA+C;AAC/C,yDAAuC;AACvC,uDAAqC;AACrC,uDAAqC;AACrC,0DAAwC;AACxC,sDAAoC;AACpC,uDAAqC;AACrC,sDAAoC;AACpC,wDAAsC;AACtC,gDAA8B;AAC9B,qDAAmC;AACnC,uDAAqC;AAErC,wDAAsC;AAEtC,kDAAgC;AAEhC,4DAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/main/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AAErC,gDAA8B;AAC9B,wDAAsC;AACtC,qDAAmC;AACnC,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AAEtC,qDAAmC;AACnC,sDAAoC;AACpC,qEAAmD;AACnD,mEAAiD;AACjD,oEAAkD;AAClD,kEAAgD;AAChD,mEAAiD;AACjD,yDAAuC;AACvC,uDAAqC;AACrC,sDAAoC;AACpC,0DAAwC;AAExC,iEAA+C;AAE/C,mDAAiC;AAEjC,gDAA8B;AAC9B,gDAA8B;AAC9B,uDAAqC;AACrC,uDAAqC;AACrC,iEAA+C;AAC/C,yDAAuC;AACvC,uDAAqC;AACrC,uDAAqC;AACrC,0DAAwC;AACxC,sDAAoC;AACpC,uDAAqC;AACrC,sDAAoC;AACpC,wDAAsC;AACtC,gDAA8B;AAC9B,qDAAmC;AACnC,uDAAqC;AAErC,wDAAsC;AAEtC,kDAAgC;AAEhC,4DAA0C;AAC1C,2DAAyC"}
@@ -0,0 +1,11 @@
1
+ import { ObjectTS } from '../utils/types';
2
+ export declare type CSVProps<T extends ObjectTS = ObjectTS> = {
3
+ decimalSeparator?: string;
4
+ withHeaders?: boolean;
5
+ fieldWrapper?: string;
6
+ lineSeparator?: string;
7
+ fieldSeparator?: string;
8
+ columnNames?: ((key: keyof T) => string);
9
+ columns: (keyof T)[];
10
+ };
11
+ export declare function csvSerializer<T extends ObjectTS = ObjectTS>(items: T[], _csvProps: CSVProps<T>): string;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /*
3
+ * ts-common is the basic building blocks of our typescript projects
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __assign = (this && this.__assign) || function () {
20
+ __assign = Object.assign || function(t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
24
+ t[p] = s[p];
25
+ }
26
+ return t;
27
+ };
28
+ return __assign.apply(this, arguments);
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.csvSerializer = void 0;
32
+ function csvSerializer(items, _csvProps) {
33
+ var csvProps = __assign({ decimalSeparator: '.', withHeaders: true, fieldWrapper: '"', lineSeparator: '\n', fieldSeparator: ',', columnNames: function (k) { return k.toString(); } }, _csvProps);
34
+ function processValue(value) {
35
+ var escapedValue = (value.toString() || '').replace(csvProps.fieldWrapper, "\\".concat(csvProps.fieldWrapper));
36
+ if (escapedValue.includes(csvProps.lineSeparator) || escapedValue.includes(csvProps.fieldSeparator))
37
+ escapedValue = "".concat(csvProps.fieldWrapper).concat(escapedValue).concat(csvProps.fieldWrapper);
38
+ return "".concat(escapedValue).concat(csvProps.fieldSeparator);
39
+ }
40
+ var outputRows = [];
41
+ var columnsByOrder = csvProps.columns.map(function (c) { return c.toString(); });
42
+ var headersLine = columnsByOrder.reduce(function (output, header) { return "".concat(output).concat(processValue(csvProps.columnNames(header))); }, '').slice(0, -1);
43
+ if (csvProps.withHeaders)
44
+ outputRows.push(headersLine);
45
+ var rowsData = items.map(function (row) { return columnsByOrder.reduce(function (output, header) { return "".concat(output).concat(processValue(row[header])); }, '').slice(0, -1); });
46
+ outputRows.push.apply(outputRows, rowsData);
47
+ return outputRows.reduce(function (content, row) { return "".concat(content).concat(row).concat(csvProps.lineSeparator); }, '').slice(0, -1);
48
+ }
49
+ exports.csvSerializer = csvS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,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAE,EAAxD,CAAwD,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEzI,IAAI,QAAQ,CAAC,WAAW;QACvB,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE9B,IAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,cAAc,CAAC,MAAM,CAAC,UAAC,MAAM,EAAE,MAAM,IAAK,OAAA,UAAG,MAAM,SAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,EAAvC,CAAuC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAnG,CAAmG,CAAC,CAAC;IACzI,UAAU,CAAC,IAAI,OAAf,UAAU,EAAS,QAAQ,EAAE;IAE7B,OAAO,UAAU,CAAC,MAAM,CAAC,UAAC,OAAO,EAAE,GAAG,IAAK,OAAA,UAAG,OAAO,SAAG,GAAG,SAAG,QAAQ,CAAC,aAAa,CAAE,EAA3C,CAA2C,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC;AA9BD,sCA8BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.99.3",
3
+ "version": "0.99.6",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
package/utils/types.d.ts CHANGED
@@ -43,6 +43,7 @@ export declare type DB_BaseObject = {
43
43
  _id: string;
44
44
  };
45
45
  export declare type DB_Object = DB_BaseObject & {
46
+ _v?: string;
46
47
  __created: number;
47
48
  __updated: number;
48
49
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/main/utils/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAmEU,QAAA,IAAI,GAAG,CAAC;AACrB,CAAC,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/main/utils/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAoEU,QAAA,IAAI,GAAG,CAAC;AACrB,CAAC,CAAC,EAAE,CAAC"}