"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** Default constructor * @class DataTableJsonSerializer * @classdesc Saves and loads a {@link DataTable} object to and from an json file. */ var DataTableJsonSerializer = (function () { function DataTableJsonSerializer() { this.extension = "json"; } /** Serializes the specified {@link DataTable} object into a Buffer data. * @method DataTableJsonSerializer#serialize */ DataTableJsonSerializer.prototype.serialize = function (dataTable) { return new Buffer(JSON.stringify(dataTable, null, 4), 'utf8'); }; /** Deserializes the specified buffer data into a {@link DataTable} object * @method DataTableJsonSerializer#deserialize */ DataTableJsonSerializer.prototype.deserialize = function (data) { return JSON.parse(data.toString('utf8'), DataTableJsonSerializer.JSONDataReviver); }; DataTableJsonSerializer.JSONDataReviver = function (key, str) { var result = str; if (typeof str === 'string' || str instanceof String) { var parsedValue = DataTableJsonSerializer.parseDates(str); if (parsedValue !== null) { result = parsedValue; } } return result; }; ; DataTableJsonSerializer.parseDates = function (str) { var result = null; var dateParts = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.*(\d*)Z$/.exec(str); if (dateParts !== null) { result = new Date(Date.UTC(+dateParts[1], +dateParts[2] - 1, +dateParts[3], +dateParts[4], +dateParts[5], +dateParts[6], +dateParts[7])); } return result; }; return DataTableJsonSerializer; }()); exports.DataTableJsonSerializer = DataTableJsonSerializer; //# sourceMappingURL=DataTableJsonSerializer.js.map