dtable-utils 0.0.3 → 4.2.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.
Files changed (152) hide show
  1. package/README.md +56 -5
  2. package/dist/index.js +1 -1
  3. package/es/cell-value-get/cell-value.js +250 -20
  4. package/es/cell-value-get/collaborator.js +16 -3
  5. package/es/cell-value-get/digital-sign.js +1 -1
  6. package/es/cell-value-get/duration.js +3 -3
  7. package/es/cell-value-get/geolocation.js +52 -30
  8. package/es/cell-value-get/long-text.js +1 -1
  9. package/es/cell-value-get/number.js +51 -19
  10. package/es/cell-value-get/option.js +33 -9
  11. package/es/cell-value-get/rate.js +11 -0
  12. package/es/cell-value-set/date.js +26 -0
  13. package/es/cell-value-set/number.js +53 -1
  14. package/es/color/column-color.js +437 -0
  15. package/es/color/gradient-color.js +100 -0
  16. package/es/color/row-color.js +289 -0
  17. package/es/column/{common.js → core.js} +2 -14
  18. package/es/column/date.js +1 -1
  19. package/es/column/number.js +1 -1
  20. package/es/column/option.js +143 -0
  21. package/es/common.js +23 -3
  22. package/es/constants/color.js +16 -0
  23. package/es/constants/column-permission.js +7 -0
  24. package/es/constants/column.js +127 -2
  25. package/es/constants/filter/index.js +5 -1
  26. package/es/constants/formula.js +2 -1
  27. package/es/constants/grid-header.js +6 -0
  28. package/es/constants/group.js +23 -0
  29. package/es/constants/limit.js +3 -0
  30. package/es/constants/reg.js +4 -0
  31. package/es/constants/row-color.js +11 -0
  32. package/es/constants/sort.js +11 -0
  33. package/es/date.js +1 -1
  34. package/es/filter/core.js +322 -0
  35. package/es/filter/filter-column/array.js +87 -0
  36. package/es/filter/filter-column/checkbox.js +14 -0
  37. package/es/filter/filter-column/collaborator.js +72 -0
  38. package/es/filter/filter-column/creator.js +59 -0
  39. package/es/filter/filter-column/date.js +102 -0
  40. package/es/filter/filter-column/digital-sign.js +29 -0
  41. package/es/filter/filter-column/file.js +27 -0
  42. package/es/filter/filter-column/formula.js +57 -0
  43. package/es/filter/filter-column/geolocation.js +58 -0
  44. package/es/filter/filter-column/link.js +20 -0
  45. package/es/filter/filter-column/long-text.js +28 -0
  46. package/es/filter/filter-column/multiple-select.js +64 -0
  47. package/es/filter/filter-column/number.js +97 -0
  48. package/es/filter/filter-column/single-select.js +45 -0
  49. package/es/filter/filter-column/text.js +60 -0
  50. package/es/filter/filter-row.js +233 -0
  51. package/es/group/core.js +116 -0
  52. package/es/group/group-row.js +402 -0
  53. package/es/index.js +63 -11
  54. package/es/link/core.js +78 -0
  55. package/es/number.js +21 -0
  56. package/es/row/core.js +180 -0
  57. package/es/sort/core.js +91 -0
  58. package/es/sort/sort-column/array.js +72 -0
  59. package/es/sort/sort-column/checkbox.js +22 -0
  60. package/es/sort/sort-column/collaborator.js +16 -0
  61. package/es/sort/sort-column/date.js +25 -0
  62. package/es/sort/sort-column/formula.js +49 -0
  63. package/es/sort/sort-column/link.js +32 -0
  64. package/es/sort/sort-column/multiple-select.js +45 -0
  65. package/es/sort/sort-column/number.js +31 -0
  66. package/es/sort/sort-column/single-select.js +36 -0
  67. package/es/sort/sort-column/text.js +69 -0
  68. package/es/sort/sort-row.js +110 -0
  69. package/es/table/column.js +27 -0
  70. package/es/table/core.js +14 -0
  71. package/es/table/row.js +25 -0
  72. package/es/validate/filter.js +1 -1
  73. package/es/validate/geolocation.js +5 -0
  74. package/es/view/core.js +134 -0
  75. package/es/view/formula.js +147 -0
  76. package/es/view/group.js +32 -0
  77. package/es/view/summaries.js +167 -0
  78. package/lib/cell-value-get/cell-value.js +254 -19
  79. package/lib/cell-value-get/collaborator.js +16 -2
  80. package/lib/cell-value-get/digital-sign.js +1 -1
  81. package/lib/cell-value-get/duration.js +3 -2
  82. package/lib/cell-value-get/geolocation.js +53 -30
  83. package/lib/cell-value-get/long-text.js +1 -1
  84. package/lib/cell-value-get/number.js +51 -18
  85. package/lib/cell-value-get/option.js +34 -8
  86. package/lib/cell-value-get/rate.js +15 -0
  87. package/lib/cell-value-set/date.js +30 -0
  88. package/lib/cell-value-set/number.js +53 -0
  89. package/lib/color/column-color.js +446 -0
  90. package/lib/color/gradient-color.js +110 -0
  91. package/lib/color/row-color.js +297 -0
  92. package/lib/column/{common.js → core.js} +1 -14
  93. package/lib/column/date.js +2 -2
  94. package/lib/column/number.js +3 -3
  95. package/lib/column/option.js +151 -0
  96. package/lib/common.js +27 -3
  97. package/lib/constants/color.js +20 -0
  98. package/lib/constants/column-permission.js +11 -0
  99. package/lib/constants/column.js +134 -1
  100. package/lib/constants/filter/index.js +5 -0
  101. package/lib/constants/formula.js +2 -0
  102. package/lib/constants/grid-header.js +10 -0
  103. package/lib/constants/group.js +36 -0
  104. package/lib/constants/limit.js +7 -0
  105. package/lib/constants/reg.js +9 -0
  106. package/lib/constants/row-color.js +17 -0
  107. package/lib/constants/sort.js +18 -0
  108. package/lib/filter/core.js +336 -0
  109. package/lib/filter/filter-column/array.js +91 -0
  110. package/lib/filter/filter-column/checkbox.js +18 -0
  111. package/lib/filter/filter-column/collaborator.js +80 -0
  112. package/lib/filter/filter-column/creator.js +63 -0
  113. package/lib/filter/filter-column/date.js +106 -0
  114. package/lib/filter/filter-column/digital-sign.js +33 -0
  115. package/lib/filter/filter-column/file.js +31 -0
  116. package/lib/filter/filter-column/formula.js +61 -0
  117. package/lib/filter/filter-column/geolocation.js +62 -0
  118. package/lib/filter/filter-column/link.js +24 -0
  119. package/lib/filter/filter-column/long-text.js +32 -0
  120. package/lib/filter/filter-column/multiple-select.js +72 -0
  121. package/lib/filter/filter-column/number.js +101 -0
  122. package/lib/filter/filter-column/single-select.js +49 -0
  123. package/lib/filter/filter-column/text.js +64 -0
  124. package/lib/filter/filter-row.js +239 -0
  125. package/lib/group/core.js +126 -0
  126. package/lib/group/group-row.js +413 -0
  127. package/lib/index.js +177 -7
  128. package/lib/link/core.js +90 -0
  129. package/lib/number.js +26 -0
  130. package/lib/row/core.js +189 -0
  131. package/lib/sort/core.js +102 -0
  132. package/lib/sort/sort-column/array.js +76 -0
  133. package/lib/sort/sort-column/checkbox.js +26 -0
  134. package/lib/sort/sort-column/collaborator.js +20 -0
  135. package/lib/sort/sort-column/date.js +29 -0
  136. package/lib/sort/sort-column/formula.js +53 -0
  137. package/lib/sort/sort-column/link.js +36 -0
  138. package/lib/sort/sort-column/multiple-select.js +49 -0
  139. package/lib/sort/sort-column/number.js +35 -0
  140. package/lib/sort/sort-column/single-select.js +40 -0
  141. package/lib/sort/sort-column/text.js +74 -0
  142. package/lib/sort/sort-row.js +115 -0
  143. package/lib/table/column.js +32 -0
  144. package/lib/table/core.js +18 -0
  145. package/lib/table/row.js +30 -0
  146. package/lib/validate/filter.js +3 -3
  147. package/lib/validate/geolocation.js +9 -0
  148. package/lib/view/core.js +143 -0
  149. package/lib/view/formula.js +154 -0
  150. package/lib/view/group.js +36 -0
  151. package/lib/view/summaries.js +173 -0
  152. package/package.json +5 -3
@@ -1,6 +1,4 @@
1
- import { CellType } from '../constants/cell-type.js';
2
- import { COLLABORATOR_COLUMN_TYPES, DEFAULT_DATE_FORMAT } from '../constants/column.js';
3
- import { FORMULA_RESULT_TYPE } from '../constants/formula.js';
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
2
  import { DateUtils } from '../date.js';
5
3
  import { getCollaboratorsName } from './collaborator.js';
6
4
  import { getDateDisplayString } from './date.js';
@@ -10,9 +8,68 @@ import { getGeolocationDisplayString } from './geolocation.js';
10
8
  import { getLongtextDisplayString } from './long-text.js';
11
9
  import { getNumberDisplayString } from './number.js';
12
10
  import { getMultipleOptionName, getOptionName } from './option.js';
11
+ import { CellType } from '../constants/cell-type.js';
12
+ import { COLLABORATOR_COLUMN_TYPES, DEFAULT_DATE_FORMAT } from '../constants/column.js';
13
+ import { FORMULA_RESULT_TYPE } from '../constants/formula.js';
13
14
 
14
15
  var ARRAY_VALUE_COLUMN_TYPES = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
15
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
+ */
25
+ var _getArrayColumnCellValue = function _getArrayColumnCellValue(cellValue, column, _ref) {
26
+ var collaborators = _ref.collaborators,
27
+ isArchiveView = _ref.isArchiveView;
28
+ if (!Array.isArray(cellValue) || cellValue.length === 0 || !column.data) {
29
+ return '';
30
+ }
31
+ var key = column.key,
32
+ data = column.data;
33
+ var array_type = data.array_type,
34
+ array_data = data.array_data;
35
+ var newColumn = {
36
+ key: key,
37
+ type: array_type,
38
+ data: array_data
39
+ };
40
+ // cellValue itself is an array
41
+ if (ARRAY_VALUE_COLUMN_TYPES.includes(array_type)) {
42
+ return getCellValueStringResult(_defineProperty({}, key, cellValue), newColumn, {
43
+ collaborators: collaborators
44
+ });
45
+ }
46
+
47
+ // cellValue itself is a single value
48
+ if (array_type === CellType.STRING) {
49
+ newColumn.type = CellType.TEXT;
50
+ var _result = cellValue.map(function (item) {
51
+ return getCellValueStringResult(_defineProperty({}, key, item), newColumn);
52
+ });
53
+ return _result.filter(Boolean).join(', ');
54
+ }
55
+ if (array_type === CellType.BOOL) {
56
+ newColumn.type = CellType.CHECKBOX;
57
+ var _result2 = cellValue.map(function (item) {
58
+ return getCellValueStringResult(_defineProperty({}, key, item), newColumn);
59
+ });
60
+ return _result2.filter(Boolean).join(', ');
61
+ }
62
+ var result = cellValue.map(function (item) {
63
+ return getCellValueStringResult(_defineProperty({}, key, item), newColumn, {
64
+ collaborators: collaborators,
65
+ isArchiveView: isArchiveView
66
+ });
67
+ });
68
+ return result.filter(function (item) {
69
+ return item || item === 0;
70
+ }).join(', ');
71
+ };
72
+
16
73
  /**
17
74
  * Get formatted formula result to display. It will not be formatted
18
75
  * if formula result_type is array and array_type is collaborator, creator or last-modifier etc.
@@ -66,27 +123,27 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
66
123
 
67
124
  /**
68
125
  * Get formatted cell value to display.
69
- * @param {object} row e.g. { [column.key]: 'xxx' }
126
+ * @param {object} row e.g. { [column.key]: '' }
70
127
  * @param {string} type column type
71
128
  * @param {string} key column key
72
129
  * @param {object} data column data
73
130
  * @param {object} formulaRows formula results of rows. Default as "{}"
74
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]. Default as "[]"
131
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
75
132
  * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
76
133
  * @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
77
134
  * @returns formatted cell value, string|array
78
135
  */
79
136
  var getCellValueDisplayString = function getCellValueDisplayString(row, type, key) {
80
- var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
81
- data = _ref.data,
82
- _ref$formulaRows = _ref.formulaRows,
83
- formulaRows = _ref$formulaRows === void 0 ? {} : _ref$formulaRows,
84
- _ref$collaborators = _ref.collaborators,
85
- collaborators = _ref$collaborators === void 0 ? [] : _ref$collaborators,
86
- _ref$isBaiduMap = _ref.isBaiduMap,
87
- isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
88
- _ref$geolocationHyphe = _ref.geolocationHyphen,
89
- geolocationHyphen = _ref$geolocationHyphe === void 0 ? '' : _ref$geolocationHyphe;
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;
90
147
  if (!row) return '';
91
148
  var cellValue = row[key];
92
149
  switch (type) {
@@ -123,9 +180,9 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
123
180
  }
124
181
  case CellType.DATE:
125
182
  {
126
- var _ref2 = data || {},
127
- _ref2$format = _ref2.format,
128
- format = _ref2$format === void 0 ? DEFAULT_DATE_FORMAT : _ref2$format;
183
+ var _ref3 = data || {},
184
+ _ref3$format = _ref3.format,
185
+ format = _ref3$format === void 0 ? DEFAULT_DATE_FORMAT : _ref3$format;
129
186
  return getDateDisplayString(cellValue, format);
130
187
  }
131
188
  case CellType.CTIME:
@@ -145,7 +202,8 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
145
202
  case CellType.FORMULA:
146
203
  case CellType.LINK_FORMULA:
147
204
  {
148
- var formulaRow = formulaRows[row._id] || {};
205
+ var formulaRow = formulaRows && formulaRows[row._id];
206
+ if (!formulaRow) return '';
149
207
  return getFormulaDisplayString(formulaRow[key], data);
150
208
  }
151
209
  case CellType.DIGITAL_SIGN:
@@ -162,4 +220,176 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
162
220
  }
163
221
  };
164
222
 
165
- export { getCellValueDisplayString, getFormulaDisplayString };
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
+ */
232
+ var getCellValueStringResult = function getCellValueStringResult(row, column) {
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;
244
+ var cellValue = row[key];
245
+ switch (type) {
246
+ case CellType.TEXT:
247
+ case CellType.EMAIL:
248
+ case CellType.URL:
249
+ case CellType.AUTO_NUMBER:
250
+ {
251
+ return cellValue || '';
252
+ }
253
+ case CellType.RATE:
254
+ {
255
+ // number
256
+ return cellValue ? String(cellValue) : '';
257
+ }
258
+ case CellType.CHECKBOX:
259
+ {
260
+ if (typeof cellValue === 'boolean') {
261
+ return String(cellValue);
262
+ }
263
+ return cellValue === 'true' ? 'true' : 'false';
264
+ }
265
+ case CellType.LONG_TEXT:
266
+ {
267
+ // the data returned by archive view is a string, not a result in long-text format
268
+ if (isArchiveView) {
269
+ cellValue = {
270
+ text: cellValue
271
+ };
272
+ }
273
+ return getLongtextDisplayString(cellValue);
274
+ }
275
+ case CellType.NUMBER:
276
+ {
277
+ return getNumberDisplayString(cellValue, data);
278
+ }
279
+ case CellType.DURATION:
280
+ {
281
+ return getDurationDisplayString(cellValue, data);
282
+ }
283
+ case CellType.GEOLOCATION:
284
+ {
285
+ return getGeolocationDisplayString(cellValue, data);
286
+ }
287
+ case CellType.SINGLE_SELECT:
288
+ {
289
+ if (!data) return '';
290
+ return getOptionName(data.options, cellValue);
291
+ }
292
+ case CellType.MULTIPLE_SELECT:
293
+ {
294
+ if (!data) return '';
295
+ return getMultipleOptionName(data.options, cellValue);
296
+ }
297
+ case CellType.DATE:
298
+ {
299
+ var _ref5 = data || {},
300
+ _ref5$format = _ref5.format,
301
+ format = _ref5$format === void 0 ? DEFAULT_DATE_FORMAT : _ref5$format;
302
+ // patch: compatible with previous format
303
+ var normalizedFormat = format === 'D/M/YYYY' ? format.replace(/D\/M\/YYYY/, 'DD/MM/YYYY') : format;
304
+ return getDateDisplayString(cellValue, normalizedFormat);
305
+ }
306
+ case CellType.CTIME:
307
+ case CellType.MTIME:
308
+ {
309
+ return DateUtils.format(cellValue, 'YYYY-MM-DD HH:MM:SS');
310
+ }
311
+ case CellType.COLLABORATOR:
312
+ {
313
+ return getCollaboratorsName(collaborators, cellValue);
314
+ }
315
+ case CellType.CREATOR:
316
+ case CellType.LAST_MODIFIER:
317
+ {
318
+ return cellValue === 'anonymous' ? cellValue : getCollaboratorsName(collaborators, [cellValue]);
319
+ }
320
+ case CellType.LINK:
321
+ {
322
+ var computedCellValue = cellValue;
323
+ if (!isArchiveView) {
324
+ var formulaRow = formulaRows && formulaRows[row._id];
325
+ computedCellValue = formulaRow && formulaRow[key];
326
+ }
327
+ if (!Array.isArray(computedCellValue) || computedCellValue.length === 0) {
328
+ return '';
329
+ }
330
+ var displayCellValue = computedCellValue.map(function (linked) {
331
+ return linked.display_value;
332
+ });
333
+ var isTwoDimensionalArray = displayCellValue.some(function (item) {
334
+ return Array.isArray(item);
335
+ });
336
+ if (isTwoDimensionalArray) {
337
+ var result = displayCellValue.map(function (item) {
338
+ return _getArrayColumnCellValue(item, column, {
339
+ collaborators: collaborators,
340
+ isArchiveView: isArchiveView
341
+ });
342
+ });
343
+ return result.filter(Boolean).join(', ');
344
+ }
345
+ return _getArrayColumnCellValue(displayCellValue, column, {
346
+ collaborators: collaborators
347
+ });
348
+ }
349
+ case CellType.FORMULA:
350
+ case CellType.LINK_FORMULA:
351
+ {
352
+ var _computedCellValue = cellValue;
353
+ if (!isArchiveView) {
354
+ var _formulaRow = formulaRows && formulaRows[row._id];
355
+ _computedCellValue = _formulaRow && _formulaRow[key];
356
+ }
357
+ var result_type = data.result_type;
358
+ if (result_type === FORMULA_RESULT_TYPE.STRING) {
359
+ return _computedCellValue || '';
360
+ }
361
+ if (result_type === FORMULA_RESULT_TYPE.BOOL) {
362
+ if (typeof _computedCellValue === 'boolean') return String(_computedCellValue);
363
+ return _computedCellValue === 'true' ? 'true' : 'false';
364
+ }
365
+ if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
366
+ // data is stored in the data of the current column
367
+ return getNumberDisplayString(_computedCellValue, data);
368
+ }
369
+ if (result_type === FORMULA_RESULT_TYPE.DATE) {
370
+ // data is stored in the data of the current column
371
+ var _format = data.format;
372
+ return getDateDisplayString(_computedCellValue, _format);
373
+ }
374
+
375
+ // FORMULA_RESULT_TYPE.ARRAY
376
+ return _getArrayColumnCellValue(_computedCellValue, column, {
377
+ collaborators: collaborators,
378
+ isArchiveView: isArchiveView
379
+ });
380
+ }
381
+ case CellType.FILE:
382
+ case CellType.IMAGE:
383
+ case CellType.DIGITAL_SIGN:
384
+ case CellType.BUTTON:
385
+ {
386
+ return '';
387
+ }
388
+ default:
389
+ {
390
+ return cellValue ? String(cellValue) : '';
391
+ }
392
+ }
393
+ };
394
+
395
+ export { getCellValueDisplayString, getCellValueStringResult, getFormulaDisplayString };
@@ -1,7 +1,20 @@
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;
9
+ return collaborators.find(function (collaborator) {
10
+ return collaborator.email === email;
11
+ });
12
+ };
13
+
1
14
  /**
2
15
  * Get collaborators name list of given emails
3
16
  * @param {array} emails e.g. ['email', ...]
4
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
17
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
5
18
  * @returns name list, array. e.g. ['name1', 'name2']
6
19
  */
7
20
  var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators) {
@@ -20,7 +33,7 @@ var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators
20
33
 
21
34
  /**
22
35
  * Get concatenated collaborators names of given emails.
23
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
36
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
24
37
  * @param {array} emails e.g. ['email', ...]
25
38
  * @returns concatenated collaborators names, string. e.g. 'name1, name2'
26
39
  */
@@ -30,4 +43,4 @@ var getCollaboratorsName = function getCollaboratorsName(collaborators, emails)
30
43
  return collaboratorsNames.join(', ');
31
44
  };
32
45
 
33
- export { getCollaboratorsName, getCollaboratorsNames };
46
+ export { getCollaborator, getCollaboratorsName, getCollaboratorsNames };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Get signature image url to display
3
- * @param {object} digitalSign object, e.g. { sign_image_url: 'xxx' }
3
+ * @param {object} digitalSign object, e.g. { sign_image_url, ... }
4
4
  * @returns signature image url, string
5
5
  */
6
6
  var getDigitalSignImageUrl = function getDigitalSignImageUrl(digitalSign) {
@@ -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 { getDurationDecimalSuffix, getDurationDisplayString };
86
+ export { getDurationDecimalSuffix, getDurationDisplayString, getMathRoundedDuration };
@@ -1,11 +1,10 @@
1
- var isValidPosition = function isValidPosition(lng, lat) {
2
- return (lng || lng === 0) && (lat || lat === 0);
3
- };
1
+ import { GROUP_GEOLOCATION_GRANULARITY } from '../constants/group.js';
2
+ import { isValidPosition } from '../validate/geolocation.js';
4
3
 
5
4
  /**
6
5
  * Get formatted geolocation
7
6
  * @param {object} loc
8
- * @param {object} formats , e.g. { geo_format: 'xxx' }
7
+ * @param {object} formats , e.g. { geo_format, ... }
9
8
  * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
10
9
  * @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
11
10
  * @returns formatted geolocation, string
@@ -16,66 +15,89 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
16
15
  isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
17
16
  _ref$hyphen = _ref.hyphen,
18
17
  hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
19
- if (!loc) {
20
- return '';
21
- }
18
+ if (!loc) return '';
22
19
  var _ref2 = formats || {},
23
20
  geo_format = _ref2.geo_format;
24
21
  switch (geo_format) {
25
22
  case 'lng_lat':
26
23
  {
27
- var _ref3 = loc || {},
28
- lng = _ref3.lng,
29
- lat = _ref3.lat;
24
+ var lng = loc.lng,
25
+ lat = loc.lat;
30
26
  if (!isValidPosition(lng, lat)) return '';
31
27
  return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
32
28
  }
33
29
  case 'country_region':
34
30
  {
35
- var _ref4 = loc || {},
36
- country_region = _ref4.country_region;
31
+ var country_region = loc.country_region;
37
32
  return country_region || '';
38
33
  }
39
34
  case 'province':
40
35
  {
41
- var _ref5 = loc || {},
42
- province = _ref5.province;
36
+ var province = loc.province;
43
37
  return province || '';
44
38
  }
45
39
  case 'province_city':
46
40
  {
47
- var _ref6 = loc || {},
48
- _province = _ref6.province,
49
- city = _ref6.city;
41
+ var _province = loc.province,
42
+ city = loc.city;
50
43
  return "".concat(_province || '').concat(hyphen).concat(city || '').trim();
51
44
  }
52
45
  case 'province_city_district':
53
46
  {
54
- var _ref7 = loc || {},
55
- _province2 = _ref7.province,
56
- _city = _ref7.city,
57
- district = _ref7.district;
47
+ var _province2 = loc.province,
48
+ _city = loc.city,
49
+ district = loc.district;
58
50
  return "".concat(_province2 || '').concat(hyphen).concat(_city || '').concat(hyphen).concat(district || '').trim();
59
51
  }
60
52
  case 'map_selection':
61
53
  {
62
- var _ref8 = loc || {},
63
- address = _ref8.address,
64
- title = _ref8.title;
54
+ var address = loc.address,
55
+ title = loc.title;
65
56
  return "".concat(address || '').concat(hyphen).concat(title || '').trim();
66
57
  }
67
58
  default:
68
59
  {
69
60
  // default as 'geolocation'
70
- var _ref9 = loc || {},
71
- _province3 = _ref9.province,
72
- _city2 = _ref9.city,
73
- _district = _ref9.district,
74
- detail = _ref9.detail;
61
+ var _province3 = loc.province,
62
+ _city2 = loc.city,
63
+ _district = loc.district,
64
+ detail = loc.detail;
75
65
  if (!_province3 && !_city2 && !_district && !detail) return '';
76
66
  return "".concat(_province3 || '').concat(hyphen).concat(_city2 || '').concat(hyphen).concat(_district || '').concat(hyphen).concat(detail || '').trim();
77
67
  }
78
68
  }
79
69
  };
80
70
 
81
- export { getGeolocationDisplayString };
71
+ /**
72
+ * Get geolocation by granularity
73
+ * @param {object} geolocation e.g. { province, ... }
74
+ * @param {string} granularity
75
+ * @returns geolocation string
76
+ */
77
+ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocation, granularity) {
78
+ if (!geolocation) return '';
79
+ var province = geolocation.province,
80
+ city = geolocation.city,
81
+ district = geolocation.district,
82
+ country_region = geolocation.country_region;
83
+ switch (granularity) {
84
+ case GROUP_GEOLOCATION_GRANULARITY.CITY:
85
+ {
86
+ return city || '';
87
+ }
88
+ case GROUP_GEOLOCATION_GRANULARITY.DISTRICT:
89
+ {
90
+ return district || '';
91
+ }
92
+ case GROUP_GEOLOCATION_GRANULARITY.COUNTRY:
93
+ {
94
+ return country_region || '';
95
+ }
96
+ default:
97
+ {
98
+ return province || '';
99
+ }
100
+ }
101
+ };
102
+
103
+ export { getGeolocationByGranularity, getGeolocationDisplayString };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Get text from long-text to display.
3
- * @param {object} longText e.g. { text: 'xxx' }
3
+ * @param {object} longText e.g. { text, ... }
4
4
  * @returns text from long-text, string
5
5
  */
6
6
  var getLongtextDisplayString = function getLongtextDisplayString(longText) {
@@ -1,6 +1,7 @@
1
1
  import { NPminus as minus } from '../helper/number-precision/index.js';
2
- import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js';
3
2
  import { getDurationDisplayString } from './duration.js';
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,6 +9,37 @@ var separatorMap = {
8
9
  no: '',
9
10
  space: ' '
10
11
  };
12
+ var _getDecimalDigits = function _getDecimalDigits(number) {
13
+ if (Number.isInteger(number)) {
14
+ return 0;
15
+ }
16
+ var valueArr = String(number).split('.');
17
+ var digitsLength = valueArr[1] ? valueArr[1].length : 8;
18
+ return digitsLength > 8 ? 8 : digitsLength;
19
+ };
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 || {},
29
+ _ref$precision = _ref.precision,
30
+ precision = _ref$precision === void 0 ? 2 : _ref$precision,
31
+ _ref$enable_precision = _ref.enable_precision,
32
+ enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
33
+ var type = Object.prototype.toString.call(number);
34
+ if (type !== '[object Number]') {
35
+ if (type === '[object String]' && DISPLAY_INTERNAL_ERRORS.includes(number)) {
36
+ return number;
37
+ }
38
+ return null;
39
+ }
40
+ var decimalDigits = enable_precision ? precision : _getDecimalDigits(number);
41
+ return number.toFixed(decimalDigits);
42
+ };
11
43
 
12
44
  /**
13
45
  * removeZerosFromEnd('0.0100') // '0.01'
@@ -34,19 +66,19 @@ var getDecimalDigitsFromNumber = function getDecimalDigitsFromNumber(number) {
34
66
  var digitsLength = decimalPart ? decimalPart.length : 8;
35
67
  return digitsLength > 8 ? 8 : digitsLength;
36
68
  };
37
- var toThousands = function toThousands(number, _ref) {
38
- var formats = _ref.formats,
39
- _ref$isCurrency = _ref.isCurrency,
40
- isCurrency = _ref$isCurrency === void 0 ? true : _ref$isCurrency;
41
- var _ref2 = formats || {},
42
- _ref2$decimal = _ref2.decimal,
43
- decimal = _ref2$decimal === void 0 ? 'dot' : _ref2$decimal,
44
- _ref2$thousands = _ref2.thousands,
45
- thousands = _ref2$thousands === void 0 ? 'no' : _ref2$thousands,
46
- _ref2$precision = _ref2.precision,
47
- precision = _ref2$precision === void 0 ? 2 : _ref2$precision,
48
- _ref2$enable_precisio = _ref2.enable_precision,
49
- enable_precision = _ref2$enable_precisio === void 0 ? false : _ref2$enable_precisio;
69
+ var toThousands = function toThousands(number, _ref2) {
70
+ var formats = _ref2.formats,
71
+ _ref2$isCurrency = _ref2.isCurrency,
72
+ isCurrency = _ref2$isCurrency === void 0 ? true : _ref2$isCurrency;
73
+ var _ref3 = formats || {},
74
+ _ref3$decimal = _ref3.decimal,
75
+ decimal = _ref3$decimal === void 0 ? 'dot' : _ref3$decimal,
76
+ _ref3$thousands = _ref3.thousands,
77
+ thousands = _ref3$thousands === void 0 ? 'no' : _ref3$thousands,
78
+ _ref3$precision = _ref3.precision,
79
+ precision = _ref3$precision === void 0 ? 2 : _ref3$precision,
80
+ _ref3$enable_precisio = _ref3.enable_precision,
81
+ enable_precision = _ref3$enable_precisio === void 0 ? false : _ref3$enable_precisio;
50
82
 
51
83
  // handle numbers in scientific notation
52
84
  if (String(number).includes('e')) {
@@ -65,7 +97,7 @@ var toThousands = function toThousands(number, _ref) {
65
97
  }
66
98
  return numericString;
67
99
  }
68
- return number;
100
+ return String(number);
69
101
  }
70
102
  var decimalString = separatorMap[decimal];
71
103
  var thousandsString = separatorMap[thousands];
@@ -118,9 +150,9 @@ var getNumberDisplayString = function getNumberDisplayString(number, formats) {
118
150
  if (isNaN(number) || number === Infinity || number === -Infinity) return String(number);
119
151
 
120
152
  // formats: old version maybe 'null'
121
- var _ref3 = formats || {},
122
- _ref3$format = _ref3.format,
123
- format = _ref3$format === void 0 ? DEFAULT_NUMBER_FORMAT : _ref3$format;
153
+ var _ref4 = formats || {},
154
+ _ref4$format = _ref4.format,
155
+ format = _ref4$format === void 0 ? DEFAULT_NUMBER_FORMAT : _ref4$format;
124
156
  switch (format) {
125
157
  case 'number':
126
158
  {
@@ -219,4 +251,4 @@ var replaceNumberNotAllowInput = function replaceNumberNotAllowInput(sNum, forma
219
251
  }
220
252
  };
221
253
 
222
- export { getNumberDisplayString, replaceNumberNotAllowInput };
254
+ export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput };