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
@@ -2,9 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var cellType = require('../constants/cell-type.js');
6
- var column = require('../constants/column.js');
7
- var formula = require('../constants/formula.js');
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
8
6
  var date$1 = require('../date.js');
9
7
  var collaborator = require('./collaborator.js');
10
8
  var date = require('./date.js');
@@ -14,9 +12,72 @@ var geolocation = require('./geolocation.js');
14
12
  var longText = require('./long-text.js');
15
13
  var number = require('./number.js');
16
14
  var option = require('./option.js');
15
+ var cellType = require('../constants/cell-type.js');
16
+ var column = require('../constants/column.js');
17
+ var formula = require('../constants/formula.js');
18
+
19
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
+
21
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
17
22
 
18
23
  var ARRAY_VALUE_COLUMN_TYPES = [cellType.CellType.IMAGE, cellType.CellType.FILE, cellType.CellType.MULTIPLE_SELECT, cellType.CellType.COLLABORATOR];
19
24
 
25
+ /**
26
+ * the helper of 'getCellValueStringResult'
27
+ * @param {any} cellValue
28
+ * @param {object} column
29
+ * @param {array} collaborators
30
+ * @param {bool} isArchiveView
31
+ * @returns formatted array cell value, string
32
+ */
33
+ var _getArrayColumnCellValue = function _getArrayColumnCellValue(cellValue, column, _ref) {
34
+ var collaborators = _ref.collaborators,
35
+ isArchiveView = _ref.isArchiveView;
36
+ if (!Array.isArray(cellValue) || cellValue.length === 0 || !column.data) {
37
+ return '';
38
+ }
39
+ var key = column.key,
40
+ data = column.data;
41
+ var array_type = data.array_type,
42
+ array_data = data.array_data;
43
+ var newColumn = {
44
+ key: key,
45
+ type: array_type,
46
+ data: array_data
47
+ };
48
+ // cellValue itself is an array
49
+ if (ARRAY_VALUE_COLUMN_TYPES.includes(array_type)) {
50
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, cellValue), newColumn, {
51
+ collaborators: collaborators
52
+ });
53
+ }
54
+
55
+ // cellValue itself is a single value
56
+ if (array_type === cellType.CellType.STRING) {
57
+ newColumn.type = cellType.CellType.TEXT;
58
+ var _result = cellValue.map(function (item) {
59
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, item), newColumn);
60
+ });
61
+ return _result.filter(Boolean).join(', ');
62
+ }
63
+ if (array_type === cellType.CellType.BOOL) {
64
+ newColumn.type = cellType.CellType.CHECKBOX;
65
+ var _result2 = cellValue.map(function (item) {
66
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, item), newColumn);
67
+ });
68
+ return _result2.filter(Boolean).join(', ');
69
+ }
70
+ var result = cellValue.map(function (item) {
71
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, item), newColumn, {
72
+ collaborators: collaborators,
73
+ isArchiveView: isArchiveView
74
+ });
75
+ });
76
+ return result.filter(function (item) {
77
+ return item || item === 0;
78
+ }).join(', ');
79
+ };
80
+
20
81
  /**
21
82
  * Get formatted formula result to display. It will not be formatted
22
83
  * if formula result_type is array and array_type is collaborator, creator or last-modifier etc.
@@ -70,27 +131,27 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
70
131
 
71
132
  /**
72
133
  * Get formatted cell value to display.
73
- * @param {object} row e.g. { [column.key]: 'xxx' }
134
+ * @param {object} row e.g. { [column.key]: '' }
74
135
  * @param {string} type column type
75
136
  * @param {string} key column key
76
137
  * @param {object} data column data
77
138
  * @param {object} formulaRows formula results of rows. Default as "{}"
78
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]. Default as "[]"
139
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
79
140
  * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
80
141
  * @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
81
142
  * @returns formatted cell value, string|array
82
143
  */
83
144
  var getCellValueDisplayString = function getCellValueDisplayString(row, type, key) {
84
- var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
85
- data = _ref.data,
86
- _ref$formulaRows = _ref.formulaRows,
87
- formulaRows = _ref$formulaRows === void 0 ? {} : _ref$formulaRows,
88
- _ref$collaborators = _ref.collaborators,
89
- collaborators = _ref$collaborators === void 0 ? [] : _ref$collaborators,
90
- _ref$isBaiduMap = _ref.isBaiduMap,
91
- isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
92
- _ref$geolocationHyphe = _ref.geolocationHyphen,
93
- geolocationHyphen = _ref$geolocationHyphe === void 0 ? '' : _ref$geolocationHyphe;
145
+ var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
146
+ data = _ref2.data,
147
+ _ref2$formulaRows = _ref2.formulaRows,
148
+ formulaRows = _ref2$formulaRows === void 0 ? {} : _ref2$formulaRows,
149
+ _ref2$collaborators = _ref2.collaborators,
150
+ collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
151
+ _ref2$isBaiduMap = _ref2.isBaiduMap,
152
+ isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
153
+ _ref2$geolocationHyph = _ref2.geolocationHyphen,
154
+ geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
94
155
  if (!row) return '';
95
156
  var cellValue = row[key];
96
157
  switch (type) {
@@ -127,9 +188,9 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
127
188
  }
128
189
  case cellType.CellType.DATE:
129
190
  {
130
- var _ref2 = data || {},
131
- _ref2$format = _ref2.format,
132
- format = _ref2$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref2$format;
191
+ var _ref3 = data || {},
192
+ _ref3$format = _ref3.format,
193
+ format = _ref3$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref3$format;
133
194
  return date.getDateDisplayString(cellValue, format);
134
195
  }
135
196
  case cellType.CellType.CTIME:
@@ -149,7 +210,8 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
149
210
  case cellType.CellType.FORMULA:
150
211
  case cellType.CellType.LINK_FORMULA:
151
212
  {
152
- var formulaRow = formulaRows[row._id] || {};
213
+ var formulaRow = formulaRows && formulaRows[row._id];
214
+ if (!formulaRow) return '';
153
215
  return getFormulaDisplayString(formulaRow[key], data);
154
216
  }
155
217
  case cellType.CellType.DIGITAL_SIGN:
@@ -166,5 +228,178 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
166
228
  }
167
229
  };
168
230
 
231
+ /**
232
+ * Format cell value to string
233
+ * @param {object} row { [column.key]: '', ... }
234
+ * @param {object} column
235
+ * @param {object} formulaRows formula results of rows. Default as "{}"
236
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
237
+ * @param {bool} isArchiveView If is archive view, get original cell value from "row", otherwise get cell value from "formulaRows"
238
+ * @returns formatted cell value, string
239
+ */
240
+ var getCellValueStringResult = function getCellValueStringResult(row, column$1) {
241
+ var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
242
+ _ref4$formulaRows = _ref4.formulaRows,
243
+ formulaRows = _ref4$formulaRows === void 0 ? {} : _ref4$formulaRows,
244
+ _ref4$collaborators = _ref4.collaborators,
245
+ collaborators = _ref4$collaborators === void 0 ? [] : _ref4$collaborators,
246
+ _ref4$isArchiveView = _ref4.isArchiveView,
247
+ isArchiveView = _ref4$isArchiveView === void 0 ? false : _ref4$isArchiveView;
248
+ if (!row || !column$1) return '';
249
+ var key = column$1.key,
250
+ type = column$1.type,
251
+ data = column$1.data;
252
+ var cellValue = row[key];
253
+ switch (type) {
254
+ case cellType.CellType.TEXT:
255
+ case cellType.CellType.EMAIL:
256
+ case cellType.CellType.URL:
257
+ case cellType.CellType.AUTO_NUMBER:
258
+ {
259
+ return cellValue || '';
260
+ }
261
+ case cellType.CellType.RATE:
262
+ {
263
+ // number
264
+ return cellValue ? String(cellValue) : '';
265
+ }
266
+ case cellType.CellType.CHECKBOX:
267
+ {
268
+ if (typeof cellValue === 'boolean') {
269
+ return String(cellValue);
270
+ }
271
+ return cellValue === 'true' ? 'true' : 'false';
272
+ }
273
+ case cellType.CellType.LONG_TEXT:
274
+ {
275
+ // the data returned by archive view is a string, not a result in long-text format
276
+ if (isArchiveView) {
277
+ cellValue = {
278
+ text: cellValue
279
+ };
280
+ }
281
+ return longText.getLongtextDisplayString(cellValue);
282
+ }
283
+ case cellType.CellType.NUMBER:
284
+ {
285
+ return number.getNumberDisplayString(cellValue, data);
286
+ }
287
+ case cellType.CellType.DURATION:
288
+ {
289
+ return duration.getDurationDisplayString(cellValue, data);
290
+ }
291
+ case cellType.CellType.GEOLOCATION:
292
+ {
293
+ return geolocation.getGeolocationDisplayString(cellValue, data);
294
+ }
295
+ case cellType.CellType.SINGLE_SELECT:
296
+ {
297
+ if (!data) return '';
298
+ return option.getOptionName(data.options, cellValue);
299
+ }
300
+ case cellType.CellType.MULTIPLE_SELECT:
301
+ {
302
+ if (!data) return '';
303
+ return option.getMultipleOptionName(data.options, cellValue);
304
+ }
305
+ case cellType.CellType.DATE:
306
+ {
307
+ var _ref5 = data || {},
308
+ _ref5$format = _ref5.format,
309
+ format = _ref5$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref5$format;
310
+ // patch: compatible with previous format
311
+ var normalizedFormat = format === 'D/M/YYYY' ? format.replace(/D\/M\/YYYY/, 'DD/MM/YYYY') : format;
312
+ return date.getDateDisplayString(cellValue, normalizedFormat);
313
+ }
314
+ case cellType.CellType.CTIME:
315
+ case cellType.CellType.MTIME:
316
+ {
317
+ return date$1.DateUtils.format(cellValue, 'YYYY-MM-DD HH:MM:SS');
318
+ }
319
+ case cellType.CellType.COLLABORATOR:
320
+ {
321
+ return collaborator.getCollaboratorsName(collaborators, cellValue);
322
+ }
323
+ case cellType.CellType.CREATOR:
324
+ case cellType.CellType.LAST_MODIFIER:
325
+ {
326
+ return cellValue === 'anonymous' ? cellValue : collaborator.getCollaboratorsName(collaborators, [cellValue]);
327
+ }
328
+ case cellType.CellType.LINK:
329
+ {
330
+ var computedCellValue = cellValue;
331
+ if (!isArchiveView) {
332
+ var formulaRow = formulaRows && formulaRows[row._id];
333
+ computedCellValue = formulaRow && formulaRow[key];
334
+ }
335
+ if (!Array.isArray(computedCellValue) || computedCellValue.length === 0) {
336
+ return '';
337
+ }
338
+ var displayCellValue = computedCellValue.map(function (linked) {
339
+ return linked.display_value;
340
+ });
341
+ var isTwoDimensionalArray = displayCellValue.some(function (item) {
342
+ return Array.isArray(item);
343
+ });
344
+ if (isTwoDimensionalArray) {
345
+ var result = displayCellValue.map(function (item) {
346
+ return _getArrayColumnCellValue(item, column$1, {
347
+ collaborators: collaborators,
348
+ isArchiveView: isArchiveView
349
+ });
350
+ });
351
+ return result.filter(Boolean).join(', ');
352
+ }
353
+ return _getArrayColumnCellValue(displayCellValue, column$1, {
354
+ collaborators: collaborators
355
+ });
356
+ }
357
+ case cellType.CellType.FORMULA:
358
+ case cellType.CellType.LINK_FORMULA:
359
+ {
360
+ var _computedCellValue = cellValue;
361
+ if (!isArchiveView) {
362
+ var _formulaRow = formulaRows && formulaRows[row._id];
363
+ _computedCellValue = _formulaRow && _formulaRow[key];
364
+ }
365
+ var result_type = data.result_type;
366
+ if (result_type === formula.FORMULA_RESULT_TYPE.STRING) {
367
+ return _computedCellValue || '';
368
+ }
369
+ if (result_type === formula.FORMULA_RESULT_TYPE.BOOL) {
370
+ if (typeof _computedCellValue === 'boolean') return String(_computedCellValue);
371
+ return _computedCellValue === 'true' ? 'true' : 'false';
372
+ }
373
+ if (result_type === formula.FORMULA_RESULT_TYPE.NUMBER) {
374
+ // data is stored in the data of the current column
375
+ return number.getNumberDisplayString(_computedCellValue, data);
376
+ }
377
+ if (result_type === formula.FORMULA_RESULT_TYPE.DATE) {
378
+ // data is stored in the data of the current column
379
+ var _format = data.format;
380
+ return date.getDateDisplayString(_computedCellValue, _format);
381
+ }
382
+
383
+ // FORMULA_RESULT_TYPE.ARRAY
384
+ return _getArrayColumnCellValue(_computedCellValue, column$1, {
385
+ collaborators: collaborators,
386
+ isArchiveView: isArchiveView
387
+ });
388
+ }
389
+ case cellType.CellType.FILE:
390
+ case cellType.CellType.IMAGE:
391
+ case cellType.CellType.DIGITAL_SIGN:
392
+ case cellType.CellType.BUTTON:
393
+ {
394
+ return '';
395
+ }
396
+ default:
397
+ {
398
+ return cellValue ? String(cellValue) : '';
399
+ }
400
+ }
401
+ };
402
+
169
403
  exports.getCellValueDisplayString = getCellValueDisplayString;
404
+ exports.getCellValueStringResult = getCellValueStringResult;
170
405
  exports.getFormulaDisplayString = getFormulaDisplayString;
@@ -2,10 +2,23 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ /**
6
+ * Get collaborator by email
7
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
8
+ * @param {string} email
9
+ * @returns collaborator, object
10
+ */
11
+ var getCollaborator = function getCollaborator(collaborators, email) {
12
+ if (!Array.isArray(collaborators) || !email) return null;
13
+ return collaborators.find(function (collaborator) {
14
+ return collaborator.email === email;
15
+ });
16
+ };
17
+
5
18
  /**
6
19
  * Get collaborators name list of given emails
7
20
  * @param {array} emails e.g. ['email', ...]
8
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
21
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
9
22
  * @returns name list, array. e.g. ['name1', 'name2']
10
23
  */
11
24
  var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators) {
@@ -24,7 +37,7 @@ var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators
24
37
 
25
38
  /**
26
39
  * Get concatenated collaborators names of given emails.
27
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
40
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
28
41
  * @param {array} emails e.g. ['email', ...]
29
42
  * @returns concatenated collaborators names, string. e.g. 'name1, name2'
30
43
  */
@@ -34,5 +47,6 @@ var getCollaboratorsName = function getCollaboratorsName(collaborators, emails)
34
47
  return collaboratorsNames.join(', ');
35
48
  };
36
49
 
50
+ exports.getCollaborator = getCollaborator;
37
51
  exports.getCollaboratorsName = getCollaboratorsName;
38
52
  exports.getCollaboratorsNames = getCollaboratorsNames;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  /**
6
6
  * Get signature image url to display
7
- * @param {object} digitalSign object, e.g. { sign_image_url: 'xxx' }
7
+ * @param {object} digitalSign object, e.g. { sign_image_url, ... }
8
8
  * @returns signature image url, string
9
9
  */
10
10
  var getDigitalSignImageUrl = function getDigitalSignImageUrl(digitalSign) {
@@ -73,8 +73,8 @@ var getDurationDisplayString = function getDurationDisplayString(duration, forma
73
73
  }
74
74
  var decimalDigits = column.DURATION_DECIMAL_DIGITS[duration_format];
75
75
  var decimalSuffix = getDurationDecimalSuffix(duration_format, decimal);
76
- var hours = parseInt(positiveValue / 3600, 10);
77
- var minutes = parseInt((positiveValue - hours * 3600) / 60, 10);
76
+ var hours = parseInt(positiveValue / 3600);
77
+ var minutes = parseInt((positiveValue - hours * 3600) / 60);
78
78
  var displayString = duration < 0 ? '-' : '';
79
79
  if (duration_format === column.DURATION_FORMATS_MAP.H_MM) {
80
80
  displayString += "".concat(hours, ":").concat(minutes > 9 ? minutes : "0".concat(minutes));
@@ -89,3 +89,4 @@ var getDurationDisplayString = function getDurationDisplayString(duration, forma
89
89
 
90
90
  exports.getDurationDecimalSuffix = getDurationDecimalSuffix;
91
91
  exports.getDurationDisplayString = getDurationDisplayString;
92
+ exports.getMathRoundedDuration = getMathRoundedDuration;
@@ -2,14 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var isValidPosition = function isValidPosition(lng, lat) {
6
- return (lng || lng === 0) && (lat || lat === 0);
7
- };
5
+ var group = require('../constants/group.js');
6
+ var geolocation = require('../validate/geolocation.js');
8
7
 
9
8
  /**
10
9
  * Get formatted geolocation
11
10
  * @param {object} loc
12
- * @param {object} formats , e.g. { geo_format: 'xxx' }
11
+ * @param {object} formats , e.g. { geo_format, ... }
13
12
  * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
14
13
  * @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
15
14
  * @returns formatted geolocation, string
@@ -20,66 +19,90 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
20
19
  isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
21
20
  _ref$hyphen = _ref.hyphen,
22
21
  hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
23
- if (!loc) {
24
- return '';
25
- }
22
+ if (!loc) return '';
26
23
  var _ref2 = formats || {},
27
24
  geo_format = _ref2.geo_format;
28
25
  switch (geo_format) {
29
26
  case 'lng_lat':
30
27
  {
31
- var _ref3 = loc || {},
32
- lng = _ref3.lng,
33
- lat = _ref3.lat;
34
- if (!isValidPosition(lng, lat)) return '';
28
+ var lng = loc.lng,
29
+ lat = loc.lat;
30
+ if (!geolocation.isValidPosition(lng, lat)) return '';
35
31
  return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
36
32
  }
37
33
  case 'country_region':
38
34
  {
39
- var _ref4 = loc || {},
40
- country_region = _ref4.country_region;
35
+ var country_region = loc.country_region;
41
36
  return country_region || '';
42
37
  }
43
38
  case 'province':
44
39
  {
45
- var _ref5 = loc || {},
46
- province = _ref5.province;
40
+ var province = loc.province;
47
41
  return province || '';
48
42
  }
49
43
  case 'province_city':
50
44
  {
51
- var _ref6 = loc || {},
52
- _province = _ref6.province,
53
- city = _ref6.city;
45
+ var _province = loc.province,
46
+ city = loc.city;
54
47
  return "".concat(_province || '').concat(hyphen).concat(city || '').trim();
55
48
  }
56
49
  case 'province_city_district':
57
50
  {
58
- var _ref7 = loc || {},
59
- _province2 = _ref7.province,
60
- _city = _ref7.city,
61
- district = _ref7.district;
51
+ var _province2 = loc.province,
52
+ _city = loc.city,
53
+ district = loc.district;
62
54
  return "".concat(_province2 || '').concat(hyphen).concat(_city || '').concat(hyphen).concat(district || '').trim();
63
55
  }
64
56
  case 'map_selection':
65
57
  {
66
- var _ref8 = loc || {},
67
- address = _ref8.address,
68
- title = _ref8.title;
58
+ var address = loc.address,
59
+ title = loc.title;
69
60
  return "".concat(address || '').concat(hyphen).concat(title || '').trim();
70
61
  }
71
62
  default:
72
63
  {
73
64
  // default as 'geolocation'
74
- var _ref9 = loc || {},
75
- _province3 = _ref9.province,
76
- _city2 = _ref9.city,
77
- _district = _ref9.district,
78
- detail = _ref9.detail;
65
+ var _province3 = loc.province,
66
+ _city2 = loc.city,
67
+ _district = loc.district,
68
+ detail = loc.detail;
79
69
  if (!_province3 && !_city2 && !_district && !detail) return '';
80
70
  return "".concat(_province3 || '').concat(hyphen).concat(_city2 || '').concat(hyphen).concat(_district || '').concat(hyphen).concat(detail || '').trim();
81
71
  }
82
72
  }
83
73
  };
84
74
 
75
+ /**
76
+ * Get geolocation by granularity
77
+ * @param {object} geolocation e.g. { province, ... }
78
+ * @param {string} granularity
79
+ * @returns geolocation string
80
+ */
81
+ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocation, granularity) {
82
+ if (!geolocation) return '';
83
+ var province = geolocation.province,
84
+ city = geolocation.city,
85
+ district = geolocation.district,
86
+ country_region = geolocation.country_region;
87
+ switch (granularity) {
88
+ case group.GROUP_GEOLOCATION_GRANULARITY.CITY:
89
+ {
90
+ return city || '';
91
+ }
92
+ case group.GROUP_GEOLOCATION_GRANULARITY.DISTRICT:
93
+ {
94
+ return district || '';
95
+ }
96
+ case group.GROUP_GEOLOCATION_GRANULARITY.COUNTRY:
97
+ {
98
+ return country_region || '';
99
+ }
100
+ default:
101
+ {
102
+ return province || '';
103
+ }
104
+ }
105
+ };
106
+
107
+ exports.getGeolocationByGranularity = getGeolocationByGranularity;
85
108
  exports.getGeolocationDisplayString = getGeolocationDisplayString;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  /**
6
6
  * Get text from long-text to display.
7
- * @param {object} longText e.g. { text: 'xxx' }
7
+ * @param {object} longText e.g. { text, ... }
8
8
  * @returns text from long-text, string
9
9
  */
10
10
  var getLongtextDisplayString = function getLongtextDisplayString(longText) {
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var index = require('../helper/number-precision/index.js');
6
- var column = require('../constants/column.js');
7
6
  var duration = require('./duration.js');
7
+ var column = require('../constants/column.js');
8
+ var formula = require('../constants/formula.js');
8
9
 
9
10
  var separatorMap = {
10
11
  comma: ',',
@@ -12,6 +13,37 @@ var separatorMap = {
12
13
  no: '',
13
14
  space: ' '
14
15
  };
16
+ var _getDecimalDigits = function _getDecimalDigits(number) {
17
+ if (Number.isInteger(number)) {
18
+ return 0;
19
+ }
20
+ var valueArr = String(number).split('.');
21
+ var digitsLength = valueArr[1] ? valueArr[1].length : 8;
22
+ return digitsLength > 8 ? 8 : digitsLength;
23
+ };
24
+
25
+ /**
26
+ * Get fixed number by precision
27
+ * @param {number} number
28
+ * @param {object} formats e.g. { enable_precision, precision, ... }
29
+ * @returns fixed number, string
30
+ */
31
+ var getPrecisionNumber = function getPrecisionNumber(number, formats) {
32
+ var _ref = formats || {},
33
+ _ref$precision = _ref.precision,
34
+ precision = _ref$precision === void 0 ? 2 : _ref$precision,
35
+ _ref$enable_precision = _ref.enable_precision,
36
+ enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
37
+ var type = Object.prototype.toString.call(number);
38
+ if (type !== '[object Number]') {
39
+ if (type === '[object String]' && formula.DISPLAY_INTERNAL_ERRORS.includes(number)) {
40
+ return number;
41
+ }
42
+ return null;
43
+ }
44
+ var decimalDigits = enable_precision ? precision : _getDecimalDigits(number);
45
+ return number.toFixed(decimalDigits);
46
+ };
15
47
 
16
48
  /**
17
49
  * removeZerosFromEnd('0.0100') // '0.01'
@@ -38,19 +70,19 @@ var getDecimalDigitsFromNumber = function getDecimalDigitsFromNumber(number) {
38
70
  var digitsLength = decimalPart ? decimalPart.length : 8;
39
71
  return digitsLength > 8 ? 8 : digitsLength;
40
72
  };
41
- var toThousands = function toThousands(number, _ref) {
42
- var formats = _ref.formats,
43
- _ref$isCurrency = _ref.isCurrency,
44
- isCurrency = _ref$isCurrency === void 0 ? true : _ref$isCurrency;
45
- var _ref2 = formats || {},
46
- _ref2$decimal = _ref2.decimal,
47
- decimal = _ref2$decimal === void 0 ? 'dot' : _ref2$decimal,
48
- _ref2$thousands = _ref2.thousands,
49
- thousands = _ref2$thousands === void 0 ? 'no' : _ref2$thousands,
50
- _ref2$precision = _ref2.precision,
51
- precision = _ref2$precision === void 0 ? 2 : _ref2$precision,
52
- _ref2$enable_precisio = _ref2.enable_precision,
53
- enable_precision = _ref2$enable_precisio === void 0 ? false : _ref2$enable_precisio;
73
+ var toThousands = function toThousands(number, _ref2) {
74
+ var formats = _ref2.formats,
75
+ _ref2$isCurrency = _ref2.isCurrency,
76
+ isCurrency = _ref2$isCurrency === void 0 ? true : _ref2$isCurrency;
77
+ var _ref3 = formats || {},
78
+ _ref3$decimal = _ref3.decimal,
79
+ decimal = _ref3$decimal === void 0 ? 'dot' : _ref3$decimal,
80
+ _ref3$thousands = _ref3.thousands,
81
+ thousands = _ref3$thousands === void 0 ? 'no' : _ref3$thousands,
82
+ _ref3$precision = _ref3.precision,
83
+ precision = _ref3$precision === void 0 ? 2 : _ref3$precision,
84
+ _ref3$enable_precisio = _ref3.enable_precision,
85
+ enable_precision = _ref3$enable_precisio === void 0 ? false : _ref3$enable_precisio;
54
86
 
55
87
  // handle numbers in scientific notation
56
88
  if (String(number).includes('e')) {
@@ -69,7 +101,7 @@ var toThousands = function toThousands(number, _ref) {
69
101
  }
70
102
  return numericString;
71
103
  }
72
- return number;
104
+ return String(number);
73
105
  }
74
106
  var decimalString = separatorMap[decimal];
75
107
  var thousandsString = separatorMap[thousands];
@@ -122,9 +154,9 @@ var getNumberDisplayString = function getNumberDisplayString(number, formats) {
122
154
  if (isNaN(number) || number === Infinity || number === -Infinity) return String(number);
123
155
 
124
156
  // formats: old version maybe 'null'
125
- var _ref3 = formats || {},
126
- _ref3$format = _ref3.format,
127
- format = _ref3$format === void 0 ? column.DEFAULT_NUMBER_FORMAT : _ref3$format;
157
+ var _ref4 = formats || {},
158
+ _ref4$format = _ref4.format,
159
+ format = _ref4$format === void 0 ? column.DEFAULT_NUMBER_FORMAT : _ref4$format;
128
160
  switch (format) {
129
161
  case 'number':
130
162
  {
@@ -224,4 +256,5 @@ var replaceNumberNotAllowInput = function replaceNumberNotAllowInput(sNum, forma
224
256
  };
225
257
 
226
258
  exports.getNumberDisplayString = getNumberDisplayString;
259
+ exports.getPrecisionNumber = getPrecisionNumber;
227
260
  exports.replaceNumberNotAllowInput = replaceNumberNotAllowInput;