dtable-utils 0.0.3-beta.1 → 0.0.4-beta.1

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.
Files changed (115) hide show
  1. package/README.md +12 -3
  2. package/dist/index.js +1 -1
  3. package/es/cell-value-get/cell-value.js +82 -60
  4. package/es/cell-value-get/collaborator.js +9 -2
  5. package/es/cell-value-get/duration.js +3 -3
  6. package/es/cell-value-get/geolocation.js +23 -25
  7. package/es/cell-value-get/number.js +19 -11
  8. package/es/cell-value-get/option.js +18 -4
  9. package/es/cell-value-get/rate.js +5 -0
  10. package/es/cell-value-set/date.js +9 -3
  11. package/es/{column/color.js → color/column-color.js} +25 -3
  12. package/es/{row/color.js → color/row-color.js} +12 -1
  13. package/es/column/option.js +37 -7
  14. package/es/common.js +23 -2
  15. package/es/constants/formula.js +2 -1
  16. package/es/filter/core.js +61 -26
  17. package/es/filter/filter-column/array.js +35 -30
  18. package/es/filter/filter-column/checkbox.js +9 -3
  19. package/es/filter/filter-column/collaborator.js +20 -15
  20. package/es/filter/filter-column/creator.js +22 -13
  21. package/es/filter/filter-column/date.js +57 -14
  22. package/es/filter/filter-column/digital-sign.js +11 -8
  23. package/es/filter/filter-column/file.js +9 -6
  24. package/es/filter/filter-column/formula.js +16 -8
  25. package/es/filter/filter-column/geolocation.js +12 -7
  26. package/es/filter/filter-column/link.js +10 -2
  27. package/es/filter/filter-column/long-text.js +10 -7
  28. package/es/filter/filter-column/multiple-select.js +17 -13
  29. package/es/filter/filter-column/number.js +25 -21
  30. package/es/filter/filter-column/single-select.js +14 -10
  31. package/es/filter/filter-column/text.js +18 -13
  32. package/es/filter/filter-row.js +35 -0
  33. package/es/group/core.js +15 -6
  34. package/es/group/group-row.js +39 -3
  35. package/es/index.js +10 -10
  36. package/es/link/core.js +14 -14
  37. package/es/number.js +11 -3
  38. package/es/row/core.js +20 -1
  39. package/es/sort/core.js +66 -7
  40. package/es/sort/sort-column/array.js +39 -30
  41. package/es/sort/sort-column/checkbox.js +12 -5
  42. package/es/sort/sort-column/collaborator.js +11 -4
  43. package/es/sort/sort-column/date.js +12 -12
  44. package/es/sort/sort-column/formula.js +21 -12
  45. package/es/sort/sort-column/link.js +18 -9
  46. package/es/sort/sort-column/multiple-select.js +26 -26
  47. package/es/sort/sort-column/number.js +15 -8
  48. package/es/sort/sort-column/single-select.js +16 -8
  49. package/es/sort/sort-column/text.js +24 -10
  50. package/es/sort/sort-row.js +22 -38
  51. package/es/table/column.js +2 -2
  52. package/es/table/core.js +2 -2
  53. package/es/table/row.js +4 -4
  54. package/es/view/core.js +20 -21
  55. package/es/view/formula.js +35 -31
  56. package/es/view/group.js +4 -4
  57. package/es/view/summaries.js +17 -29
  58. package/lib/cell-value-get/cell-value.js +82 -60
  59. package/lib/cell-value-get/collaborator.js +9 -2
  60. package/lib/cell-value-get/duration.js +4 -2
  61. package/lib/cell-value-get/geolocation.js +23 -25
  62. package/lib/cell-value-get/number.js +19 -11
  63. package/lib/cell-value-get/option.js +18 -4
  64. package/lib/cell-value-get/rate.js +5 -0
  65. package/lib/cell-value-set/date.js +9 -3
  66. package/lib/{column/color.js → color/column-color.js} +31 -9
  67. package/lib/{row/color.js → color/row-color.js} +12 -1
  68. package/lib/column/option.js +37 -7
  69. package/lib/common.js +23 -1
  70. package/lib/constants/formula.js +2 -0
  71. package/lib/filter/core.js +61 -26
  72. package/lib/filter/filter-column/array.js +35 -30
  73. package/lib/filter/filter-column/checkbox.js +9 -3
  74. package/lib/filter/filter-column/collaborator.js +20 -15
  75. package/lib/filter/filter-column/creator.js +22 -13
  76. package/lib/filter/filter-column/date.js +57 -14
  77. package/lib/filter/filter-column/digital-sign.js +11 -8
  78. package/lib/filter/filter-column/file.js +9 -6
  79. package/lib/filter/filter-column/formula.js +16 -8
  80. package/lib/filter/filter-column/geolocation.js +12 -7
  81. package/lib/filter/filter-column/link.js +10 -2
  82. package/lib/filter/filter-column/long-text.js +10 -7
  83. package/lib/filter/filter-column/multiple-select.js +17 -13
  84. package/lib/filter/filter-column/number.js +25 -21
  85. package/lib/filter/filter-column/single-select.js +14 -10
  86. package/lib/filter/filter-column/text.js +18 -13
  87. package/lib/filter/filter-row.js +35 -0
  88. package/lib/group/core.js +15 -6
  89. package/lib/group/group-row.js +39 -3
  90. package/lib/index.js +47 -45
  91. package/lib/link/core.js +14 -14
  92. package/lib/number.js +11 -3
  93. package/lib/row/core.js +20 -1
  94. package/lib/sort/core.js +71 -6
  95. package/lib/sort/sort-column/array.js +39 -30
  96. package/lib/sort/sort-column/checkbox.js +12 -5
  97. package/lib/sort/sort-column/collaborator.js +11 -4
  98. package/lib/sort/sort-column/date.js +12 -12
  99. package/lib/sort/sort-column/formula.js +21 -12
  100. package/lib/sort/sort-column/link.js +18 -9
  101. package/lib/sort/sort-column/multiple-select.js +25 -26
  102. package/lib/sort/sort-column/number.js +15 -8
  103. package/lib/sort/sort-column/single-select.js +16 -8
  104. package/lib/sort/sort-column/text.js +24 -10
  105. package/lib/sort/sort-row.js +21 -42
  106. package/lib/table/column.js +2 -2
  107. package/lib/table/core.js +2 -2
  108. package/lib/table/row.js +4 -4
  109. package/lib/view/core.js +20 -21
  110. package/lib/view/formula.js +35 -31
  111. package/lib/view/group.js +4 -4
  112. package/lib/view/summaries.js +17 -29
  113. package/package.json +1 -1
  114. package/es/table/index.js +0 -14
  115. package/lib/table/index.js +0 -18
@@ -13,24 +13,32 @@ import { COLLABORATOR_COLUMN_TYPES, DEFAULT_DATE_FORMAT } from '../constants/col
13
13
  import { FORMULA_RESULT_TYPE } from '../constants/formula.js';
14
14
 
15
15
  var ARRAY_VALUE_COLUMN_TYPES = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
16
+
17
+ /**
18
+ * the helper of 'getCellValueStringResult'
19
+ * @param {any} cellValue
20
+ * @param {object} column
21
+ * @param {array} collaborators
22
+ * @param {bool} isArchiveView
23
+ * @returns formatted array cell value, string
24
+ */
16
25
  var _getArrayColumnCellValue = function _getArrayColumnCellValue(cellValue, column, _ref) {
17
26
  var collaborators = _ref.collaborators,
18
27
  isArchiveView = _ref.isArchiveView;
19
- if (!cellValue || !Array.isArray(cellValue) || cellValue.length === 0) {
28
+ if (!Array.isArray(cellValue) || cellValue.length === 0 || !column.data) {
20
29
  return '';
21
30
  }
22
31
  var key = column.key,
23
32
  data = column.data;
24
- var _ref2 = data || {},
25
- array_type = _ref2.array_type,
26
- array_data = _ref2.array_data;
33
+ var array_type = data.array_type,
34
+ array_data = data.array_data;
27
35
  var newColumn = {
28
36
  key: key,
29
37
  type: array_type,
30
38
  data: array_data
31
39
  };
32
40
  // cellValue itself is an array
33
- if ([CellType.FILE, CellType.IMAGE, CellType.COLLABORATOR, CellType.MULTIPLE_SELECT].includes(array_type)) {
41
+ if (ARRAY_VALUE_COLUMN_TYPES.includes(array_type)) {
34
42
  return getCellValueStringResult(_defineProperty({}, key, cellValue), newColumn, {
35
43
  collaborators: collaborators
36
44
  });
@@ -126,16 +134,16 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
126
134
  * @returns formatted cell value, string|array
127
135
  */
128
136
  var getCellValueDisplayString = function getCellValueDisplayString(row, type, key) {
129
- var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
130
- data = _ref3.data,
131
- _ref3$formulaRows = _ref3.formulaRows,
132
- formulaRows = _ref3$formulaRows === void 0 ? {} : _ref3$formulaRows,
133
- _ref3$collaborators = _ref3.collaborators,
134
- collaborators = _ref3$collaborators === void 0 ? [] : _ref3$collaborators,
135
- _ref3$isBaiduMap = _ref3.isBaiduMap,
136
- isBaiduMap = _ref3$isBaiduMap === void 0 ? true : _ref3$isBaiduMap,
137
- _ref3$geolocationHyph = _ref3.geolocationHyphen,
138
- geolocationHyphen = _ref3$geolocationHyph === void 0 ? '' : _ref3$geolocationHyph;
137
+ var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
138
+ data = _ref2.data,
139
+ _ref2$formulaRows = _ref2.formulaRows,
140
+ formulaRows = _ref2$formulaRows === void 0 ? {} : _ref2$formulaRows,
141
+ _ref2$collaborators = _ref2.collaborators,
142
+ collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
143
+ _ref2$isBaiduMap = _ref2.isBaiduMap,
144
+ isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
145
+ _ref2$geolocationHyph = _ref2.geolocationHyphen,
146
+ geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
139
147
  if (!row) return '';
140
148
  var cellValue = row[key];
141
149
  switch (type) {
@@ -172,9 +180,9 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
172
180
  }
173
181
  case CellType.DATE:
174
182
  {
175
- var _ref4 = data || {},
176
- _ref4$format = _ref4.format,
177
- format = _ref4$format === void 0 ? DEFAULT_DATE_FORMAT : _ref4$format;
183
+ var _ref3 = data || {},
184
+ _ref3$format = _ref3.format,
185
+ format = _ref3$format === void 0 ? DEFAULT_DATE_FORMAT : _ref3$format;
178
186
  return getDateDisplayString(cellValue, format);
179
187
  }
180
188
  case CellType.CTIME:
@@ -194,7 +202,8 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
194
202
  case CellType.FORMULA:
195
203
  case CellType.LINK_FORMULA:
196
204
  {
197
- var formulaRow = formulaRows[row._id] || {};
205
+ var formulaRow = formulaRows && formulaRows[row._id];
206
+ if (!formulaRow) return '';
198
207
  return getFormulaDisplayString(formulaRow[key], data);
199
208
  }
200
209
  case CellType.DIGITAL_SIGN:
@@ -210,18 +219,28 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
210
219
  }
211
220
  }
212
221
  };
222
+
223
+ /**
224
+ * Format cell value to string
225
+ * @param {object} row { [column.key]: '', ... }
226
+ * @param {object} column
227
+ * @param {object} formulaRows formula results of rows. Default as "{}"
228
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
229
+ * @param {bool} isArchiveView If is archive view, get original cell value from "row", otherwise get cell value from "formulaRows"
230
+ * @returns formatted cell value, string
231
+ */
213
232
  var getCellValueStringResult = function getCellValueStringResult(row, column) {
214
- var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
215
- _ref5$formulaRows = _ref5.formulaRows,
216
- formulaRows = _ref5$formulaRows === void 0 ? {} : _ref5$formulaRows,
217
- _ref5$collaborators = _ref5.collaborators,
218
- collaborators = _ref5$collaborators === void 0 ? [] : _ref5$collaborators,
219
- _ref5$isArchiveView = _ref5.isArchiveView,
220
- isArchiveView = _ref5$isArchiveView === void 0 ? false : _ref5$isArchiveView;
221
- var _ref6 = column || {},
222
- key = _ref6.key,
223
- type = _ref6.type,
224
- data = _ref6.data;
233
+ var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
234
+ _ref4$formulaRows = _ref4.formulaRows,
235
+ formulaRows = _ref4$formulaRows === void 0 ? {} : _ref4$formulaRows,
236
+ _ref4$collaborators = _ref4.collaborators,
237
+ collaborators = _ref4$collaborators === void 0 ? [] : _ref4$collaborators,
238
+ _ref4$isArchiveView = _ref4.isArchiveView,
239
+ isArchiveView = _ref4$isArchiveView === void 0 ? false : _ref4$isArchiveView;
240
+ if (!row || !column) return '';
241
+ var key = column.key,
242
+ type = column.type,
243
+ data = column.data;
225
244
  var cellValue = row[key];
226
245
  switch (type) {
227
246
  case CellType.TEXT:
@@ -268,20 +287,18 @@ var getCellValueStringResult = function getCellValueStringResult(row, column) {
268
287
  case CellType.SINGLE_SELECT:
269
288
  {
270
289
  if (!data) return '';
271
- var options = data.options;
272
- return getOptionName(options, cellValue);
290
+ return getOptionName(data.options, cellValue);
273
291
  }
274
292
  case CellType.MULTIPLE_SELECT:
275
293
  {
276
294
  if (!data) return '';
277
- var _options2 = data.options;
278
- return getMultipleOptionName(_options2, cellValue);
295
+ return getMultipleOptionName(data.options, cellValue);
279
296
  }
280
297
  case CellType.DATE:
281
298
  {
282
- var _ref7 = data || {},
283
- _ref7$format = _ref7.format,
284
- format = _ref7$format === void 0 ? DEFAULT_DATE_FORMAT : _ref7$format;
299
+ var _ref5 = data || {},
300
+ _ref5$format = _ref5.format,
301
+ format = _ref5$format === void 0 ? DEFAULT_DATE_FORMAT : _ref5$format;
285
302
  // patch: compatible with previous format
286
303
  var normalizedFormat = format === 'D/M/YYYY' ? format.replace(/D\/M\/YYYY/, 'DD/MM/YYYY') : format;
287
304
  return getDateDisplayString(cellValue, normalizedFormat);
@@ -302,63 +319,68 @@ var getCellValueStringResult = function getCellValueStringResult(row, column) {
302
319
  }
303
320
  case CellType.LINK:
304
321
  {
322
+ var computedCellValue = cellValue;
305
323
  if (!isArchiveView) {
306
- var formulaRow = formulaRows[row._id] || {};
307
- cellValue = formulaRow[key];
324
+ var formulaRow = formulaRows && formulaRows[row._id];
325
+ computedCellValue = formulaRow && formulaRow[key];
326
+ }
327
+ if (!Array.isArray(computedCellValue) || computedCellValue.length === 0) {
328
+ return '';
308
329
  }
309
- if (!cellValue || !Array.isArray(cellValue) || cellValue.length === 0) return '';
310
- var newCellValue = cellValue.map(function (linked) {
330
+ var displayCellValue = computedCellValue.map(function (linked) {
311
331
  return linked.display_value;
312
332
  });
313
- var isTwoDimensionalArray = newCellValue.some(function (item) {
333
+ var isTwoDimensionalArray = displayCellValue.some(function (item) {
314
334
  return Array.isArray(item);
315
335
  });
316
- if (!isTwoDimensionalArray) {
317
- return _getArrayColumnCellValue(newCellValue, column, {
318
- collaborators: collaborators
336
+ if (isTwoDimensionalArray) {
337
+ var result = displayCellValue.map(function (item) {
338
+ return _getArrayColumnCellValue(item, column, {
339
+ collaborators: collaborators,
340
+ isArchiveView: isArchiveView
341
+ });
319
342
  });
343
+ return result.filter(Boolean).join(', ');
320
344
  }
321
- var result = newCellValue.map(function (item) {
322
- return _getArrayColumnCellValue(item, column, {
323
- collaborators: collaborators,
324
- isArchiveView: isArchiveView
325
- });
345
+ return _getArrayColumnCellValue(displayCellValue, column, {
346
+ collaborators: collaborators
326
347
  });
327
- return result.filter(Boolean).join(', ');
328
348
  }
329
349
  case CellType.FORMULA:
330
350
  case CellType.LINK_FORMULA:
331
351
  {
352
+ var _computedCellValue = cellValue;
332
353
  if (!isArchiveView) {
333
- var _formulaRow = formulaRows[row._id] || {};
334
- cellValue = _formulaRow[key];
354
+ var _formulaRow = formulaRows && formulaRows[row._id];
355
+ _computedCellValue = _formulaRow && _formulaRow[key];
335
356
  }
336
357
  var result_type = data.result_type;
337
358
  if (result_type === FORMULA_RESULT_TYPE.STRING) {
338
- return cellValue || '';
359
+ return _computedCellValue || '';
339
360
  }
340
361
  if (result_type === FORMULA_RESULT_TYPE.BOOL) {
341
- return [true, 'true'].includes(cellValue) ? 'true' : 'false';
362
+ if (typeof _computedCellValue === 'boolean') return String(_computedCellValue);
363
+ return _computedCellValue === 'true' ? 'true' : 'false';
342
364
  }
343
365
  if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
344
366
  // data is stored in the data of the current column
345
- return getNumberDisplayString(cellValue, data);
367
+ return getNumberDisplayString(_computedCellValue, data);
346
368
  }
347
369
  if (result_type === FORMULA_RESULT_TYPE.DATE) {
348
370
  // data is stored in the data of the current column
349
- var _ref8 = data || {},
350
- _format = _ref8.format;
351
- return getDateDisplayString(cellValue, _format);
371
+ var _format = data.format;
372
+ return getDateDisplayString(_computedCellValue, _format);
352
373
  }
353
374
 
354
375
  // FORMULA_RESULT_TYPE.ARRAY
355
- return _getArrayColumnCellValue(cellValue, column, {
376
+ return _getArrayColumnCellValue(_computedCellValue, column, {
356
377
  collaborators: collaborators,
357
378
  isArchiveView: isArchiveView
358
379
  });
359
380
  }
360
381
  case CellType.FILE:
361
382
  case CellType.IMAGE:
383
+ case CellType.DIGITAL_SIGN:
362
384
  case CellType.BUTTON:
363
385
  {
364
386
  return '';
@@ -1,6 +1,13 @@
1
- var getCollaborator = function getCollaborator(collaborators, collaboratorEmail) {
1
+ /**
2
+ * Get collaborator by email
3
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
4
+ * @param {string} email
5
+ * @returns collaborator, object
6
+ */
7
+ var getCollaborator = function getCollaborator(collaborators, email) {
8
+ if (!Array.isArray(collaborators) || !email) return null;
2
9
  return collaborators.find(function (collaborator) {
3
- return collaborator.email === collaboratorEmail;
10
+ return collaborator.email === email;
4
11
  });
5
12
  };
6
13
 
@@ -69,8 +69,8 @@ var getDurationDisplayString = function getDurationDisplayString(duration, forma
69
69
  }
70
70
  var decimalDigits = DURATION_DECIMAL_DIGITS[duration_format];
71
71
  var decimalSuffix = getDurationDecimalSuffix(duration_format, decimal);
72
- var hours = parseInt(positiveValue / 3600, 10);
73
- var minutes = parseInt((positiveValue - hours * 3600) / 60, 10);
72
+ var hours = parseInt(positiveValue / 3600);
73
+ var minutes = parseInt((positiveValue - hours * 3600) / 60);
74
74
  var displayString = duration < 0 ? '-' : '';
75
75
  if (duration_format === DURATION_FORMATS_MAP.H_MM) {
76
76
  displayString += "".concat(hours, ":").concat(minutes > 9 ? minutes : "0".concat(minutes));
@@ -83,4 +83,4 @@ var getDurationDisplayString = function getDurationDisplayString(duration, forma
83
83
  return displayString;
84
84
  };
85
85
 
86
- export { getDurationDisplayString };
86
+ export { getDurationDecimalSuffix, getDurationDisplayString, getMathRoundedDuration };
@@ -15,67 +15,65 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
15
15
  isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
16
16
  _ref$hyphen = _ref.hyphen,
17
17
  hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
18
- if (!loc) {
19
- return '';
20
- }
18
+ if (!loc) return '';
21
19
  var _ref2 = formats || {},
22
20
  geo_format = _ref2.geo_format;
23
21
  switch (geo_format) {
24
22
  case 'lng_lat':
25
23
  {
26
- var _ref3 = loc || {},
27
- lng = _ref3.lng,
28
- lat = _ref3.lat;
24
+ var lng = loc.lng,
25
+ lat = loc.lat;
29
26
  if (!isValidPosition(lng, lat)) return '';
30
27
  return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
31
28
  }
32
29
  case 'country_region':
33
30
  {
34
- var _ref4 = loc || {},
35
- country_region = _ref4.country_region;
31
+ var country_region = loc.country_region;
36
32
  return country_region || '';
37
33
  }
38
34
  case 'province':
39
35
  {
40
- var _ref5 = loc || {},
41
- province = _ref5.province;
36
+ var province = loc.province;
42
37
  return province || '';
43
38
  }
44
39
  case 'province_city':
45
40
  {
46
- var _ref6 = loc || {},
47
- _province = _ref6.province,
48
- city = _ref6.city;
41
+ var _province = loc.province,
42
+ city = loc.city;
49
43
  return "".concat(_province || '').concat(hyphen).concat(city || '').trim();
50
44
  }
51
45
  case 'province_city_district':
52
46
  {
53
- var _ref7 = loc || {},
54
- _province2 = _ref7.province,
55
- _city = _ref7.city,
56
- district = _ref7.district;
47
+ var _province2 = loc.province,
48
+ _city = loc.city,
49
+ district = loc.district;
57
50
  return "".concat(_province2 || '').concat(hyphen).concat(_city || '').concat(hyphen).concat(district || '').trim();
58
51
  }
59
52
  case 'map_selection':
60
53
  {
61
- var _ref8 = loc || {},
62
- address = _ref8.address,
63
- title = _ref8.title;
54
+ var address = loc.address,
55
+ title = loc.title;
64
56
  return "".concat(address || '').concat(hyphen).concat(title || '').trim();
65
57
  }
66
58
  default:
67
59
  {
68
60
  // default as 'geolocation'
69
- var _ref9 = loc || {},
70
- _province3 = _ref9.province,
71
- _city2 = _ref9.city,
72
- _district = _ref9.district,
73
- detail = _ref9.detail;
61
+ var _province3 = loc.province,
62
+ _city2 = loc.city,
63
+ _district = loc.district,
64
+ detail = loc.detail;
74
65
  if (!_province3 && !_city2 && !_district && !detail) return '';
75
66
  return "".concat(_province3 || '').concat(hyphen).concat(_city2 || '').concat(hyphen).concat(_district || '').concat(hyphen).concat(detail || '').trim();
76
67
  }
77
68
  }
78
69
  };
70
+
71
+ /**
72
+ * Get geolocation by granularity
73
+ * @param {object} geolocation e.g. { province, ... }
74
+ * @param {string} granularity
75
+ * @returns geolocation string
76
+ */
79
77
  var getGeolocationByGranularity = function getGeolocationByGranularity(geolocation, granularity) {
80
78
  if (!geolocation) return '';
81
79
  var province = geolocation.province,
@@ -1,6 +1,7 @@
1
1
  import { NPminus as minus } from '../helper/number-precision/index.js';
2
2
  import { getDurationDisplayString } from './duration.js';
3
3
  import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js';
4
+ import { DISPLAY_INTERNAL_ERRORS } from '../constants/formula.js';
4
5
 
5
6
  var separatorMap = {
6
7
  comma: ',',
@@ -8,29 +9,36 @@ var separatorMap = {
8
9
  no: '',
9
10
  space: ' '
10
11
  };
11
- var _getDecimalDigits = function _getDecimalDigits(num) {
12
- if (Number.isInteger(num)) {
12
+ var _getDecimalDigits = function _getDecimalDigits(number) {
13
+ if (Number.isInteger(number)) {
13
14
  return 0;
14
15
  }
15
- var valueArr = (num + '').split('.');
16
+ var valueArr = String(number).split('.');
16
17
  var digitsLength = valueArr[1] ? valueArr[1].length : 8;
17
18
  return digitsLength > 8 ? 8 : digitsLength;
18
19
  };
19
- var getPrecisionNumber = function getPrecisionNumber(num, formatData) {
20
- var _ref = formatData || {},
20
+
21
+ /**
22
+ * Get fixed number by precision
23
+ * @param {number} number
24
+ * @param {object} formats e.g. { enable_precision, precision, ... }
25
+ * @returns fixed number, string
26
+ */
27
+ var getPrecisionNumber = function getPrecisionNumber(number, formats) {
28
+ var _ref = formats || {},
21
29
  _ref$precision = _ref.precision,
22
30
  precision = _ref$precision === void 0 ? 2 : _ref$precision,
23
31
  _ref$enable_precision = _ref.enable_precision,
24
32
  enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
25
- var type = Object.prototype.toString.call(num);
33
+ var type = Object.prototype.toString.call(number);
26
34
  if (type !== '[object Number]') {
27
- if (type === '[object String]' && DISPLAY_INTERNAL_ERRORS.includes(num)) {
28
- return num;
35
+ if (type === '[object String]' && DISPLAY_INTERNAL_ERRORS.includes(number)) {
36
+ return number;
29
37
  }
30
38
  return null;
31
39
  }
32
- var decimalDigits = enable_precision ? precision : _getDecimalDigits(num);
33
- return num.toFixed(decimalDigits);
40
+ var decimalDigits = enable_precision ? precision : _getDecimalDigits(number);
41
+ return number.toFixed(decimalDigits);
34
42
  };
35
43
 
36
44
  /**
@@ -89,7 +97,7 @@ var toThousands = function toThousands(number, _ref2) {
89
97
  }
90
98
  return numericString;
91
99
  }
92
- return number;
100
+ return String(number);
93
101
  }
94
102
  var decimalString = separatorMap[decimal];
95
103
  var thousandsString = separatorMap[thousands];
@@ -1,14 +1,21 @@
1
1
  import { getColumnOptions } from '../column/option.js';
2
2
 
3
+ /**
4
+ * Get option by id
5
+ * @param {array} options e.g. [{ id, name, ... }]
6
+ * @param {string} optionId
7
+ * @returns option, object
8
+ */
3
9
  var getOption = function getOption(options, optionId) {
4
- return options.find(function (o) {
5
- return o.id === optionId;
10
+ if (!Array.isArray(options) || !optionId) return null;
11
+ return options.find(function (option) {
12
+ return option.id === optionId;
6
13
  });
7
14
  };
8
15
 
9
16
  /**
10
17
  * Get option name of the given id
11
- * @param {array} options e.g. [ { id: '', color: '', name: '' } ]
18
+ * @param {array} options e.g. [ { id, color, name, ... } ]
12
19
  * @param {string} targetOptionId option id
13
20
  * @returns option name, string
14
21
  */
@@ -17,6 +24,13 @@ var getOptionName = function getOptionName(options, targetOptionId) {
17
24
  var targetOption = getOption(options, targetOptionId);
18
25
  return targetOption ? targetOption.name : '';
19
26
  };
27
+
28
+ /**
29
+ * Get column option name by id
30
+ * @param {object} column e.g. { data: { options, ... }, ... }
31
+ * @param {string} optionId
32
+ * @returns option name, string
33
+ */
20
34
  var getColumnOptionNameById = function getColumnOptionNameById(column, optionId) {
21
35
  var options = getColumnOptions(column);
22
36
  return getOptionName(options, optionId);
@@ -24,7 +38,7 @@ var getColumnOptionNameById = function getColumnOptionNameById(column, optionId)
24
38
 
25
39
  /**
26
40
  * Get concatenated options names of given ids.
27
- * @param {array} options e.g. [ { id: '', color: '', name: '' }, ... ]
41
+ * @param {array} options e.g. [ { id, color, name, ... }, ... ]
28
42
  * @param {array} targetOptionsIds e.g. [ option.id, ... ]
29
43
  * @returns concatenated options names, string. e.g. 'name1, name2'
30
44
  */
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Get formatted rate
3
+ * @param {number} value
4
+ * @returns formatted rate
5
+ */
1
6
  var getRateDisplayString = function getRateDisplayString(value) {
2
7
  if (!value) return '';
3
8
  return String(value);
@@ -1,17 +1,23 @@
1
1
  import { DateUtils } from '../date.js';
2
2
  import { getFloatNumber } from './number.js';
3
3
 
4
+ /**
5
+ * Parse string to date
6
+ * @param {string} text
7
+ * @param {string} format default as "YYYY-MM-DD"
8
+ * @returns date, string
9
+ */
4
10
  var formatTextToDate = function formatTextToDate(text) {
5
- var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
11
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
6
12
  if (typeof text !== 'string' || !text.trim()) return null;
7
13
  var isAllNumber = /^[0-9]+$/.test(text);
8
14
  var dateObj = {};
9
15
  if (isAllNumber) {
10
16
  dateObj = new Date(getFloatNumber(text));
11
17
  } else {
12
- dateObj = DateUtils.parseDateWithFormat(text, dateFormat);
18
+ dateObj = DateUtils.parseDateWithFormat(text, format);
13
19
  }
14
- if (dateFormat.indexOf('HH:mm') < 0) {
20
+ if (format.indexOf('HH:mm') < 0) {
15
21
  return DateUtils.format(dateObj, 'YYYY-MM-DD') || null;
16
22
  }
17
23
  return DateUtils.format(dateObj, 'YYYY-MM-DD HH:MM') || null;
@@ -3,12 +3,12 @@ import deepCopy from 'deep-copy';
3
3
  import { deleteInvalidFilter, getFormattedFilters } from '../filter/core.js';
4
4
  import { filterRows, filterRow } from '../filter/filter-row.js';
5
5
  import { ValidateFilter } from '../validate/filter.js';
6
- import { isNumberColumn } from './number.js';
6
+ import { isNumberColumn } from '../column/number.js';
7
7
  import { getRowsByIds } from '../table/row.js';
8
8
  import { sortTableRows } from '../sort/sort-row.js';
9
9
  import { isTableRows } from '../row/core.js';
10
- import RowColorUtils from '../row/color.js';
11
- import GradientColorUtils from '../color/gradient-color.js';
10
+ import RowColorUtils from './row-color.js';
11
+ import GradientColorUtils from './gradient-color.js';
12
12
  import { CellType } from '../constants/cell-type.js';
13
13
  import '../constants/column.js';
14
14
  import { FILTER_CONJUNCTION_TYPE } from '../constants/filter/index.js';
@@ -242,6 +242,17 @@ var getFormattedColumn = function getFormattedColumn(column, view, table, value,
242
242
  dupColumn.gradientColorUtils = gradientColorUtils;
243
243
  return dupColumn;
244
244
  };
245
+
246
+ /**
247
+ * Calculate column color
248
+ * @param {array} rows
249
+ * @param {object} view
250
+ * @param {object} table e.g. { id_row_map, ... }
251
+ * @param {object} value e.g. { tables, collaborators, ... }
252
+ * @param {string} username
253
+ * @param {userId} username
254
+ * @returns column color, object
255
+ */
245
256
  var getColumnColors = function getColumnColors(rows, view, table, value) {
246
257
  var _ref5 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
247
258
  _ref5$username = _ref5.username,
@@ -353,6 +364,17 @@ var getColumnColors = function getColumnColors(rows, view, table, value) {
353
364
  }
354
365
  return column_colors;
355
366
  };
367
+
368
+ /**
369
+ * Update column color by updated rows.
370
+ * @param {array} rows updated rows | rows ids
371
+ * @param {object} view
372
+ * @param {object} table e.g. { id_row_map, ... }
373
+ * @param {object} value e.g. { tables, collaborators, ... }
374
+ * @param {string} username
375
+ * @param {userId} username
376
+ * @returns column color, object
377
+ */
356
378
  var updateColumnColorsByUpdateRows = function updateColumnColorsByUpdateRows(rows, view, table, value) {
357
379
  var _ref7 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
358
380
  _ref7$username = _ref7.username,
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { getTableColumnByKey } from '../table/column.js';
3
3
  import { getRowsByIds } from '../table/row.js';
4
- import { isTableRows } from './core.js';
4
+ import { isTableRows } from '../row/core.js';
5
5
  import { getColumnOptions } from '../column/option.js';
6
6
  import { getGeolocationDisplayString } from '../cell-value-get/geolocation.js';
7
7
  import { ValidateFilter } from '../validate/filter.js';
@@ -223,6 +223,17 @@ var getRowsColorByDuplicateValues = function getRowsColorByDuplicateValues(rows,
223
223
  duplicate_rows_ids_map: duplicate_rows_ids_map
224
224
  };
225
225
  };
226
+
227
+ /**
228
+ * Calculate rows color.
229
+ * @param {array} rows
230
+ * @param {object} view
231
+ * @param {object} table e.g. { id_row_map, ... }
232
+ * @param {object} value e.g. { tables, collaborators, ... }
233
+ * @param {string} username
234
+ * @param {userId} username
235
+ * @returns rows color, object
236
+ */
226
237
  var getRowsColor = function getRowsColor(rows, view, table, value) {
227
238
  var _ref5 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
228
239
  username = _ref5.username,