dtable-utils 0.0.2 → 0.0.3-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 (150) hide show
  1. package/README.md +30 -2
  2. package/dist/index.js +1 -1
  3. package/es/cell-value-get/cell-value.js +227 -19
  4. package/es/cell-value-get/collaborator.js +9 -3
  5. package/es/cell-value-get/digital-sign.js +1 -1
  6. package/es/cell-value-get/geolocation.js +29 -5
  7. package/es/cell-value-get/long-text.js +1 -1
  8. package/es/cell-value-get/number.js +42 -18
  9. package/es/cell-value-get/option.js +17 -7
  10. package/es/cell-value-get/rate.js +6 -0
  11. package/es/cell-value-set/date.js +20 -0
  12. package/es/cell-value-set/number.js +53 -1
  13. package/es/color/gradient-color.js +100 -0
  14. package/es/column/color.js +415 -0
  15. package/es/column/{common.js → core.js} +3 -15
  16. package/es/column/date.js +2 -3
  17. package/es/column/number.js +3 -5
  18. package/es/column/option.js +115 -0
  19. package/es/common.js +10 -1
  20. package/es/constants/color.js +16 -0
  21. package/es/constants/column-permission.js +7 -0
  22. package/es/constants/column.js +127 -2
  23. package/es/constants/filter/index.js +5 -1
  24. package/es/constants/grid-header.js +6 -0
  25. package/es/constants/group.js +23 -0
  26. package/es/constants/limit.js +3 -0
  27. package/es/constants/reg.js +4 -0
  28. package/es/constants/row-color.js +11 -0
  29. package/es/constants/sort.js +11 -0
  30. package/es/date.js +1 -1
  31. package/es/filter/core.js +287 -0
  32. package/es/filter/filter-column/array.js +82 -0
  33. package/es/filter/filter-column/checkbox.js +8 -0
  34. package/es/filter/filter-column/collaborator.js +67 -0
  35. package/es/filter/filter-column/creator.js +50 -0
  36. package/es/filter/filter-column/date.js +59 -0
  37. package/es/filter/filter-column/digital-sign.js +26 -0
  38. package/es/filter/filter-column/file.js +24 -0
  39. package/es/filter/filter-column/formula.js +49 -0
  40. package/es/filter/filter-column/geolocation.js +53 -0
  41. package/es/filter/filter-column/link.js +12 -0
  42. package/es/filter/filter-column/long-text.js +25 -0
  43. package/es/filter/filter-column/multiple-select.js +60 -0
  44. package/es/filter/filter-column/number.js +93 -0
  45. package/es/filter/filter-column/single-select.js +41 -0
  46. package/es/filter/filter-column/text.js +55 -0
  47. package/es/filter/filter-row.js +198 -0
  48. package/es/group/core.js +107 -0
  49. package/es/group/group-row.js +366 -0
  50. package/es/index.js +62 -10
  51. package/es/link/core.js +78 -0
  52. package/es/number.js +13 -0
  53. package/es/row/color.js +278 -0
  54. package/es/row/core.js +161 -0
  55. package/es/sort/core.js +32 -0
  56. package/es/sort/sort-column/array.js +63 -0
  57. package/es/sort/sort-column/checkbox.js +15 -0
  58. package/es/sort/sort-column/collaborator.js +9 -0
  59. package/es/sort/sort-column/date.js +25 -0
  60. package/es/sort/sort-column/formula.js +40 -0
  61. package/es/sort/sort-column/link.js +23 -0
  62. package/es/sort/sort-column/multiple-select.js +45 -0
  63. package/es/sort/sort-column/number.js +18 -0
  64. package/es/sort/sort-column/single-select.js +22 -0
  65. package/es/sort/sort-column/text.js +47 -0
  66. package/es/sort/sort-row.js +126 -0
  67. package/es/table/column.js +27 -0
  68. package/es/table/core.js +14 -0
  69. package/es/table/index.js +14 -0
  70. package/es/table/row.js +25 -0
  71. package/es/validate/filter.js +1 -1
  72. package/es/validate/geolocation.js +5 -0
  73. package/es/view/core.js +135 -0
  74. package/es/view/formula.js +143 -0
  75. package/es/view/group.js +32 -0
  76. package/es/view/summaries.js +179 -0
  77. package/lib/cell-value-get/cell-value.js +231 -18
  78. package/lib/cell-value-get/collaborator.js +9 -2
  79. package/lib/cell-value-get/digital-sign.js +1 -1
  80. package/lib/cell-value-get/geolocation.js +30 -5
  81. package/lib/cell-value-get/long-text.js +1 -1
  82. package/lib/cell-value-get/number.js +42 -17
  83. package/lib/cell-value-get/option.js +18 -6
  84. package/lib/cell-value-get/rate.js +10 -0
  85. package/lib/cell-value-set/date.js +24 -0
  86. package/lib/cell-value-set/number.js +53 -0
  87. package/lib/color/gradient-color.js +110 -0
  88. package/lib/column/color.js +424 -0
  89. package/lib/column/{common.js → core.js} +3 -16
  90. package/lib/column/date.js +2 -3
  91. package/lib/column/number.js +3 -5
  92. package/lib/column/option.js +123 -0
  93. package/lib/common.js +14 -0
  94. package/lib/constants/color.js +20 -0
  95. package/lib/constants/column-permission.js +11 -0
  96. package/lib/constants/column.js +134 -1
  97. package/lib/constants/filter/index.js +5 -0
  98. package/lib/constants/grid-header.js +10 -0
  99. package/lib/constants/group.js +36 -0
  100. package/lib/constants/limit.js +7 -0
  101. package/lib/constants/reg.js +9 -0
  102. package/lib/constants/row-color.js +17 -0
  103. package/lib/constants/sort.js +18 -0
  104. package/lib/filter/core.js +301 -0
  105. package/lib/filter/filter-column/array.js +86 -0
  106. package/lib/filter/filter-column/checkbox.js +12 -0
  107. package/lib/filter/filter-column/collaborator.js +75 -0
  108. package/lib/filter/filter-column/creator.js +54 -0
  109. package/lib/filter/filter-column/date.js +63 -0
  110. package/lib/filter/filter-column/digital-sign.js +30 -0
  111. package/lib/filter/filter-column/file.js +28 -0
  112. package/lib/filter/filter-column/formula.js +53 -0
  113. package/lib/filter/filter-column/geolocation.js +57 -0
  114. package/lib/filter/filter-column/link.js +16 -0
  115. package/lib/filter/filter-column/long-text.js +29 -0
  116. package/lib/filter/filter-column/multiple-select.js +68 -0
  117. package/lib/filter/filter-column/number.js +97 -0
  118. package/lib/filter/filter-column/single-select.js +45 -0
  119. package/lib/filter/filter-column/text.js +59 -0
  120. package/lib/filter/filter-row.js +204 -0
  121. package/lib/group/core.js +117 -0
  122. package/lib/group/group-row.js +377 -0
  123. package/lib/index.js +176 -6
  124. package/lib/link/core.js +90 -0
  125. package/lib/number.js +18 -0
  126. package/lib/row/color.js +286 -0
  127. package/lib/row/core.js +170 -0
  128. package/lib/sort/core.js +37 -0
  129. package/lib/sort/sort-column/array.js +67 -0
  130. package/lib/sort/sort-column/checkbox.js +19 -0
  131. package/lib/sort/sort-column/collaborator.js +13 -0
  132. package/lib/sort/sort-column/date.js +29 -0
  133. package/lib/sort/sort-column/formula.js +44 -0
  134. package/lib/sort/sort-column/link.js +27 -0
  135. package/lib/sort/sort-column/multiple-select.js +50 -0
  136. package/lib/sort/sort-column/number.js +22 -0
  137. package/lib/sort/sort-column/single-select.js +26 -0
  138. package/lib/sort/sort-column/text.js +52 -0
  139. package/lib/sort/sort-row.js +136 -0
  140. package/lib/table/column.js +32 -0
  141. package/lib/table/core.js +18 -0
  142. package/lib/table/index.js +18 -0
  143. package/lib/table/row.js +30 -0
  144. package/lib/validate/filter.js +3 -3
  145. package/lib/validate/geolocation.js +9 -0
  146. package/lib/view/core.js +144 -0
  147. package/lib/view/formula.js +150 -0
  148. package/lib/view/group.js +36 -0
  149. package/lib/view/summaries.js +185 -0
  150. package/package.json +4 -2
@@ -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,8 +12,63 @@ 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];
24
+ var _getArrayColumnCellValue = function _getArrayColumnCellValue(cellValue, column, _ref) {
25
+ var collaborators = _ref.collaborators,
26
+ isArchiveView = _ref.isArchiveView;
27
+ if (!cellValue || !Array.isArray(cellValue) || cellValue.length === 0) {
28
+ return '';
29
+ }
30
+ var key = column.key,
31
+ data = column.data;
32
+ var _ref2 = data || {},
33
+ array_type = _ref2.array_type,
34
+ array_data = _ref2.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 ([cellType.CellType.FILE, cellType.CellType.IMAGE, cellType.CellType.COLLABORATOR, cellType.CellType.MULTIPLE_SELECT].includes(array_type)) {
42
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, cellValue), newColumn, {
43
+ collaborators: collaborators
44
+ });
45
+ }
46
+
47
+ // cellValue itself is a single value
48
+ if (array_type === cellType.CellType.STRING) {
49
+ newColumn.type = cellType.CellType.TEXT;
50
+ var _result = cellValue.map(function (item) {
51
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, item), newColumn);
52
+ });
53
+ return _result.filter(Boolean).join(', ');
54
+ }
55
+ if (array_type === cellType.CellType.BOOL) {
56
+ newColumn.type = cellType.CellType.CHECKBOX;
57
+ var _result2 = cellValue.map(function (item) {
58
+ return getCellValueStringResult(_defineProperty__default["default"]({}, key, item), newColumn);
59
+ });
60
+ return _result2.filter(Boolean).join(', ');
61
+ }
62
+ var result = cellValue.map(function (item) {
63
+ return getCellValueStringResult(_defineProperty__default["default"]({}, 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
+ };
19
72
 
20
73
  /**
21
74
  * Get formatted formula result to display. It will not be formatted
@@ -70,27 +123,27 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
70
123
 
71
124
  /**
72
125
  * Get formatted cell value to display.
73
- * @param {object} row e.g. { [column.key]: 'xxx' }
126
+ * @param {object} row e.g. { [column.key]: '' }
74
127
  * @param {string} type column type
75
128
  * @param {string} key column key
76
129
  * @param {object} data column data
77
130
  * @param {object} formulaRows formula results of rows. Default as "{}"
78
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]. Default as "[]"
131
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
79
132
  * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
80
133
  * @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
81
134
  * @returns formatted cell value, string|array
82
135
  */
83
136
  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;
137
+ var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
138
+ data = _ref3.data,
139
+ _ref3$formulaRows = _ref3.formulaRows,
140
+ formulaRows = _ref3$formulaRows === void 0 ? {} : _ref3$formulaRows,
141
+ _ref3$collaborators = _ref3.collaborators,
142
+ collaborators = _ref3$collaborators === void 0 ? [] : _ref3$collaborators,
143
+ _ref3$isBaiduMap = _ref3.isBaiduMap,
144
+ isBaiduMap = _ref3$isBaiduMap === void 0 ? true : _ref3$isBaiduMap,
145
+ _ref3$geolocationHyph = _ref3.geolocationHyphen,
146
+ geolocationHyphen = _ref3$geolocationHyph === void 0 ? '' : _ref3$geolocationHyph;
94
147
  if (!row) return '';
95
148
  var cellValue = row[key];
96
149
  switch (type) {
@@ -127,9 +180,9 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
127
180
  }
128
181
  case cellType.CellType.DATE:
129
182
  {
130
- var _ref2 = data || {},
131
- _ref2$format = _ref2.format,
132
- format = _ref2$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref2$format;
183
+ var _ref4 = data || {},
184
+ _ref4$format = _ref4.format,
185
+ format = _ref4$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref4$format;
133
186
  return date.getDateDisplayString(cellValue, format);
134
187
  }
135
188
  case cellType.CellType.CTIME:
@@ -165,6 +218,166 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
165
218
  }
166
219
  }
167
220
  };
221
+ var getCellValueStringResult = function getCellValueStringResult(row, column$1) {
222
+ var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
223
+ _ref5$formulaRows = _ref5.formulaRows,
224
+ formulaRows = _ref5$formulaRows === void 0 ? {} : _ref5$formulaRows,
225
+ _ref5$collaborators = _ref5.collaborators,
226
+ collaborators = _ref5$collaborators === void 0 ? [] : _ref5$collaborators,
227
+ _ref5$isArchiveView = _ref5.isArchiveView,
228
+ isArchiveView = _ref5$isArchiveView === void 0 ? false : _ref5$isArchiveView;
229
+ var _ref6 = column$1 || {},
230
+ key = _ref6.key,
231
+ type = _ref6.type,
232
+ data = _ref6.data;
233
+ var cellValue = row[key];
234
+ switch (type) {
235
+ case cellType.CellType.TEXT:
236
+ case cellType.CellType.EMAIL:
237
+ case cellType.CellType.URL:
238
+ case cellType.CellType.AUTO_NUMBER:
239
+ {
240
+ return cellValue || '';
241
+ }
242
+ case cellType.CellType.RATE:
243
+ {
244
+ // number
245
+ return cellValue ? String(cellValue) : '';
246
+ }
247
+ case cellType.CellType.CHECKBOX:
248
+ {
249
+ if (typeof cellValue === 'boolean') {
250
+ return String(cellValue);
251
+ }
252
+ return cellValue === 'true' ? 'true' : 'false';
253
+ }
254
+ case cellType.CellType.LONG_TEXT:
255
+ {
256
+ // the data returned by archive view is a string, not a result in long-text format
257
+ if (isArchiveView) {
258
+ cellValue = {
259
+ text: cellValue
260
+ };
261
+ }
262
+ return longText.getLongtextDisplayString(cellValue);
263
+ }
264
+ case cellType.CellType.NUMBER:
265
+ {
266
+ return number.getNumberDisplayString(cellValue, data);
267
+ }
268
+ case cellType.CellType.DURATION:
269
+ {
270
+ return duration.getDurationDisplayString(cellValue, data);
271
+ }
272
+ case cellType.CellType.GEOLOCATION:
273
+ {
274
+ return geolocation.getGeolocationDisplayString(cellValue, data);
275
+ }
276
+ case cellType.CellType.SINGLE_SELECT:
277
+ {
278
+ if (!data) return '';
279
+ var options = data.options;
280
+ return option.getOptionName(options, cellValue);
281
+ }
282
+ case cellType.CellType.MULTIPLE_SELECT:
283
+ {
284
+ if (!data) return '';
285
+ var _options2 = data.options;
286
+ return option.getMultipleOptionName(_options2, cellValue);
287
+ }
288
+ case cellType.CellType.DATE:
289
+ {
290
+ var _ref7 = data || {},
291
+ _ref7$format = _ref7.format,
292
+ format = _ref7$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref7$format;
293
+ // patch: compatible with previous format
294
+ var normalizedFormat = format === 'D/M/YYYY' ? format.replace(/D\/M\/YYYY/, 'DD/MM/YYYY') : format;
295
+ return date.getDateDisplayString(cellValue, normalizedFormat);
296
+ }
297
+ case cellType.CellType.CTIME:
298
+ case cellType.CellType.MTIME:
299
+ {
300
+ return date$1.DateUtils.format(cellValue, 'YYYY-MM-DD HH:MM:SS');
301
+ }
302
+ case cellType.CellType.COLLABORATOR:
303
+ {
304
+ return collaborator.getCollaboratorsName(collaborators, cellValue);
305
+ }
306
+ case cellType.CellType.CREATOR:
307
+ case cellType.CellType.LAST_MODIFIER:
308
+ {
309
+ return cellValue === 'anonymous' ? cellValue : collaborator.getCollaboratorsName(collaborators, [cellValue]);
310
+ }
311
+ case cellType.CellType.LINK:
312
+ {
313
+ if (!isArchiveView) {
314
+ var formulaRow = formulaRows[row._id] || {};
315
+ cellValue = formulaRow[key];
316
+ }
317
+ if (!cellValue || !Array.isArray(cellValue) || cellValue.length === 0) return '';
318
+ var newCellValue = cellValue.map(function (linked) {
319
+ return linked.display_value;
320
+ });
321
+ var isTwoDimensionalArray = newCellValue.some(function (item) {
322
+ return Array.isArray(item);
323
+ });
324
+ if (!isTwoDimensionalArray) {
325
+ return _getArrayColumnCellValue(newCellValue, column$1, {
326
+ collaborators: collaborators
327
+ });
328
+ }
329
+ var result = newCellValue.map(function (item) {
330
+ return _getArrayColumnCellValue(item, column$1, {
331
+ collaborators: collaborators,
332
+ isArchiveView: isArchiveView
333
+ });
334
+ });
335
+ return result.filter(Boolean).join(', ');
336
+ }
337
+ case cellType.CellType.FORMULA:
338
+ case cellType.CellType.LINK_FORMULA:
339
+ {
340
+ if (!isArchiveView) {
341
+ var _formulaRow = formulaRows[row._id] || {};
342
+ cellValue = _formulaRow[key];
343
+ }
344
+ var result_type = data.result_type;
345
+ if (result_type === formula.FORMULA_RESULT_TYPE.STRING) {
346
+ return cellValue || '';
347
+ }
348
+ if (result_type === formula.FORMULA_RESULT_TYPE.BOOL) {
349
+ return [true, 'true'].includes(cellValue) ? 'true' : 'false';
350
+ }
351
+ if (result_type === formula.FORMULA_RESULT_TYPE.NUMBER) {
352
+ // data is stored in the data of the current column
353
+ return number.getNumberDisplayString(cellValue, data);
354
+ }
355
+ if (result_type === formula.FORMULA_RESULT_TYPE.DATE) {
356
+ // data is stored in the data of the current column
357
+ var _ref8 = data || {},
358
+ _format = _ref8.format;
359
+ return date.getDateDisplayString(cellValue, _format);
360
+ }
361
+
362
+ // FORMULA_RESULT_TYPE.ARRAY
363
+ return _getArrayColumnCellValue(cellValue, column$1, {
364
+ collaborators: collaborators,
365
+ isArchiveView: isArchiveView
366
+ });
367
+ }
368
+ case cellType.CellType.FILE:
369
+ case cellType.CellType.IMAGE:
370
+ case cellType.CellType.BUTTON:
371
+ {
372
+ return '';
373
+ }
374
+ default:
375
+ {
376
+ return cellValue ? String(cellValue) : '';
377
+ }
378
+ }
379
+ };
168
380
 
169
381
  exports.getCellValueDisplayString = getCellValueDisplayString;
382
+ exports.getCellValueStringResult = getCellValueStringResult;
170
383
  exports.getFormulaDisplayString = getFormulaDisplayString;
@@ -2,10 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var getCollaborator = function getCollaborator(collaborators, collaboratorEmail) {
6
+ return collaborators.find(function (collaborator) {
7
+ return collaborator.email === collaboratorEmail;
8
+ });
9
+ };
10
+
5
11
  /**
6
12
  * Get collaborators name list of given emails
7
13
  * @param {array} emails e.g. ['email', ...]
8
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
14
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
9
15
  * @returns name list, array. e.g. ['name1', 'name2']
10
16
  */
11
17
  var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators) {
@@ -24,7 +30,7 @@ var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators
24
30
 
25
31
  /**
26
32
  * Get concatenated collaborators names of given emails.
27
- * @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
33
+ * @param {array} collaborators e.g. [{ email, name, ... }, ...]
28
34
  * @param {array} emails e.g. ['email', ...]
29
35
  * @returns concatenated collaborators names, string. e.g. 'name1, name2'
30
36
  */
@@ -34,5 +40,6 @@ var getCollaboratorsName = function getCollaboratorsName(collaborators, emails)
34
40
  return collaboratorsNames.join(', ');
35
41
  };
36
42
 
43
+ exports.getCollaborator = getCollaborator;
37
44
  exports.getCollaboratorsName = getCollaboratorsName;
38
45
  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) {
@@ -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
@@ -31,7 +30,7 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
31
30
  var _ref3 = loc || {},
32
31
  lng = _ref3.lng,
33
32
  lat = _ref3.lat;
34
- if (!isValidPosition(lng, lat)) return '';
33
+ if (!geolocation.isValidPosition(lng, lat)) return '';
35
34
  return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
36
35
  }
37
36
  case 'country_region':
@@ -81,5 +80,31 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
81
80
  }
82
81
  }
83
82
  };
83
+ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocation, granularity) {
84
+ if (!geolocation) return '';
85
+ var province = geolocation.province,
86
+ city = geolocation.city,
87
+ district = geolocation.district,
88
+ country_region = geolocation.country_region;
89
+ switch (granularity) {
90
+ case group.GROUP_GEOLOCATION_GRANULARITY.CITY:
91
+ {
92
+ return city || '';
93
+ }
94
+ case group.GROUP_GEOLOCATION_GRANULARITY.DISTRICT:
95
+ {
96
+ return district || '';
97
+ }
98
+ case group.GROUP_GEOLOCATION_GRANULARITY.COUNTRY:
99
+ {
100
+ return country_region || '';
101
+ }
102
+ default:
103
+ {
104
+ return province || '';
105
+ }
106
+ }
107
+ };
84
108
 
109
+ exports.getGeolocationByGranularity = getGeolocationByGranularity;
85
110
  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,8 @@
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
8
 
9
9
  var separatorMap = {
10
10
  comma: ',',
@@ -12,6 +12,30 @@ var separatorMap = {
12
12
  no: '',
13
13
  space: ' '
14
14
  };
15
+ var _getDecimalDigits = function _getDecimalDigits(num) {
16
+ if (Number.isInteger(num)) {
17
+ return 0;
18
+ }
19
+ var valueArr = (num + '').split('.');
20
+ var digitsLength = valueArr[1] ? valueArr[1].length : 8;
21
+ return digitsLength > 8 ? 8 : digitsLength;
22
+ };
23
+ var getPrecisionNumber = function getPrecisionNumber(num, formatData) {
24
+ var _ref = formatData || {},
25
+ _ref$precision = _ref.precision,
26
+ precision = _ref$precision === void 0 ? 2 : _ref$precision,
27
+ _ref$enable_precision = _ref.enable_precision,
28
+ enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
29
+ var type = Object.prototype.toString.call(num);
30
+ if (type !== '[object Number]') {
31
+ if (type === '[object String]' && DISPLAY_INTERNAL_ERRORS.includes(num)) {
32
+ return num;
33
+ }
34
+ return null;
35
+ }
36
+ var decimalDigits = enable_precision ? precision : _getDecimalDigits(num);
37
+ return num.toFixed(decimalDigits);
38
+ };
15
39
 
16
40
  /**
17
41
  * removeZerosFromEnd('0.0100') // '0.01'
@@ -38,19 +62,19 @@ var getDecimalDigitsFromNumber = function getDecimalDigitsFromNumber(number) {
38
62
  var digitsLength = decimalPart ? decimalPart.length : 8;
39
63
  return digitsLength > 8 ? 8 : digitsLength;
40
64
  };
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;
65
+ var toThousands = function toThousands(number, _ref2) {
66
+ var formats = _ref2.formats,
67
+ _ref2$isCurrency = _ref2.isCurrency,
68
+ isCurrency = _ref2$isCurrency === void 0 ? true : _ref2$isCurrency;
69
+ var _ref3 = formats || {},
70
+ _ref3$decimal = _ref3.decimal,
71
+ decimal = _ref3$decimal === void 0 ? 'dot' : _ref3$decimal,
72
+ _ref3$thousands = _ref3.thousands,
73
+ thousands = _ref3$thousands === void 0 ? 'no' : _ref3$thousands,
74
+ _ref3$precision = _ref3.precision,
75
+ precision = _ref3$precision === void 0 ? 2 : _ref3$precision,
76
+ _ref3$enable_precisio = _ref3.enable_precision,
77
+ enable_precision = _ref3$enable_precisio === void 0 ? false : _ref3$enable_precisio;
54
78
 
55
79
  // handle numbers in scientific notation
56
80
  if (String(number).includes('e')) {
@@ -122,9 +146,9 @@ var getNumberDisplayString = function getNumberDisplayString(number, formats) {
122
146
  if (isNaN(number) || number === Infinity || number === -Infinity) return String(number);
123
147
 
124
148
  // 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;
149
+ var _ref4 = formats || {},
150
+ _ref4$format = _ref4.format,
151
+ format = _ref4$format === void 0 ? column.DEFAULT_NUMBER_FORMAT : _ref4$format;
128
152
  switch (format) {
129
153
  case 'number':
130
154
  {
@@ -224,4 +248,5 @@ var replaceNumberNotAllowInput = function replaceNumberNotAllowInput(sNum, forma
224
248
  };
225
249
 
226
250
  exports.getNumberDisplayString = getNumberDisplayString;
251
+ exports.getPrecisionNumber = getPrecisionNumber;
227
252
  exports.replaceNumberNotAllowInput = replaceNumberNotAllowInput;
@@ -2,19 +2,29 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var option = require('../column/option.js');
6
+
7
+ var getOption = function getOption(options, optionId) {
8
+ return options.find(function (o) {
9
+ return o.id === optionId;
10
+ });
11
+ };
12
+
5
13
  /**
6
14
  * Get option name of the given id
7
15
  * @param {array} options e.g. [ { id: '', color: '', name: '' } ]
8
- * @param {string} targetOptionID option id
16
+ * @param {string} targetOptionId option id
9
17
  * @returns option name, string
10
18
  */
11
- var getOptionName = function getOptionName(options, targetOptionID) {
12
- if (!targetOptionID || !Array.isArray(options)) return '';
13
- var targetOption = options.find(function (option) {
14
- return option.id === targetOptionID;
15
- });
19
+ var getOptionName = function getOptionName(options, targetOptionId) {
20
+ if (!targetOptionId || !Array.isArray(options)) return '';
21
+ var targetOption = getOption(options, targetOptionId);
16
22
  return targetOption ? targetOption.name : '';
17
23
  };
24
+ var getColumnOptionNameById = function getColumnOptionNameById(column, optionId) {
25
+ var options = option.getColumnOptions(column);
26
+ return getOptionName(options, optionId);
27
+ };
18
28
 
19
29
  /**
20
30
  * Get concatenated options names of given ids.
@@ -33,5 +43,7 @@ var getMultipleOptionName = function getMultipleOptionName(options, targetOption
33
43
  }).join(', ');
34
44
  };
35
45
 
46
+ exports.getColumnOptionNameById = getColumnOptionNameById;
36
47
  exports.getMultipleOptionName = getMultipleOptionName;
48
+ exports.getOption = getOption;
37
49
  exports.getOptionName = getOptionName;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var getRateDisplayString = function getRateDisplayString(value) {
6
+ if (!value) return '';
7
+ return String(value);
8
+ };
9
+
10
+ exports.getRateDisplayString = getRateDisplayString;
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var date = require('../date.js');
6
+ var number = require('./number.js');
7
+
8
+ var formatTextToDate = function formatTextToDate(text) {
9
+ var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
10
+ if (typeof text !== 'string' || !text.trim()) return null;
11
+ var isAllNumber = /^[0-9]+$/.test(text);
12
+ var dateObj = {};
13
+ if (isAllNumber) {
14
+ dateObj = new Date(number.getFloatNumber(text));
15
+ } else {
16
+ dateObj = date.DateUtils.parseDateWithFormat(text, dateFormat);
17
+ }
18
+ if (dateFormat.indexOf('HH:mm') < 0) {
19
+ return date.DateUtils.format(dateObj, 'YYYY-MM-DD') || null;
20
+ }
21
+ return date.DateUtils.format(dateObj, 'YYYY-MM-DD HH:MM') || null;
22
+ };
23
+
24
+ exports.formatTextToDate = formatTextToDate;
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var index = require('../helper/number-precision/index.js');
6
+ var number = require('../number.js');
7
+ var column = require('../constants/column.js');
6
8
 
7
9
  /**
8
10
  * @param {string} sNumber e.g. '1.23'
@@ -54,5 +56,56 @@ var formatStringToNumber = function formatStringToNumber(sNum, formats) {
54
56
  return value;
55
57
  };
56
58
 
59
+ /**
60
+ * parse duration to seconds depend on formats
61
+ * @param {string} duration
62
+ * @param {object} data { duration_format: '' }
63
+ * @returns number
64
+ */
65
+ var formatDurationToNumber = function formatDurationToNumber(duration, data) {
66
+ if (duration === 0) return 0;
67
+ if (!duration) return null;
68
+ var _ref2 = data || {},
69
+ duration_format = _ref2.duration_format;
70
+ duration_format = duration_format || column.DURATION_FORMATS_MAP.H_MM;
71
+ if (column.DURATION_FORMATS.findIndex(function (format) {
72
+ return format.type === duration_format;
73
+ }) < 0) {
74
+ return null;
75
+ }
76
+ var numericDuration = duration - 0;
77
+ if (number.isNumber(numericDuration)) {
78
+ return duration_format === column.DURATION_FORMATS_MAP.H_MM ? numericDuration * 60 : numericDuration;
79
+ }
80
+ var stringifyDuration = String(duration);
81
+ var isNegative = stringifyDuration[0] === '-';
82
+ if (isNegative) {
83
+ stringifyDuration = stringifyDuration.substring(1);
84
+ }
85
+ var timeParts = stringifyDuration.split(/[::]/); // support ':' and ':'.
86
+ var timePartsLen = timeParts.length;
87
+ var hoursIndex;
88
+ var minutesIndex;
89
+ var secondsIndex;
90
+ if (duration_format === column.DURATION_FORMATS_MAP.H_MM) {
91
+ hoursIndex = timePartsLen - 2;
92
+ minutesIndex = timePartsLen - 1;
93
+ } else {
94
+ hoursIndex = timePartsLen - 3;
95
+ minutesIndex = timePartsLen - 2;
96
+ secondsIndex = timePartsLen - 1;
97
+ }
98
+ var hours = timeParts[hoursIndex] - 0;
99
+ var minutes = timeParts[minutesIndex] - 0;
100
+ var seconds = timeParts[secondsIndex] - 0;
101
+ if (!number.isNumber(hours) && !number.isNumber(minutes) && !number.isNumber(seconds)) return null;
102
+ hours = number.isNumber(hours) ? hours : 0;
103
+ minutes = number.isNumber(minutes) ? minutes : 0;
104
+ seconds = number.isNumber(seconds) ? seconds : 0;
105
+ var result = hours * 3600 + minutes * 60 + seconds;
106
+ return isNegative ? -result : result;
107
+ };
108
+
109
+ exports.formatDurationToNumber = formatDurationToNumber;
57
110
  exports.formatStringToNumber = formatStringToNumber;
58
111
  exports.getFloatNumber = getFloatNumber;