read-excel-file 5.8.7 → 6.0.0
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/CHANGELOG.md +37 -0
- package/README.md +223 -271
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/read/dropEmptyRows.js +3 -3
- package/commonjs/read/dropEmptyRows.js.map +1 -1
- package/commonjs/read/dropEmptyRows.test.js.map +1 -1
- package/commonjs/read/getData.js +18 -8
- package/commonjs/read/getData.js.map +1 -1
- package/commonjs/read/readXlsx.js +2 -2
- package/commonjs/read/readXlsx.js.map +1 -1
- package/commonjs/read/readXlsxFileContents.js +8 -9
- package/commonjs/read/readXlsxFileContents.js.map +1 -1
- package/commonjs/read/readXlsxFileNode.test.js.map +1 -1
- package/commonjs/read/schema/mapToObjects.js +100 -38
- package/commonjs/read/schema/mapToObjects.js.map +1 -1
- package/commonjs/read/schema/mapToObjects.test.js.map +1 -1
- package/commonjs/read/unpackXlsxFileNode.js +14 -3
- package/commonjs/read/unpackXlsxFileNode.js.map +1 -1
- package/index.d.ts +0 -2
- package/modules/read/dropEmptyRows.js +3 -3
- package/modules/read/dropEmptyRows.js.map +1 -1
- package/modules/read/dropEmptyRows.test.js.map +1 -1
- package/modules/read/getData.js +18 -8
- package/modules/read/getData.js.map +1 -1
- package/modules/read/readXlsx.js +2 -2
- package/modules/read/readXlsx.js.map +1 -1
- package/modules/read/readXlsxFileContents.js +8 -9
- package/modules/read/readXlsxFileContents.js.map +1 -1
- package/modules/read/readXlsxFileNode.test.js.map +1 -1
- package/modules/read/schema/mapToObjects.js +100 -38
- package/modules/read/schema/mapToObjects.js.map +1 -1
- package/modules/read/schema/mapToObjects.test.js.map +1 -1
- package/modules/read/unpackXlsxFileNode.js +14 -3
- package/modules/read/unpackXlsxFileNode.js.map +1 -1
- package/node/index.d.ts +0 -2
- package/package.json +5 -15
- package/types.d.ts +25 -39
- package/web-worker/index.d.ts +0 -2
- package/bundle/index.html +0 -261
- package/bundle/lib/prism.css +0 -125
- package/bundle/lib/prism.js +0 -7
- package/bundle/lib/promise-polyfill.min.js +0 -1
- package/commonjs/read/schema/convertMapToSchema.js +0 -27
- package/commonjs/read/schema/convertMapToSchema.js.map +0 -1
- package/commonjs/read/schema/convertMapToSchema.test.js.map +0 -1
- package/commonjs/read/schema/mapToObjects.legacy.js +0 -60
- package/commonjs/read/schema/mapToObjects.legacy.js.map +0 -1
- package/commonjs/read/schema/mapToObjects.legacy.test.js.map +0 -1
- package/commonjs/read/schema/mapToObjects.spreadsheet.js +0 -25
- package/commonjs/read/schema/mapToObjects.spreadsheet.js.map +0 -1
- package/commonjs/read/schema/mapToObjects.spreadsheet.test.js.map +0 -1
- package/map/index.cjs +0 -2
- package/map/index.cjs.js +0 -7
- package/map/index.d.ts +0 -15
- package/map/index.js +0 -1
- package/map/package.json +0 -17
- package/modules/read/schema/convertMapToSchema.js +0 -21
- package/modules/read/schema/convertMapToSchema.js.map +0 -1
- package/modules/read/schema/convertMapToSchema.test.js.map +0 -1
- package/modules/read/schema/mapToObjects.legacy.js +0 -53
- package/modules/read/schema/mapToObjects.legacy.js.map +0 -1
- package/modules/read/schema/mapToObjects.legacy.test.js.map +0 -1
- package/modules/read/schema/mapToObjects.spreadsheet.js +0 -19
- package/modules/read/schema/mapToObjects.spreadsheet.js.map +0 -1
- package/modules/read/schema/mapToObjects.spreadsheet.test.js.map +0 -1
- package/schema/index.cjs +0 -2
- package/schema/index.cjs.js +0 -7
- package/schema/index.d.ts +0 -11
- package/schema/index.js +0 -1
- package/schema/package.json +0 -17
- package/website/index.html +0 -261
- package/website/lib/prism.css +0 -125
- package/website/lib/prism.js +0 -7
- package/website/lib/promise-polyfill.min.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readXlsxFileContents.js","names":["readXlsx","
|
|
1
|
+
{"version":3,"file":"readXlsxFileContents.js","names":["readXlsx","mapToObjects","readXlsxFileContents","entries","xml","_ref","schema","options","_objectWithoutProperties","_excluded","map","Error","result","_objectSpread","properties","data"],"sources":["../../source/read/readXlsxFileContents.js"],"sourcesContent":["import readXlsx from './readXlsx.js'\r\n\r\nimport mapToObjects from './schema/mapToObjects.js'\r\n\r\nexport default function readXlsxFileContents(entries, xml, { schema, ...options}) {\r\n\tif (options.map) {\r\n\t\tthrow new Error('`map` option was removed. Pass a `schema` option instead.')\r\n\t}\r\n\t// `readXlsx()` function creates `options.rowIndexSourceMap` property.\r\n\t// It maps parsed data row indexes to spreadsheet row indexes.\r\n\t// That's because empty rows are ignored (discarded) when parsing using `schema`.\r\n\tconst result = readXlsx(entries, xml, { ...options, properties: schema || options.properties })\r\n\tif (schema) {\r\n\t\treturn mapToObjects(result.data, schema, {\r\n\t\t\t...options,\r\n\t\t\tproperties: result.properties\r\n\t\t})\r\n\t}\r\n\treturn result\r\n}"],"mappings":";;;;;;;;;AAAA,OAAOA,QAAQ,MAAM,eAAe;AAEpC,OAAOC,YAAY,MAAM,0BAA0B;AAEnD,eAAe,SAASC,oBAAoBA,CAACC,OAAO,EAAEC,GAAG,EAAAC,IAAA,EAAyB;EAAA,IAArBC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAKC,OAAO,GAAAC,wBAAA,CAAAH,IAAA,EAAAI,SAAA;EAC9E,IAAIF,OAAO,CAACG,GAAG,EAAE;IAChB,MAAM,IAAIC,KAAK,CAAC,2DAA2D,CAAC;EAC7E;EACA;EACA;EACA;EACA,IAAMC,MAAM,GAAGZ,QAAQ,CAACG,OAAO,EAAEC,GAAG,EAAAS,aAAA,CAAAA,aAAA,KAAON,OAAO;IAAEO,UAAU,EAAER,MAAM,IAAIC,OAAO,CAACO;EAAU,EAAE,CAAC;EAC/F,IAAIR,MAAM,EAAE;IACX,OAAOL,YAAY,CAACW,MAAM,CAACG,IAAI,EAAET,MAAM,EAAAO,aAAA,CAAAA,aAAA,KACnCN,OAAO;MACVO,UAAU,EAAEF,MAAM,CAACE;IAAU,EAC7B,CAAC;EACH;EACA,OAAOF,MAAM;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readXlsxFileNode.test.js","names":["path","readXlsxFileNode","describe","it","schema","
|
|
1
|
+
{"version":3,"file":"readXlsxFileNode.test.js","names":["path","readXlsxFileNode","describe","it","schema","date","column","type","Date","numberOfStudents","Number","required","course","isFree","Boolean","cost","title","String","contact","value","rowIndexSourceMap","resolve","then","_ref","rows","getTime","should","deep","equal","convertToUTCTimezone","getTimezoneOffset"],"sources":["../../source/read/readXlsxFileNode.test.js"],"sourcesContent":["import path from 'path'\r\n\r\nimport readXlsxFileNode from './readXlsxFileNode.js'\r\n\r\ndescribe('readXlsxFileNode', () => {\r\n\tit('should read *.xlsx file on Node.js and parse it to JSON', () => {\r\n\t\tconst schema = {\r\n\t\t\tdate: {\r\n\t\t\t\tcolumn: 'START DATE',\r\n\t\t\t\ttype: Date\r\n\t\t\t},\r\n\t\t\tnumberOfStudents: {\r\n\t\t\t\tcolumn: 'NUMBER OF STUDENTS',\r\n\t\t\t\ttype: Number,\r\n\t\t\t\trequired: true\r\n\t\t\t},\r\n\t\t\tcourse: {\r\n\t\t\t\tschema: {\r\n\t\t\t\t\tisFree: {\r\n\t\t\t\t\t\tcolumn: 'IS FREE',\r\n\t\t\t\t\t\ttype: Boolean\r\n\t\t\t\t\t\t// Excel stores booleans as numbers:\r\n\t\t\t\t\t\t// `1` is `true` and `0` is `false`.\r\n\t\t\t\t\t\t// Such numbers are parsed into booleans.\r\n\t\t\t\t\t},\r\n\t\t\t\t\tcost: {\r\n\t\t\t\t\t\tcolumn: 'COST',\r\n\t\t\t\t\t\ttype: Number\r\n\t\t\t\t\t},\r\n\t\t\t\t\ttitle: {\r\n\t\t\t\t\t\tcolumn: 'COURSE TITLE',\r\n\t\t\t\t\t\ttype: String\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\tcontact: {\r\n\t\t\t\tcolumn: 'CONTACT',\r\n\t\t\t\trequired: true,\r\n\t\t\t\ttype(value) {\r\n\t\t\t\t\treturn '+11234567890'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst rowIndexSourceMap = []\r\n\r\n\t\treturn readXlsxFileNode(path.resolve('./test/spreadsheets/course.xlsx'), { schema, rowIndexSourceMap }).then(({ rows }) => {\r\n\t\t\trows[0].date = rows[0].date.getTime()\r\n\t\t\trows.should.deep.equal([{\r\n\t\t\t\tdate: convertToUTCTimezone(new Date(2018, 2, 24)).getTime(),\r\n\t\t\t\tnumberOfStudents: 123,\r\n\t\t\t\tcourse: {\r\n\t\t\t\t\tisFree: false,\r\n\t\t\t\t\tcost: 210.45,\r\n\t\t\t\t\ttitle: 'Chemistry'\r\n\t\t\t\t},\r\n\t\t\t\tcontact: '+11234567890'\r\n\t\t\t}])\r\n\t\t\trowIndexSourceMap.should.deep.equal([0, 1])\r\n\t\t})\r\n\t})\r\n})\r\n\r\n// Converts timezone to UTC while preserving the same time\r\nfunction convertToUTCTimezone(date) {\r\n\t// Doesn't account for leap seconds but I guess that's ok\r\n\t// given that javascript's own `Date()` does not either.\r\n\t// https://www.timeanddate.com/time/leap-seconds-background.html\r\n\t//\r\n\t// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset\r\n\t//\r\n\treturn new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000)\r\n}\r\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,OAAOC,gBAAgB,MAAM,uBAAuB;AAEpDC,QAAQ,CAAC,kBAAkB,EAAE,YAAM;EAClCC,EAAE,CAAC,yDAAyD,EAAE,YAAM;IACnE,IAAMC,MAAM,GAAG;MACdC,IAAI,EAAE;QACLC,MAAM,EAAE,YAAY;QACpBC,IAAI,EAAEC;MACP,CAAC;MACDC,gBAAgB,EAAE;QACjBH,MAAM,EAAE,oBAAoB;QAC5BC,IAAI,EAAEG,MAAM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C,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC;;AAEF;AACA,SAASC,oBAAoBA,CAACxB,IAAI,EAAE;EACnC;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAIG,IAAI,CAACH,IAAI,CAACoB,OAAO,CAAC,CAAC,GAAGpB,IAAI,CAACyB,iBAAiB,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACvE"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
var _excluded = ["isColumnOriented", "ignoreEmptyRows", "rowIndexSourceMap"];
|
|
2
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1
3
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
4
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
6
7
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
8
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
9
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
11
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
9
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
13
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
14
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -17,8 +20,7 @@ import BooleanType from '../../types/Boolean.js';
|
|
|
17
20
|
import DateType from '../../types/Date.js';
|
|
18
21
|
var DEFAULT_OPTIONS = {
|
|
19
22
|
schemaPropertyValueForMissingColumn: undefined,
|
|
20
|
-
|
|
21
|
-
schemaPropertyValueForNullCellValue: null,
|
|
23
|
+
schemaPropertyValueForMissingValue: null,
|
|
22
24
|
schemaPropertyShouldSkipRequiredValidationForMissingColumn: function schemaPropertyShouldSkipRequiredValidationForMissingColumn() {
|
|
23
25
|
return false;
|
|
24
26
|
},
|
|
@@ -31,24 +33,39 @@ var DEFAULT_OPTIONS = {
|
|
|
31
33
|
return null;
|
|
32
34
|
},
|
|
33
35
|
isColumnOriented: false,
|
|
36
|
+
ignoreEmptyRows: true,
|
|
34
37
|
arrayValueSeparator: ','
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
|
-
* (this function is exported from `read-excel-file/map`)
|
|
39
41
|
* Converts spreadsheet-alike data structure into an array of objects.
|
|
40
|
-
*
|
|
42
|
+
*
|
|
43
|
+
* Parameters:
|
|
44
|
+
*
|
|
45
|
+
* * `data` — An array of rows, each row being an array of cells. The first row should be the list of column headers and the rest of the rows should be the data.
|
|
46
|
+
* * `schema` — A "to JSON" convertion schema (see above).
|
|
47
|
+
* * `options` — (optional) Schema conversion parameters of `read-excel-file`:
|
|
48
|
+
* * `schemaPropertyValueForMissingColumn` — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such "missing column" properties to `null` in the output objects.
|
|
49
|
+
* * `schemaPropertyValueForNullCellValue` — By default, when it encounters a `null` value in a cell in input `data`, it sets it to `undefined` in the output object. Pass `schemaPropertyValueForNullCellValue: null` to make it set such values as `null`s in output objects.
|
|
50
|
+
* * `schemaPropertyValueForUndefinedCellValue` — By default, when it encounters an `undefined` value in a cell in input `data`, it it sets it to `undefined` in the output object. Pass `schemaPropertyValueForUndefinedCellValue: null` to make it set such values as `null`s in output objects.
|
|
51
|
+
* * `schemaPropertyShouldSkipRequiredValidationForMissingColumn: (column: string, { object }) => boolean` — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.
|
|
52
|
+
* * `getEmptyObjectValue(object, { path? })` — By default, it returns `null` for "empty" objects. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional (optional) `path?: string` parameter.
|
|
53
|
+
* * `getEmptyArrayValue(array, { path })` — By default, it returns `null` for an "empty" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.
|
|
54
|
+
*
|
|
55
|
+
* When parsing a property value, in case of an error, the value of that property is gonna be `undefined`.
|
|
56
|
+
*
|
|
41
57
|
* @param {any[][]} data - An array of rows, each row being an array of cells.
|
|
42
58
|
* @param {object} schema
|
|
43
59
|
* @param {object} [options]
|
|
44
60
|
* @param {null} [options.schemaPropertyValueForMissingColumn] — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such "missing column" properties to `null` in the output objects.
|
|
45
|
-
* @param {null} [options.
|
|
46
|
-
* @param {
|
|
61
|
+
* @param {null} [options.schemaPropertyValueForMissingValue] — By default, when it encounters a `null` value in a cell in input `data`, it leaves the value as is. Pass a custom `schemaPropertyValueForMissingValue` to make it set such values to that value.
|
|
62
|
+
* @param {object} [options.properties] — An optional object with optional property `epoch1904: true/false`. It is used when parsing dates.
|
|
47
63
|
* @param {boolean} [options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(column: string, { object })] — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.
|
|
48
64
|
* @param {function} [options.getEmptyObjectValue(object, { path })] — By default, it returns `null` for an "empty" resulting object. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional `path?: string` parameter.
|
|
49
65
|
* @param {function} [getEmptyArrayValue(array, { path })] — By default, it returns `null` for an "empty" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.
|
|
50
66
|
* @param {boolean} [options.isColumnOriented] — By default, the headers are assumed to be the first row in the `data`. Pass `isColumnOriented: true` if the headers are the first column in the `data`. i.e. if `data` is "transposed".
|
|
51
|
-
* @param {
|
|
67
|
+
* @param {string} [options.arrayValueSeparator] — When specified, string values will be split by this separator to get the array.
|
|
68
|
+
* @param {object} [options.rowIndexSourceMap] — Custom row indexes of `data` rows. If present, will overwrite the indexes of `data` rows with the indexes from this `rowIndexSourceMap`.
|
|
52
69
|
* @return {object[]}
|
|
53
70
|
*/
|
|
54
71
|
export default function mapToObjects(data, schema, options) {
|
|
@@ -59,28 +76,50 @@ export default function mapToObjects(data, schema, options) {
|
|
|
59
76
|
}
|
|
60
77
|
var _options = options,
|
|
61
78
|
isColumnOriented = _options.isColumnOriented,
|
|
62
|
-
|
|
79
|
+
ignoreEmptyRows = _options.ignoreEmptyRows,
|
|
80
|
+
rowIndexSourceMapOriginal = _options.rowIndexSourceMap,
|
|
81
|
+
schemaTransformOptions = _objectWithoutProperties(_options, _excluded);
|
|
82
|
+
|
|
83
|
+
// `rowIndexSourceMap` could be mutated by `ignoreEmptyRows: true` option.
|
|
84
|
+
// Create a copy of it so that the original `rowIndexSourceMap` is not affected by those changes.
|
|
85
|
+
var rowIndexSourceMap = rowIndexSourceMapOriginal && rowIndexSourceMapOriginal.slice();
|
|
63
86
|
validateSchema(schema);
|
|
64
87
|
if (isColumnOriented) {
|
|
65
88
|
data = transpose(data);
|
|
66
89
|
}
|
|
90
|
+
if (ignoreEmptyRows) {
|
|
91
|
+
data = data.filter(function (row, i) {
|
|
92
|
+
var isEmptyRow = row.every(function (cell) {
|
|
93
|
+
return cell === null;
|
|
94
|
+
});
|
|
95
|
+
if (isEmptyRow) {
|
|
96
|
+
// Adjust `rowIndexSourceMap` now that the row has been removed.
|
|
97
|
+
if (rowIndexSourceMap) {
|
|
98
|
+
// Remove the `rowIndexSourceMap` entry that corresponds to the removed row.
|
|
99
|
+
rowIndexSourceMap.splice(i, 1);
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
67
106
|
var columns = data[0];
|
|
68
107
|
var results = [];
|
|
69
108
|
var errors = [];
|
|
70
109
|
for (var i = 1; i < data.length; i++) {
|
|
71
|
-
var result = read(schema, data[i], i, undefined, columns, errors,
|
|
110
|
+
var result = read(schema, data[i], i, undefined, columns, errors, schemaTransformOptions);
|
|
72
111
|
results.push(result);
|
|
73
112
|
}
|
|
74
113
|
|
|
75
|
-
// Set the correct `row` number in `errors` if a custom `
|
|
76
|
-
if (
|
|
114
|
+
// Set the correct `row` number in `errors` if a custom `rowIndexSourceMap` is supplied.
|
|
115
|
+
if (rowIndexSourceMap) {
|
|
77
116
|
for (var _iterator = _createForOfIteratorHelperLoose(errors), _step; !(_step = _iterator()).done;) {
|
|
78
117
|
var error = _step.value;
|
|
79
118
|
// Convert the `row` index in `data` to the
|
|
80
119
|
// actual `row` index in the spreadsheet.
|
|
81
120
|
// `- 1` converts row number to row index.
|
|
82
121
|
// `+ 1` converts row index to row number.
|
|
83
|
-
error.row =
|
|
122
|
+
error.row = rowIndexSourceMap[error.row - 1] + 1;
|
|
84
123
|
}
|
|
85
124
|
}
|
|
86
125
|
return {
|
|
@@ -92,21 +131,23 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
92
131
|
var object = {};
|
|
93
132
|
var isEmptyObject = true;
|
|
94
133
|
var createError = function createError(_ref) {
|
|
95
|
-
var
|
|
134
|
+
var schemaEntry = _ref.schemaEntry,
|
|
96
135
|
value = _ref.value,
|
|
97
136
|
errorMessage = _ref.error,
|
|
98
137
|
reason = _ref.reason;
|
|
99
138
|
var error = {
|
|
100
139
|
error: errorMessage,
|
|
101
140
|
row: rowIndex + 1,
|
|
102
|
-
column: column,
|
|
141
|
+
column: schemaEntry.column,
|
|
103
142
|
value: value
|
|
104
143
|
};
|
|
105
144
|
if (reason) {
|
|
106
145
|
error.reason = reason;
|
|
107
146
|
}
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
// * Regular values specify a `type?` property, which is included in the `error` object.
|
|
148
|
+
// * Nested objects specify a `schema` property, which is not included in the `error` object.
|
|
149
|
+
if (schemaEntry.type) {
|
|
150
|
+
error.type = schemaEntry.type;
|
|
110
151
|
}
|
|
111
152
|
return error;
|
|
112
153
|
};
|
|
@@ -116,14 +157,19 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
116
157
|
var _loop = function _loop() {
|
|
117
158
|
var key = _Object$keys[_i];
|
|
118
159
|
var schemaEntry = schema[key];
|
|
119
|
-
|
|
160
|
+
|
|
161
|
+
// `schemaEntry.prop` property is now deprecated and shouldn't be used.
|
|
162
|
+
// Instead, it now uses `key` as the key in the `object`.
|
|
163
|
+
// And column name is now read not from `key` but from `schemaEntry.column` property.
|
|
164
|
+
var propertyName = key;
|
|
165
|
+
var columnTitle = schemaEntry.column;
|
|
120
166
|
|
|
121
167
|
// The path of this property inside the resulting object.
|
|
122
|
-
var propertyPath = "".concat(path || '', ".").concat(
|
|
168
|
+
var propertyPath = "".concat(path || '', ".").concat(propertyName);
|
|
123
169
|
|
|
124
170
|
// Read the cell value for the schema entry.
|
|
125
171
|
var cellValue;
|
|
126
|
-
var columnIndex = columns.indexOf(
|
|
172
|
+
var columnIndex = columns.indexOf(columnTitle);
|
|
127
173
|
var isMissingColumn = columnIndex < 0;
|
|
128
174
|
if (!isMissingColumn) {
|
|
129
175
|
cellValue = row[columnIndex];
|
|
@@ -133,15 +179,23 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
133
179
|
var reason;
|
|
134
180
|
|
|
135
181
|
// Get property `value` from cell value.
|
|
136
|
-
if (
|
|
137
|
-
value = read(schemaEntry.
|
|
182
|
+
if (schemaEntry.schema) {
|
|
183
|
+
value = read(schemaEntry.schema, row, rowIndex, propertyPath, columns, errors, options);
|
|
138
184
|
} else {
|
|
139
185
|
if (isMissingColumn) {
|
|
140
|
-
|
|
186
|
+
if ('schemaPropertyValueForMissingColumn' in options) {
|
|
187
|
+
value = options.schemaPropertyValueForMissingColumn;
|
|
188
|
+
}
|
|
141
189
|
} else if (cellValue === undefined) {
|
|
142
|
-
|
|
190
|
+
// This isn't supposed to be possible. Cell values are always `null` when cells are empty.
|
|
191
|
+
// Employ some sensible fallback behavior here.
|
|
192
|
+
if ('schemaPropertyValueForMissingValue' in options) {
|
|
193
|
+
value = options.schemaPropertyValueForMissingValue;
|
|
194
|
+
}
|
|
143
195
|
} else if (cellValue === null) {
|
|
144
|
-
|
|
196
|
+
if ('schemaPropertyValueForMissingValue' in options) {
|
|
197
|
+
value = options.schemaPropertyValueForMissingValue;
|
|
198
|
+
}
|
|
145
199
|
} else if (Array.isArray(schemaEntry.type)) {
|
|
146
200
|
var array = parseArray(cellValue, options.arrayValueSeparator).map(function (_value) {
|
|
147
201
|
if (error) {
|
|
@@ -177,7 +231,7 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
177
231
|
// Will perform this `required()` validation in the end,
|
|
178
232
|
// when all properties of the mapped object have been mapped.
|
|
179
233
|
pendingRequiredChecks.push({
|
|
180
|
-
|
|
234
|
+
schemaEntry: schemaEntry,
|
|
181
235
|
value: value,
|
|
182
236
|
isMissingColumn: isMissingColumn
|
|
183
237
|
});
|
|
@@ -187,7 +241,7 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
187
241
|
// If there was an error then the property value in the `object` will be `undefined`,
|
|
188
242
|
// i.e it won't add the property value to the mapped object.
|
|
189
243
|
errors.push(createError({
|
|
190
|
-
|
|
244
|
+
schemaEntry: schemaEntry,
|
|
191
245
|
value: value,
|
|
192
246
|
error: error,
|
|
193
247
|
reason: reason
|
|
@@ -198,9 +252,10 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
198
252
|
isEmptyObject = false;
|
|
199
253
|
}
|
|
200
254
|
// Set the value in the mapped object.
|
|
201
|
-
// Skip setting `undefined` values because they're already `undefined
|
|
255
|
+
// Skip setting `undefined` values because they're already `undefined`
|
|
256
|
+
// due to not having previously been set.
|
|
202
257
|
if (value !== undefined) {
|
|
203
|
-
object[
|
|
258
|
+
object[propertyName] = value;
|
|
204
259
|
}
|
|
205
260
|
}
|
|
206
261
|
};
|
|
@@ -218,19 +273,19 @@ function read(schema, row, rowIndex, path, columns, errors, options) {
|
|
|
218
273
|
// Perform any `required` validations.
|
|
219
274
|
for (var _i2 = 0, _pendingRequiredCheck = pendingRequiredChecks; _i2 < _pendingRequiredCheck.length; _i2++) {
|
|
220
275
|
var _pendingRequiredCheck2 = _pendingRequiredCheck[_i2],
|
|
221
|
-
|
|
276
|
+
schemaEntry = _pendingRequiredCheck2.schemaEntry,
|
|
222
277
|
value = _pendingRequiredCheck2.value,
|
|
223
278
|
isMissingColumn = _pendingRequiredCheck2.isMissingColumn;
|
|
224
279
|
// Can optionally skip `required` validation for missing columns.
|
|
225
|
-
var skipRequiredValidation = isMissingColumn && options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, {
|
|
280
|
+
var skipRequiredValidation = isMissingColumn && options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(schemaEntry.column, {
|
|
226
281
|
object: object
|
|
227
282
|
});
|
|
228
283
|
if (!skipRequiredValidation) {
|
|
229
|
-
var required =
|
|
284
|
+
var required = schemaEntry.required;
|
|
230
285
|
var isRequired = typeof required === 'boolean' ? required : required(object);
|
|
231
286
|
if (isRequired) {
|
|
232
287
|
errors.push(createError({
|
|
233
|
-
|
|
288
|
+
schemaEntry: schemaEntry,
|
|
234
289
|
value: value,
|
|
235
290
|
error: 'required'
|
|
236
291
|
}));
|
|
@@ -256,7 +311,7 @@ export function parseValue(value, schemaEntry, options) {
|
|
|
256
311
|
}
|
|
257
312
|
var result;
|
|
258
313
|
if (schemaEntry.parse) {
|
|
259
|
-
|
|
314
|
+
throw new Error('`schemaEntry.parse` property was renamed to `schemaEntry.type`');
|
|
260
315
|
} else if (schemaEntry.type) {
|
|
261
316
|
result = parseValueOfType(value,
|
|
262
317
|
// Supports parsing array types.
|
|
@@ -269,7 +324,7 @@ export function parseValue(value, schemaEntry, options) {
|
|
|
269
324
|
result = {
|
|
270
325
|
value: value
|
|
271
326
|
};
|
|
272
|
-
// throw new Error('Invalid schema entry: no
|
|
327
|
+
// throw new Error('Invalid schema entry: no `type` specified:\n\n' + JSON.stringify(schemaEntry, null, 2))
|
|
273
328
|
}
|
|
274
329
|
// If errored then return the error.
|
|
275
330
|
if (result.error) {
|
|
@@ -402,9 +457,16 @@ var transpose = function transpose(array) {
|
|
|
402
457
|
function validateSchema(schema) {
|
|
403
458
|
for (var _i3 = 0, _Object$keys2 = Object.keys(schema); _i3 < _Object$keys2.length; _i3++) {
|
|
404
459
|
var key = _Object$keys2[_i3];
|
|
405
|
-
var
|
|
406
|
-
|
|
407
|
-
|
|
460
|
+
var schemaEntry = schema[key];
|
|
461
|
+
// Validate that the `schema` is not using a deprecated `type: nestedSchema` format.
|
|
462
|
+
if (_typeof(schemaEntry.type) === 'object' && !Array.isArray(schemaEntry.type)) {
|
|
463
|
+
throw new Error('When defining a nested schema, use a `schema` property instead of a `type` property');
|
|
464
|
+
}
|
|
465
|
+
// Validate that every property has a source `column` title specified for it.
|
|
466
|
+
if (!schemaEntry.schema) {
|
|
467
|
+
if (!schemaEntry.column) {
|
|
468
|
+
throw new Error("\"column\" not defined for schema entry \"".concat(key, "\"."));
|
|
469
|
+
}
|
|
408
470
|
}
|
|
409
471
|
}
|
|
410
472
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapToObjects.js","names":["NumberType","StringType","BooleanType","DateType","DEFAULT_OPTIONS","schemaPropertyValueForMissingColumn","undefined","schemaPropertyValueForUndefinedCellValue","schemaPropertyValueForNullCellValue","schemaPropertyShouldSkipRequiredValidationForMissingColumn","getEmptyObjectValue","getEmptyArrayValue","isColumnOriented","arrayValueSeparator","mapToObjects","data","schema","options","_objectSpread","_options","rowIndexMap","validateSchema","transpose","columns","results","errors","i","length","result","read","push","_iterator","_createForOfIteratorHelperLoose","_step","done","error","value","row","rows","rowIndex","path","object","isEmptyObject","createError","_ref","column","errorMessage","reason","type","pendingRequiredChecks","_loop","key","_Object$keys","_i","schemaEntry","isNestedSchema","_typeof","Array","isArray","propertyPath","concat","prop","cellValue","columnIndex","indexOf","isMissingColumn","array","parseArray","map","_value","parseValue","isEmpty","every","isEmptyValue","required","Object","keys","_i2","_pendingRequiredCheck","_pendingRequiredCheck2","skipRequiredValidation","isRequired","parse","parseCustomValue","parseValueOfType","oneOf","validate","message","parsedValue","String","Number","Date","properties","Boolean","Error","name","getBlock","string","endCharacter","startIndex","substring","character","block","blocks","index","_getBlock","_getBlock2","_slicedToArray","trim","_","_i3","_Object$keys2","entry"],"sources":["../../../source/read/schema/mapToObjects.js"],"sourcesContent":["import NumberType from '../../types/Number.js'\r\nimport StringType from '../../types/String.js'\r\nimport BooleanType from '../../types/Boolean.js'\r\nimport DateType from '../../types/Date.js'\r\n\r\nconst DEFAULT_OPTIONS = {\r\n schemaPropertyValueForMissingColumn: undefined,\r\n schemaPropertyValueForUndefinedCellValue: undefined,\r\n schemaPropertyValueForNullCellValue: null,\r\n schemaPropertyShouldSkipRequiredValidationForMissingColumn: () => false,\r\n // `getEmptyObjectValue(object, { path })` applies to both the top-level object\r\n // and any of its sub-objects.\r\n getEmptyObjectValue: () => null,\r\n getEmptyArrayValue: () => null,\r\n isColumnOriented: false,\r\n arrayValueSeparator: ','\r\n}\r\n\r\n/**\r\n * (this function is exported from `read-excel-file/map`)\r\n * Converts spreadsheet-alike data structure into an array of objects.\r\n * The first row should be the list of column headers.\r\n * @param {any[][]} data - An array of rows, each row being an array of cells.\r\n * @param {object} schema\r\n * @param {object} [options]\r\n * @param {null} [options.schemaPropertyValueForMissingColumn] — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * @param {null} [options.schemaPropertyValueForNullCellValue] — By default, when it encounters a `null` value in a cell in input `data`, it sets it to `undefined` in the output object. Pass `schemaPropertyValueForNullCellValue: null` to make it set such values as `null`s in output objects.\r\n * @param {null} [options.schemaPropertyValueForUndefinedCellValue] — By default, when it encounters an `undefined` value in a cell in input `data`, it it sets it to `undefined` in the output object. Pass `schemaPropertyValueForUndefinedCellValue: null` to make it set such values as `null`s in output objects.\r\n * @param {boolean} [options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(column: string, { object })] — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * @param {function} [options.getEmptyObjectValue(object, { path })] — By default, it returns `null` for an \"empty\" resulting object. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional `path?: string` parameter.\r\n * @param {function} [getEmptyArrayValue(array, { path })] — By default, it returns `null` for an \"empty\" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.\r\n * @param {boolean} [options.isColumnOriented] — By default, the headers are assumed to be the first row in the `data`. Pass `isColumnOriented: true` if the headers are the first column in the `data`. i.e. if `data` is \"transposed\".\r\n * @param {object} [options.rowIndexMap] — Custom row index mapping `data` rows. If present, will overwrite the indexes of `data` rows with the indexes from this `rowIndexMap`.\r\n * @return {object[]}\r\n */\r\nexport default function mapToObjects(data, schema, options) {\r\n if (options) {\r\n options = {\r\n ...DEFAULT_OPTIONS,\r\n ...options\r\n }\r\n } else {\r\n options = DEFAULT_OPTIONS\r\n }\r\n\r\n const {\r\n isColumnOriented,\r\n rowIndexMap\r\n } = options\r\n\r\n validateSchema(schema)\r\n\r\n if (isColumnOriented) {\r\n data = transpose(data)\r\n }\r\n\r\n const columns = data[0]\r\n\r\n const results = []\r\n const errors = []\r\n\r\n for (let i = 1; i < data.length; i++) {\r\n const result = read(schema, data[i], i, undefined, columns, errors, options)\r\n results.push(result)\r\n }\r\n\r\n // Set the correct `row` number in `errors` if a custom `rowIndexMap` is supplied.\r\n if (rowIndexMap) {\r\n for (const error of errors) {\r\n // Convert the `row` index in `data` to the\r\n // actual `row` index in the spreadsheet.\r\n // `- 1` converts row number to row index.\r\n // `+ 1` converts row index to row number.\r\n error.row = rowIndexMap[error.row - 1] + 1\r\n }\r\n }\r\n\r\n return {\r\n rows: results,\r\n errors\r\n }\r\n}\r\n\r\nfunction read(schema, row, rowIndex, path, columns, errors, options) {\r\n const object = {}\r\n let isEmptyObject = true\r\n\r\n const createError = ({\r\n column,\r\n value,\r\n error: errorMessage,\r\n reason\r\n }) => {\r\n const error = {\r\n error: errorMessage,\r\n row: rowIndex + 1,\r\n column,\r\n value\r\n }\r\n if (reason) {\r\n error.reason = reason\r\n }\r\n if (schema[column].type) {\r\n error.type = schema[column].type\r\n }\r\n return error\r\n }\r\n\r\n const pendingRequiredChecks = []\r\n\r\n // For each schema entry.\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n const isNestedSchema = typeof schemaEntry.type === 'object' && !Array.isArray(schemaEntry.type)\r\n\r\n // The path of this property inside the resulting object.\r\n const propertyPath = `${path || ''}.${schemaEntry.prop}`\r\n\r\n // Read the cell value for the schema entry.\r\n let cellValue\r\n const columnIndex = columns.indexOf(key)\r\n const isMissingColumn = columnIndex < 0\r\n if (!isMissingColumn) {\r\n cellValue = row[columnIndex]\r\n }\r\n\r\n let value\r\n let error\r\n let reason\r\n\r\n // Get property `value` from cell value.\r\n if (isNestedSchema) {\r\n value = read(schemaEntry.type, row, rowIndex, propertyPath, columns, errors, options)\r\n } else {\r\n if (isMissingColumn) {\r\n value = options.schemaPropertyValueForMissingColumn\r\n }\r\n else if (cellValue === undefined) {\r\n value = options.schemaPropertyValueForUndefinedCellValue\r\n }\r\n else if (cellValue === null) {\r\n value = options.schemaPropertyValueForNullCellValue\r\n }\r\n else if (Array.isArray(schemaEntry.type)) {\r\n const array = parseArray(cellValue, options.arrayValueSeparator).map((_value) => {\r\n if (error) {\r\n return\r\n }\r\n const result = parseValue(_value, schemaEntry, options)\r\n if (result.error) {\r\n // In case of an error, `value` won't be returned and will just be reported\r\n // as part of an `error` object, so it's fine assigning just an element of the array.\r\n value = _value\r\n error = result.error\r\n reason = result.reason\r\n }\r\n return result.value\r\n })\r\n if (!error) {\r\n const isEmpty = array.every(isEmptyValue)\r\n value = isEmpty ? options.getEmptyArrayValue(array, { path: propertyPath }) : array\r\n }\r\n } else {\r\n const result = parseValue(cellValue, schemaEntry, options)\r\n error = result.error\r\n reason = result.reason\r\n value = error ? cellValue : result.value\r\n }\r\n }\r\n\r\n // Apply `required` validation if the value is \"empty\".\r\n if (!error && isEmptyValue(value)) {\r\n if (schemaEntry.required) {\r\n // Will perform this `required()` validation in the end,\r\n // when all properties of the mapped object have been mapped.\r\n pendingRequiredChecks.push({ column: key, value, isMissingColumn })\r\n }\r\n }\r\n\r\n if (error) {\r\n // If there was an error then the property value in the `object` will be `undefined`,\r\n // i.e it won't add the property value to the mapped object.\r\n errors.push(createError({\r\n column: key,\r\n value,\r\n error,\r\n reason\r\n }))\r\n } else {\r\n // Possibly unmark the mapped object as \"empty\".\r\n if (isEmptyObject && !isEmptyValue(value)) {\r\n isEmptyObject = false\r\n }\r\n // Set the value in the mapped object.\r\n // Skip setting `undefined` values because they're already `undefined`.\r\n if (value !== undefined) {\r\n object[schemaEntry.prop] = value\r\n }\r\n }\r\n }\r\n\r\n // Return `null` for an \"empty\" mapped object.\r\n if (isEmptyObject) {\r\n return options.getEmptyObjectValue(object, { path })\r\n }\r\n\r\n // Perform any `required` validations.\r\n for (const { column, value, isMissingColumn } of pendingRequiredChecks) {\r\n // Can optionally skip `required` validation for missing columns.\r\n const skipRequiredValidation = isMissingColumn && options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })\r\n if (!skipRequiredValidation) {\r\n const { required } = schema[column]\r\n const isRequired = typeof required === 'boolean' ? required : required(object)\r\n if (isRequired) {\r\n errors.push(createError({\r\n column,\r\n value,\r\n error: 'required'\r\n }))\r\n }\r\n }\r\n }\r\n\r\n // Return the mapped object.\r\n return object\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @return {{ value: any, error: string }}\r\n */\r\nexport function parseValue(value, schemaEntry, options) {\r\n if (value === null) {\r\n return { value: null }\r\n }\r\n let result\r\n if (schemaEntry.parse) {\r\n result = parseCustomValue(value, schemaEntry.parse)\r\n } else if (schemaEntry.type) {\r\n result = parseValueOfType(\r\n value,\r\n // Supports parsing array types.\r\n // See `parseArray()` function for more details.\r\n // Example `type`: String[]\r\n // Input: 'Barack Obama, \"String, with, colons\", Donald Trump'\r\n // Output: ['Barack Obama', 'String, with, colons', 'Donald Trump']\r\n Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type,\r\n options\r\n )\r\n } else {\r\n result = { value: value }\r\n // throw new Error('Invalid schema entry: no .type and no .parse():\\n\\n' + JSON.stringify(schemaEntry, null, 2))\r\n }\r\n // If errored then return the error.\r\n if (result.error) {\r\n return result\r\n }\r\n if (result.value !== null) {\r\n if (schemaEntry.oneOf && schemaEntry.oneOf.indexOf(result.value) < 0) {\r\n return { error: 'invalid', reason: 'unknown' }\r\n }\r\n if (schemaEntry.validate) {\r\n try {\r\n schemaEntry.validate(result.value)\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n }\r\n }\r\n return result\r\n}\r\n\r\n/**\r\n * Converts textual value to a custom value using supplied `.parse()`.\r\n * @param {any} value\r\n * @param {function} parse\r\n * @return {{ value: any, error: string }}\r\n */\r\nfunction parseCustomValue(value, parse) {\r\n try {\r\n const parsedValue = parse(value)\r\n if (parsedValue === undefined) {\r\n return { value: null }\r\n }\r\n return { value: parsedValue }\r\n } catch (error) {\r\n const result = { error: error.message }\r\n if (error.reason) {\r\n result.reason = error.reason;\r\n }\r\n return result\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {} type\r\n * @return {{ value: (string|number|Date|boolean), error: string, reason?: string }}\r\n */\r\nfunction parseValueOfType(value, type, options) {\r\n switch (type) {\r\n case String:\r\n return parseCustomValue(value, StringType)\r\n\r\n case Number:\r\n return parseCustomValue(value, NumberType)\r\n\r\n case Date:\r\n return parseCustomValue(value, (value) => DateType(value, { properties: options.properties }))\r\n\r\n case Boolean:\r\n return parseCustomValue(value, BooleanType)\r\n\r\n default:\r\n if (typeof type === 'function') {\r\n return parseCustomValue(value, type)\r\n }\r\n throw new Error(`Unsupported schema type: ${type && type.name || type}`)\r\n }\r\n}\r\n\r\nexport function getBlock(string, endCharacter, startIndex) {\r\n let i = 0\r\n let substring = ''\r\n let character\r\n while (startIndex + i < string.length) {\r\n const character = string[startIndex + i]\r\n if (character === endCharacter) {\r\n return [substring, i]\r\n }\r\n else if (character === '\"') {\r\n const block = getBlock(string, '\"', startIndex + i + 1)\r\n substring += block[0]\r\n i += '\"'.length + block[1] + '\"'.length\r\n }\r\n else {\r\n substring += character\r\n i++\r\n }\r\n }\r\n return [substring, i]\r\n}\r\n\r\n/**\r\n * Parses a string of comma-separated substrings into an array of substrings.\r\n * (the `export` is just for tests)\r\n * @param {string} string — A string of comma-separated substrings.\r\n * @return {string[]} An array of substrings.\r\n */\r\nexport function parseArray(string, arrayValueSeparator) {\r\n const blocks = []\r\n let index = 0\r\n while (index < string.length) {\r\n const [substring, length] = getBlock(string, arrayValueSeparator, index)\r\n index += length + arrayValueSeparator.length\r\n blocks.push(substring.trim())\r\n }\r\n return blocks\r\n}\r\n\r\n// Transpose a 2D array.\r\n// https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript\r\nconst transpose = array => array[0].map((_, i) => array.map(row => row[i]))\r\n\r\nfunction validateSchema(schema) {\r\n for (const key of Object.keys(schema)) {\r\n const entry = schema[key]\r\n if (!entry.prop) {\r\n throw new Error(`\"prop\" not defined for schema entry \"${key}\".`)\r\n }\r\n }\r\n}\r\n\r\nfunction isEmptyValue(value) {\r\n return value === undefined || value === null\r\n}"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,UAAU,MAAM,uBAAuB;AAC9C,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,OAAOC,WAAW,MAAM,wBAAwB;AAChD,OAAOC,QAAQ,MAAM,qBAAqB;AAE1C,IAAMC,eAAe,GAAG;EACtBC,mCAAmC,EAAEC,SAAS;EAC9CC,wCAAwC,EAAED,SAAS;EACnDE,mCAAmC,EAAE,IAAI;EACzCC,0DAA0D,EAAE,SAAAA,2DAAA;IAAA,OAAM,KAAK;EAAA;EACvE;EACA;EACAC,mBAAmB,EAAE,SAA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EAAE2F,KAAK,CAAC;MAAAE,UAAA,GAAAC,cAAA,CAAAF,SAAA;MAAjEL,SAAS,GAAAM,UAAA;MAAE/E,MAAM,GAAA+E,UAAA;IACxBF,KAAK,IAAI7E,MAAM,GAAGd,mBAAmB,CAACc,MAAM;IAC5C4E,MAAM,CAACzE,IAAI,CAACsE,SAAS,CAACQ,IAAI,CAAC,CAAC,CAAC;EAC/B;EACA,OAAOL,MAAM;AACf;;AAEA;AACA;AACA,IAAMjF,SAAS,GAAG,SAAZA,SAASA,CAAG4C,KAAK;EAAA,OAAIA,KAAK,CAAC,CAAC,CAAC,CAACE,GAAG,CAAC,UAACyC,CAAC,EAAEnF,CAAC;IAAA,OAAKwC,KAAK,CAACE,GAAG,CAAC,UAAA/B,GAAG;MAAA,OAAIA,GAAG,CAACX,CAAC,CAAC;IAAA,EAAC;EAAA,EAAC;AAAA;AAE3E,SAASL,cAAcA,CAACL,MAAM,EAAE;EAC9B,SAAA8F,GAAA,MAAAC,aAAA,GAAkBpC,MAAM,CAACC,IAAI,CAAC5D,MAAM,CAAC,EAAA8F,GAAA,GAAAC,aAAA,CAAApF,MAAA,EAAAmF,GAAA,IAAE;IAAlC,IAAM3D,GAAG,GAAA4D,aAAA,CAAAD,GAAA;IACZ,IAAME,KAAK,GAAGhG,MAAM,CAACmC,GAAG,CAAC;IACzB,IAAI,CAAC6D,KAAK,CAACnD,IAAI,EAAE;MACf,MAAM,IAAIiC,KAAK,4CAAAlC,MAAA,CAAyCT,GAAG,QAAI,CAAC;IAClE;EACF;AACF;AAEA,SAASsB,YAAYA,CAACrC,KAAK,EAAE;EAC3B,OAAOA,KAAK,KAAK9B,SAAS,IAAI8B,KAAK,KAAK,IAAI;AAC9C"}
|
|
1
|
+
{"version":3,"file":"mapToObjects.js","names":["NumberType","StringType","BooleanType","DateType","DEFAULT_OPTIONS","schemaPropertyValueForMissingColumn","undefined","schemaPropertyValueForMissingValue","schemaPropertyShouldSkipRequiredValidationForMissingColumn","getEmptyObjectValue","getEmptyArrayValue","isColumnOriented","ignoreEmptyRows","arrayValueSeparator","mapToObjects","data","schema","options","_objectSpread","_options","rowIndexSourceMapOriginal","rowIndexSourceMap","schemaTransformOptions","_objectWithoutProperties","_excluded","slice","validateSchema","transpose","filter","row","i","isEmptyRow","every","cell","splice","columns","results","errors","length","result","read","push","_iterator","_createForOfIteratorHelperLoose","_step","done","error","value","rows","rowIndex","path","object","isEmptyObject","createError","_ref","schemaEntry","errorMessage","reason","column","type","pendingRequiredChecks","_loop","key","_Object$keys","_i","propertyName","columnTitle","propertyPath","concat","cellValue","columnIndex","indexOf","isMissingColumn","Array","isArray","array","parseArray","map","_value","parseValue","isEmpty","isEmptyValue","required","Object","keys","_i2","_pendingRequiredCheck","_pendingRequiredCheck2","skipRequiredValidation","isRequired","parse","Error","parseValueOfType","oneOf","validate","message","parseCustomValue","parsedValue","String","Number","Date","properties","Boolean","name","getBlock","string","endCharacter","startIndex","substring","character","block","blocks","index","_getBlock","_getBlock2","_slicedToArray","trim","_","_i3","_Object$keys2","_typeof"],"sources":["../../../source/read/schema/mapToObjects.js"],"sourcesContent":["import NumberType from '../../types/Number.js'\r\nimport StringType from '../../types/String.js'\r\nimport BooleanType from '../../types/Boolean.js'\r\nimport DateType from '../../types/Date.js'\r\n\r\nconst DEFAULT_OPTIONS = {\r\n schemaPropertyValueForMissingColumn: undefined,\r\n schemaPropertyValueForMissingValue: null,\r\n schemaPropertyShouldSkipRequiredValidationForMissingColumn: () => false,\r\n // `getEmptyObjectValue(object, { path })` applies to both the top-level object\r\n // and any of its sub-objects.\r\n getEmptyObjectValue: () => null,\r\n getEmptyArrayValue: () => null,\r\n isColumnOriented: false,\r\n ignoreEmptyRows: true,\r\n arrayValueSeparator: ','\r\n}\r\n\r\n/**\r\n * Converts spreadsheet-alike data structure into an array of objects.\r\n *\r\n * Parameters:\r\n *\r\n * * `data` — An array of rows, each row being an array of cells. The first row should be the list of column headers and the rest of the rows should be the data.\r\n * * `schema` — A \"to JSON\" convertion schema (see above).\r\n * * `options` — (optional) Schema conversion parameters of `read-excel-file`:\r\n * * `schemaPropertyValueForMissingColumn` — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * * `schemaPropertyValueForNullCellValue` — By default, when it encounters a `null` value in a cell in input `data`, it sets it to `undefined` in the output object. Pass `schemaPropertyValueForNullCellValue: null` to make it set such values as `null`s in output objects.\r\n * * `schemaPropertyValueForUndefinedCellValue` — By default, when it encounters an `undefined` value in a cell in input `data`, it it sets it to `undefined` in the output object. Pass `schemaPropertyValueForUndefinedCellValue: null` to make it set such values as `null`s in output objects.\r\n * * `schemaPropertyShouldSkipRequiredValidationForMissingColumn: (column: string, { object }) => boolean` — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * * `getEmptyObjectValue(object, { path? })` — By default, it returns `null` for \"empty\" objects. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional (optional) `path?: string` parameter.\r\n * * `getEmptyArrayValue(array, { path })` — By default, it returns `null` for an \"empty\" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.\r\n *\r\n * When parsing a property value, in case of an error, the value of that property is gonna be `undefined`.\r\n *\r\n * @param {any[][]} data - An array of rows, each row being an array of cells.\r\n * @param {object} schema\r\n * @param {object} [options]\r\n * @param {null} [options.schemaPropertyValueForMissingColumn] — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * @param {null} [options.schemaPropertyValueForMissingValue] — By default, when it encounters a `null` value in a cell in input `data`, it leaves the value as is. Pass a custom `schemaPropertyValueForMissingValue` to make it set such values to that value.\r\n * @param {object} [options.properties] — An optional object with optional property `epoch1904: true/false`. It is used when parsing dates.\r\n * @param {boolean} [options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(column: string, { object })] — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * @param {function} [options.getEmptyObjectValue(object, { path })] — By default, it returns `null` for an \"empty\" resulting object. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional `path?: string` parameter.\r\n * @param {function} [getEmptyArrayValue(array, { path })] — By default, it returns `null` for an \"empty\" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.\r\n * @param {boolean} [options.isColumnOriented] — By default, the headers are assumed to be the first row in the `data`. Pass `isColumnOriented: true` if the headers are the first column in the `data`. i.e. if `data` is \"transposed\".\r\n * @param {string} [options.arrayValueSeparator] — When specified, string values will be split by this separator to get the array.\r\n * @param {object} [options.rowIndexSourceMap] — Custom row indexes of `data` rows. If present, will overwrite the indexes of `data` rows with the indexes from this `rowIndexSourceMap`.\r\n * @return {object[]}\r\n */\r\nexport default function mapToObjects(data, schema, options) {\r\n if (options) {\r\n options = {\r\n ...DEFAULT_OPTIONS,\r\n ...options\r\n }\r\n } else {\r\n options = DEFAULT_OPTIONS\r\n }\r\n\r\n const {\r\n isColumnOriented,\r\n ignoreEmptyRows,\r\n rowIndexSourceMap: rowIndexSourceMapOriginal,\r\n ...schemaTransformOptions\r\n } = options\r\n\r\n // `rowIndexSourceMap` could be mutated by `ignoreEmptyRows: true` option.\r\n // Create a copy of it so that the original `rowIndexSourceMap` is not affected by those changes.\r\n let rowIndexSourceMap = rowIndexSourceMapOriginal && rowIndexSourceMapOriginal.slice()\r\n\r\n validateSchema(schema)\r\n\r\n if (isColumnOriented) {\r\n data = transpose(data)\r\n }\r\n\r\n\tif (ignoreEmptyRows) {\r\n\t\tdata = data.filter((row, i) => {\r\n const isEmptyRow = row.every(cell => cell === null)\r\n if (isEmptyRow) {\r\n // Adjust `rowIndexSourceMap` now that the row has been removed.\r\n if (rowIndexSourceMap) {\r\n // Remove the `rowIndexSourceMap` entry that corresponds to the removed row.\r\n rowIndexSourceMap.splice(i, 1)\r\n }\r\n return false;\r\n }\r\n return true;\r\n })\r\n\t}\r\n\r\n const columns = data[0]\r\n\r\n const results = []\r\n const errors = []\r\n\r\n for (let i = 1; i < data.length; i++) {\r\n const result = read(schema, data[i], i, undefined, columns, errors, schemaTransformOptions)\r\n results.push(result)\r\n }\r\n\r\n // Set the correct `row` number in `errors` if a custom `rowIndexSourceMap` is supplied.\r\n if (rowIndexSourceMap) {\r\n for (const error of errors) {\r\n // Convert the `row` index in `data` to the\r\n // actual `row` index in the spreadsheet.\r\n // `- 1` converts row number to row index.\r\n // `+ 1` converts row index to row number.\r\n error.row = rowIndexSourceMap[error.row - 1] + 1\r\n }\r\n }\r\n\r\n return {\r\n rows: results,\r\n errors\r\n }\r\n}\r\n\r\nfunction read(schema, row, rowIndex, path, columns, errors, options) {\r\n const object = {}\r\n let isEmptyObject = true\r\n\r\n const createError = ({\r\n schemaEntry,\r\n value,\r\n error: errorMessage,\r\n reason\r\n }) => {\r\n const error = {\r\n error: errorMessage,\r\n row: rowIndex + 1,\r\n column: schemaEntry.column,\r\n value\r\n }\r\n if (reason) {\r\n error.reason = reason\r\n }\r\n // * Regular values specify a `type?` property, which is included in the `error` object.\r\n // * Nested objects specify a `schema` property, which is not included in the `error` object.\r\n if (schemaEntry.type) {\r\n error.type = schemaEntry.type\r\n }\r\n return error\r\n }\r\n\r\n const pendingRequiredChecks = []\r\n\r\n // For each schema entry.\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n\r\n // `schemaEntry.prop` property is now deprecated and shouldn't be used.\r\n // Instead, it now uses `key` as the key in the `object`.\r\n // And column name is now read not from `key` but from `schemaEntry.column` property.\r\n const propertyName = key\r\n const columnTitle = schemaEntry.column\r\n\r\n // The path of this property inside the resulting object.\r\n const propertyPath = `${path || ''}.${propertyName}`\r\n\r\n // Read the cell value for the schema entry.\r\n let cellValue\r\n const columnIndex = columns.indexOf(columnTitle)\r\n const isMissingColumn = columnIndex < 0\r\n if (!isMissingColumn) {\r\n cellValue = row[columnIndex]\r\n }\r\n\r\n let value\r\n let error\r\n let reason\r\n\r\n // Get property `value` from cell value.\r\n if (schemaEntry.schema) {\r\n value = read(schemaEntry.schema, row, rowIndex, propertyPath, columns, errors, options)\r\n } else {\r\n if (isMissingColumn) {\r\n if ('schemaPropertyValueForMissingColumn' in options) {\r\n value = options.schemaPropertyValueForMissingColumn\r\n }\r\n }\r\n else if (cellValue === undefined) {\r\n // This isn't supposed to be possible. Cell values are always `null` when cells are empty.\r\n // Employ some sensible fallback behavior here.\r\n if ('schemaPropertyValueForMissingValue' in options) {\r\n value = options.schemaPropertyValueForMissingValue\r\n }\r\n }\r\n else if (cellValue === null) {\r\n if ('schemaPropertyValueForMissingValue' in options) {\r\n value = options.schemaPropertyValueForMissingValue\r\n }\r\n }\r\n else if (Array.isArray(schemaEntry.type)) {\r\n const array = parseArray(cellValue, options.arrayValueSeparator).map((_value) => {\r\n if (error) {\r\n return\r\n }\r\n const result = parseValue(_value, schemaEntry, options)\r\n if (result.error) {\r\n // In case of an error, `value` won't be returned and will just be reported\r\n // as part of an `error` object, so it's fine assigning just an element of the array.\r\n value = _value\r\n error = result.error\r\n reason = result.reason\r\n }\r\n return result.value\r\n })\r\n if (!error) {\r\n const isEmpty = array.every(isEmptyValue)\r\n value = isEmpty ? options.getEmptyArrayValue(array, { path: propertyPath }) : array\r\n }\r\n } else {\r\n const result = parseValue(cellValue, schemaEntry, options)\r\n error = result.error\r\n reason = result.reason\r\n value = error ? cellValue : result.value\r\n }\r\n }\r\n\r\n // Apply `required` validation if the value is \"empty\".\r\n if (!error && isEmptyValue(value)) {\r\n if (schemaEntry.required) {\r\n // Will perform this `required()` validation in the end,\r\n // when all properties of the mapped object have been mapped.\r\n pendingRequiredChecks.push({ schemaEntry, value, isMissingColumn })\r\n }\r\n }\r\n\r\n if (error) {\r\n // If there was an error then the property value in the `object` will be `undefined`,\r\n // i.e it won't add the property value to the mapped object.\r\n errors.push(createError({\r\n schemaEntry,\r\n value,\r\n error,\r\n reason\r\n }))\r\n } else {\r\n // Possibly unmark the mapped object as \"empty\".\r\n if (isEmptyObject && !isEmptyValue(value)) {\r\n isEmptyObject = false\r\n }\r\n // Set the value in the mapped object.\r\n // Skip setting `undefined` values because they're already `undefined`\r\n // due to not having previously been set.\r\n if (value !== undefined) {\r\n object[propertyName] = value\r\n }\r\n }\r\n }\r\n\r\n // Return `null` for an \"empty\" mapped object.\r\n if (isEmptyObject) {\r\n return options.getEmptyObjectValue(object, { path })\r\n }\r\n\r\n // Perform any `required` validations.\r\n for (const { schemaEntry, value, isMissingColumn } of pendingRequiredChecks) {\r\n // Can optionally skip `required` validation for missing columns.\r\n const skipRequiredValidation = isMissingColumn && options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(schemaEntry.column, { object })\r\n if (!skipRequiredValidation) {\r\n const { required } = schemaEntry\r\n const isRequired = typeof required === 'boolean' ? required : required(object)\r\n if (isRequired) {\r\n errors.push(createError({\r\n schemaEntry,\r\n value,\r\n error: 'required'\r\n }))\r\n }\r\n }\r\n }\r\n\r\n // Return the mapped object.\r\n return object\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @return {{ value: any, error: string }}\r\n */\r\nexport function parseValue(value, schemaEntry, options) {\r\n if (value === null) {\r\n return { value: null }\r\n }\r\n let result\r\n if (schemaEntry.parse) {\r\n throw new Error('`schemaEntry.parse` property was renamed to `schemaEntry.type`')\r\n } else if (schemaEntry.type) {\r\n result = parseValueOfType(\r\n value,\r\n // Supports parsing array types.\r\n // See `parseArray()` function for more details.\r\n // Example `type`: String[]\r\n // Input: 'Barack Obama, \"String, with, colons\", Donald Trump'\r\n // Output: ['Barack Obama', 'String, with, colons', 'Donald Trump']\r\n Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type,\r\n options\r\n )\r\n } else {\r\n result = { value: value }\r\n // throw new Error('Invalid schema entry: no `type` specified:\\n\\n' + JSON.stringify(schemaEntry, null, 2))\r\n }\r\n // If errored then return the error.\r\n if (result.error) {\r\n return result\r\n }\r\n if (result.value !== null) {\r\n if (schemaEntry.oneOf && schemaEntry.oneOf.indexOf(result.value) < 0) {\r\n return { error: 'invalid', reason: 'unknown' }\r\n }\r\n if (schemaEntry.validate) {\r\n try {\r\n schemaEntry.validate(result.value)\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n }\r\n }\r\n return result\r\n}\r\n\r\n/**\r\n * Converts textual value to a custom value using supplied `.parse()`.\r\n * @param {any} value\r\n * @param {function} parse\r\n * @return {{ value: any, error: string }}\r\n */\r\nfunction parseCustomValue(value, parse) {\r\n try {\r\n const parsedValue = parse(value)\r\n if (parsedValue === undefined) {\r\n return { value: null }\r\n }\r\n return { value: parsedValue }\r\n } catch (error) {\r\n const result = { error: error.message }\r\n if (error.reason) {\r\n result.reason = error.reason;\r\n }\r\n return result\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {} type\r\n * @return {{ value: (string|number|Date|boolean), error: string, reason?: string }}\r\n */\r\nfunction parseValueOfType(value, type, options) {\r\n switch (type) {\r\n case String:\r\n return parseCustomValue(value, StringType)\r\n\r\n case Number:\r\n return parseCustomValue(value, NumberType)\r\n\r\n case Date:\r\n return parseCustomValue(value, (value) => DateType(value, { properties: options.properties }))\r\n\r\n case Boolean:\r\n return parseCustomValue(value, BooleanType)\r\n\r\n default:\r\n if (typeof type === 'function') {\r\n return parseCustomValue(value, type)\r\n }\r\n throw new Error(`Unsupported schema type: ${type && type.name || type}`)\r\n }\r\n}\r\n\r\nexport function getBlock(string, endCharacter, startIndex) {\r\n let i = 0\r\n let substring = ''\r\n let character\r\n while (startIndex + i < string.length) {\r\n const character = string[startIndex + i]\r\n if (character === endCharacter) {\r\n return [substring, i]\r\n }\r\n else if (character === '\"') {\r\n const block = getBlock(string, '\"', startIndex + i + 1)\r\n substring += block[0]\r\n i += '\"'.length + block[1] + '\"'.length\r\n }\r\n else {\r\n substring += character\r\n i++\r\n }\r\n }\r\n return [substring, i]\r\n}\r\n\r\n/**\r\n * Parses a string of comma-separated substrings into an array of substrings.\r\n * (the `export` is just for tests)\r\n * @param {string} string — A string of comma-separated substrings.\r\n * @return {string[]} An array of substrings.\r\n */\r\nexport function parseArray(string, arrayValueSeparator) {\r\n const blocks = []\r\n let index = 0\r\n while (index < string.length) {\r\n const [substring, length] = getBlock(string, arrayValueSeparator, index)\r\n index += length + arrayValueSeparator.length\r\n blocks.push(substring.trim())\r\n }\r\n return blocks\r\n}\r\n\r\n// Transpose a 2D array.\r\n// https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript\r\nconst transpose = array => array[0].map((_, i) => array.map(row => row[i]))\r\n\r\nfunction validateSchema(schema) {\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n // Validate that the `schema` is not using a deprecated `type: nestedSchema` format.\r\n if (typeof schemaEntry.type === 'object' && !Array.isArray(schemaEntry.type)) {\r\n throw new Error('When defining a nested schema, use a `schema` property instead of a `type` property')\r\n }\r\n // Validate that every property has a source `column` title specified for it.\r\n if (!schemaEntry.schema) {\r\n if (!schemaEntry.column) {\r\n throw new Error(`\"column\" not defined for schema entry \"${key}\".`)\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction isEmptyValue(value) {\r\n return value === undefined || value === null\r\n}"],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAOA,UAAU,MAAM,uBAAuB;AAC9C,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,OAAOC,WAAW,MAAM,wBAAwB;AAChD,OAAOC,QAAQ,MAAM,qBAAqB;AAE1C,IAAMC,eAAe,GAAG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