1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var abstract_1 = require("./abstract");
|
17 | var object_1 = require("../lang/object");
|
18 | var ObjectCsvStringifier = (function (_super) {
|
19 | __extends(ObjectCsvStringifier, _super);
|
20 | function ObjectCsvStringifier(fieldStringifier, header, recordDelimiter, headerIdDelimiter) {
|
21 | var _this = _super.call(this, fieldStringifier, recordDelimiter) || this;
|
22 | _this.header = header;
|
23 | _this.headerIdDelimiter = headerIdDelimiter;
|
24 | return _this;
|
25 | }
|
26 | ObjectCsvStringifier.prototype.getHeaderRecord = function () {
|
27 | if (!this.isObjectHeader)
|
28 | return null;
|
29 | return this.header.map(function (field) { return field.title; });
|
30 | };
|
31 | ObjectCsvStringifier.prototype.getRecordAsArray = function (record) {
|
32 | var _this = this;
|
33 | return this.fieldIds.map(function (fieldId) { return _this.getNestedValue(record, fieldId); });
|
34 | };
|
35 | ObjectCsvStringifier.prototype.getNestedValue = function (obj, key) {
|
36 | if (!this.headerIdDelimiter)
|
37 | return obj[key];
|
38 | return key.split(this.headerIdDelimiter).reduce(function (subObj, keyPart) { return (subObj || {})[keyPart]; }, obj);
|
39 | };
|
40 | Object.defineProperty(ObjectCsvStringifier.prototype, "fieldIds", {
|
41 | get: function () {
|
42 | return this.isObjectHeader ? this.header.map(function (column) { return column.id; }) : this.header;
|
43 | },
|
44 | enumerable: true,
|
45 | configurable: true
|
46 | });
|
47 | Object.defineProperty(ObjectCsvStringifier.prototype, "isObjectHeader", {
|
48 | get: function () {
|
49 | return object_1.isObject(this.header && this.header[0]);
|
50 | },
|
51 | enumerable: true,
|
52 | configurable: true
|
53 | });
|
54 | return ObjectCsvStringifier;
|
55 | }(abstract_1.CsvStringifier));
|
56 | exports.ObjectCsvStringifier = ObjectCsvStringifier;
|
57 |
|
\ | No newline at end of file |