dtable-utils 0.0.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.
- package/README.md +20 -0
- package/dist/index.js +1 -0
- package/es/cell-value-get/cell-value.js +165 -0
- package/es/cell-value-get/collaborator.js +33 -0
- package/es/cell-value-get/date.js +53 -0
- package/es/cell-value-get/digital-sign.js +10 -0
- package/es/cell-value-get/duration.js +86 -0
- package/es/cell-value-get/geolocation.js +74 -0
- package/es/cell-value-get/long-text.js +11 -0
- package/es/cell-value-get/number.js +222 -0
- package/es/cell-value-get/option.js +32 -0
- package/es/cell-value-set/number.js +53 -0
- package/es/column/common.js +41 -0
- package/es/column/date.js +17 -0
- package/es/column/number.js +31 -0
- package/es/common.js +16 -0
- package/es/constants/cell-type.js +33 -0
- package/es/constants/column.js +45 -0
- package/es/constants/filter/filter-column-options.js +65 -0
- package/es/constants/filter/filter-is-within.js +6 -0
- package/es/constants/filter/filter-modifier.js +29 -0
- package/es/constants/filter/filter-predicate.js +33 -0
- package/es/constants/filter/index.js +16 -0
- package/es/constants/formula.js +14 -0
- package/es/constants/select-option.js +129 -0
- package/es/date.js +226 -0
- package/es/helper/number-precision/index.js +64 -0
- package/es/index.js +26 -0
- package/es/validate/email.js +10 -0
- package/es/validate/filter.js +447 -0
- package/lib/cell-value-get/cell-value.js +170 -0
- package/lib/cell-value-get/collaborator.js +38 -0
- package/lib/cell-value-get/date.js +61 -0
- package/lib/cell-value-get/digital-sign.js +14 -0
- package/lib/cell-value-get/duration.js +90 -0
- package/lib/cell-value-get/geolocation.js +78 -0
- package/lib/cell-value-get/long-text.js +15 -0
- package/lib/cell-value-get/number.js +227 -0
- package/lib/cell-value-get/option.js +37 -0
- package/lib/cell-value-set/number.js +58 -0
- package/lib/column/common.js +46 -0
- package/lib/column/date.js +21 -0
- package/lib/column/number.js +36 -0
- package/lib/common.js +20 -0
- package/lib/constants/cell-type.js +37 -0
- package/lib/constants/column.js +63 -0
- package/lib/constants/filter/filter-column-options.js +73 -0
- package/lib/constants/filter/filter-is-within.js +11 -0
- package/lib/constants/filter/filter-modifier.js +38 -0
- package/lib/constants/filter/filter-predicate.js +42 -0
- package/lib/constants/filter/index.js +27 -0
- package/lib/constants/formula.js +23 -0
- package/lib/constants/select-option.js +134 -0
- package/lib/date.js +235 -0
- package/lib/helper/number-precision/index.js +69 -0
- package/lib/index.js +79 -0
- package/lib/validate/email.js +14 -0
- package/lib/validate/filter.js +458 -0
- package/package.json +44 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dayjs = require('dayjs');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get formatted date
|
|
13
|
+
* @param {string} date e.g. "2023-07-06 11:30"
|
|
14
|
+
* @param {string} format e.g. "YYYY-MM-DD"
|
|
15
|
+
* @returns formatted date, string
|
|
16
|
+
*/
|
|
17
|
+
var getDateDisplayString = function getDateDisplayString(date, format) {
|
|
18
|
+
if (!date || typeof date !== 'string') {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
var dateObj = dayjs__default["default"](date);
|
|
22
|
+
if (!dateObj.isValid()) return date;
|
|
23
|
+
switch (format) {
|
|
24
|
+
case 'D/M/YYYY':
|
|
25
|
+
case 'DD/MM/YYYY':
|
|
26
|
+
{
|
|
27
|
+
var formatValue = dateObj.format('YYYY-MM-DD');
|
|
28
|
+
var formatValueList = formatValue.split('-');
|
|
29
|
+
return "".concat(formatValueList[2], "/").concat(formatValueList[1], "/").concat(formatValueList[0]);
|
|
30
|
+
}
|
|
31
|
+
case 'D/M/YYYY HH:mm':
|
|
32
|
+
case 'DD/MM/YYYY HH:mm':
|
|
33
|
+
{
|
|
34
|
+
var formatValues = dateObj.format('YYYY-MM-DD HH:mm');
|
|
35
|
+
var formatValuesList = formatValues.split(' ');
|
|
36
|
+
var formatDateList = formatValuesList[0].split('-');
|
|
37
|
+
return "".concat(formatDateList[2], "/").concat(formatDateList[1], "/").concat(formatDateList[0], " ").concat(formatValuesList[1]);
|
|
38
|
+
}
|
|
39
|
+
case 'M/D/YYYY':
|
|
40
|
+
return dateObj.format('M/D/YYYY');
|
|
41
|
+
case 'M/D/YYYY HH:mm':
|
|
42
|
+
return dateObj.format('M/D/YYYY HH:mm');
|
|
43
|
+
case 'YYYY-MM-DD':
|
|
44
|
+
return dateObj.format('YYYY-MM-DD');
|
|
45
|
+
case 'YYYY-MM-DD HH:mm':
|
|
46
|
+
return dateObj.format('YYYY-MM-DD HH:mm');
|
|
47
|
+
case 'YYYY-MM-DD HH:mm:ss':
|
|
48
|
+
{
|
|
49
|
+
return dateObj.format('YYYY-MM-DD HH:mm:ss');
|
|
50
|
+
}
|
|
51
|
+
case 'DD.MM.YYYY':
|
|
52
|
+
return dateObj.format('DD.MM.YYYY');
|
|
53
|
+
case 'DD.MM.YYYY HH:mm':
|
|
54
|
+
return dateObj.format('DD.MM.YYYY HH:mm');
|
|
55
|
+
default:
|
|
56
|
+
// Compatible with older versions: if format is null, use defaultFormat
|
|
57
|
+
return dateObj.format('YYYY-MM-DD');
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
exports.getDateDisplayString = getDateDisplayString;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get signature image url to display
|
|
7
|
+
* @param {object} digitalSign object, e.g. { sign_image_url: 'xxx' }
|
|
8
|
+
* @returns signature image url, string
|
|
9
|
+
*/
|
|
10
|
+
var getDigitalSignImageUrl = function getDigitalSignImageUrl(digitalSign) {
|
|
11
|
+
return digitalSign && digitalSign.sign_image_url || '';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.getDigitalSignImageUrl = getDigitalSignImageUrl;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var column = require('../constants/column.js');
|
|
6
|
+
|
|
7
|
+
var getMathRoundedDuration = function getMathRoundedDuration(num, duration_format) {
|
|
8
|
+
var decimalDigits = column.DURATION_DECIMAL_DIGITS[duration_format];
|
|
9
|
+
if (decimalDigits < 1) {
|
|
10
|
+
return num;
|
|
11
|
+
}
|
|
12
|
+
var ratio = Math.pow(10, decimalDigits);
|
|
13
|
+
return Math.round(num * ratio) / ratio;
|
|
14
|
+
};
|
|
15
|
+
var getDurationDecimalSuffix = function getDurationDecimalSuffix(duration_format, decimal) {
|
|
16
|
+
if (duration_format === column.DURATION_FORMATS_MAP.H_MM_SS_S) {
|
|
17
|
+
return decimal === 0 ? '.0' : '';
|
|
18
|
+
}
|
|
19
|
+
if (duration_format === column.DURATION_FORMATS_MAP.H_MM_SS_SS) {
|
|
20
|
+
if (decimal === 0) {
|
|
21
|
+
return '.00';
|
|
22
|
+
}
|
|
23
|
+
if (decimal < 10) {
|
|
24
|
+
return '0';
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
if (duration_format === column.DURATION_FORMATS_MAP.H_MM_SS_SSS) {
|
|
29
|
+
if (decimal === 0) {
|
|
30
|
+
return '.000';
|
|
31
|
+
}
|
|
32
|
+
if (decimal < 10) {
|
|
33
|
+
return '00';
|
|
34
|
+
}
|
|
35
|
+
if (decimal < 100) {
|
|
36
|
+
return '0';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get formatted duration.
|
|
44
|
+
* @param {number} duration e.g. 100
|
|
45
|
+
* @param {object} formats { duration_format: 'h:mm', ... }
|
|
46
|
+
* @returns formatted duration, string
|
|
47
|
+
*/
|
|
48
|
+
var getDurationDisplayString = function getDurationDisplayString(duration, formats) {
|
|
49
|
+
if (!duration && duration !== 0) return '';
|
|
50
|
+
var _ref = formats || {},
|
|
51
|
+
duration_format = _ref.duration_format;
|
|
52
|
+
duration_format = duration_format || column.DURATION_FORMATS_MAP.H_MM;
|
|
53
|
+
if (column.DURATION_FORMATS.findIndex(function (format) {
|
|
54
|
+
return format.type === duration_format;
|
|
55
|
+
}) < 0) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
if (duration === 0) {
|
|
59
|
+
return column.DURATION_ZERO_DISPLAY[duration_format];
|
|
60
|
+
}
|
|
61
|
+
var includeDecimal = duration_format.indexOf('.') > -1;
|
|
62
|
+
var positiveValue = Math.abs(duration);
|
|
63
|
+
if (!includeDecimal) {
|
|
64
|
+
positiveValue = Math.round(positiveValue);
|
|
65
|
+
}
|
|
66
|
+
positiveValue = getMathRoundedDuration(positiveValue, duration_format);
|
|
67
|
+
var decimalParts = String(positiveValue).split('.');
|
|
68
|
+
var decimalPartsLen = decimalParts.length;
|
|
69
|
+
var decimal = 0;
|
|
70
|
+
if (decimalPartsLen > 1) {
|
|
71
|
+
decimal = decimalParts[decimalPartsLen - 1];
|
|
72
|
+
decimal = decimal ? decimal - 0 : 0;
|
|
73
|
+
}
|
|
74
|
+
var decimalDigits = column.DURATION_DECIMAL_DIGITS[duration_format];
|
|
75
|
+
var decimalSuffix = getDurationDecimalSuffix(duration_format, decimal);
|
|
76
|
+
var hours = parseInt(positiveValue / 3600, 10);
|
|
77
|
+
var minutes = parseInt((positiveValue - hours * 3600) / 60, 10);
|
|
78
|
+
var displayString = duration < 0 ? '-' : '';
|
|
79
|
+
if (duration_format === column.DURATION_FORMATS_MAP.H_MM) {
|
|
80
|
+
displayString += "".concat(hours, ":").concat(minutes > 9 ? minutes : "0".concat(minutes));
|
|
81
|
+
return displayString;
|
|
82
|
+
}
|
|
83
|
+
var seconds = Number.parseFloat((positiveValue - hours * 3600 - minutes * 60).toFixed(decimalDigits));
|
|
84
|
+
minutes = minutes > 9 ? minutes : "0".concat(minutes);
|
|
85
|
+
seconds = seconds > 9 ? seconds : "0".concat(seconds);
|
|
86
|
+
displayString += "".concat(hours, ":").concat(minutes, ":").concat(seconds).concat(decimalSuffix);
|
|
87
|
+
return displayString;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
exports.getDurationDisplayString = getDurationDisplayString;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var isValidPosition = function isValidPosition(lng, lat) {
|
|
6
|
+
return (lng || lng === 0) && (lat || lat === 0);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get formatted geolocation
|
|
11
|
+
* @param {object} loc
|
|
12
|
+
* @param {object} formats , e.g. { geo_format: 'xxx' }
|
|
13
|
+
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
14
|
+
* @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
15
|
+
* @returns formatted geolocation, string
|
|
16
|
+
*/
|
|
17
|
+
var getGeolocationDisplayString = function getGeolocationDisplayString(loc, formats) {
|
|
18
|
+
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
19
|
+
_ref$isBaiduMap = _ref.isBaiduMap,
|
|
20
|
+
isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
|
|
21
|
+
_ref$hyphen = _ref.hyphen,
|
|
22
|
+
hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
|
|
23
|
+
if (!loc) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
var _ref2 = formats || {},
|
|
27
|
+
geo_format = _ref2.geo_format;
|
|
28
|
+
switch (geo_format) {
|
|
29
|
+
case 'lng_lat':
|
|
30
|
+
{
|
|
31
|
+
var _ref3 = loc || {},
|
|
32
|
+
lng = _ref3.lng,
|
|
33
|
+
lat = _ref3.lat;
|
|
34
|
+
if (!isValidPosition(lng, lat)) return '';
|
|
35
|
+
return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
|
|
36
|
+
}
|
|
37
|
+
case 'country_region':
|
|
38
|
+
{
|
|
39
|
+
var _ref4 = loc || {},
|
|
40
|
+
country_region = _ref4.country_region;
|
|
41
|
+
return country_region || '';
|
|
42
|
+
}
|
|
43
|
+
case 'province':
|
|
44
|
+
{
|
|
45
|
+
var _ref5 = loc || {},
|
|
46
|
+
province = _ref5.province;
|
|
47
|
+
return province || '';
|
|
48
|
+
}
|
|
49
|
+
case 'province_city':
|
|
50
|
+
{
|
|
51
|
+
var _ref6 = loc || {},
|
|
52
|
+
_province = _ref6.province,
|
|
53
|
+
city = _ref6.city;
|
|
54
|
+
return "".concat(_province || '').concat(hyphen).concat(city || '').trim();
|
|
55
|
+
}
|
|
56
|
+
case 'province_city_district':
|
|
57
|
+
{
|
|
58
|
+
var _ref7 = loc || {},
|
|
59
|
+
_province2 = _ref7.province,
|
|
60
|
+
_city = _ref7.city,
|
|
61
|
+
district = _ref7.district;
|
|
62
|
+
return "".concat(_province2 || '').concat(hyphen).concat(_city || '').concat(hyphen).concat(district || '').trim();
|
|
63
|
+
}
|
|
64
|
+
default:
|
|
65
|
+
{
|
|
66
|
+
// default as 'geolocation'
|
|
67
|
+
var _ref8 = loc || {},
|
|
68
|
+
_province3 = _ref8.province,
|
|
69
|
+
_city2 = _ref8.city,
|
|
70
|
+
_district = _ref8.district,
|
|
71
|
+
detail = _ref8.detail;
|
|
72
|
+
if (!_province3 && !_city2 && !_district && !detail) return '';
|
|
73
|
+
return "".concat(_province3 || '').concat(hyphen).concat(_city2 || '').concat(hyphen).concat(_district || '').concat(hyphen).concat(detail || '').trim();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.getGeolocationDisplayString = getGeolocationDisplayString;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get text from long-text to display.
|
|
7
|
+
* @param {object} longText e.g. { text: 'xxx' }
|
|
8
|
+
* @returns text from long-text, string
|
|
9
|
+
*/
|
|
10
|
+
var getLongtextDisplayString = function getLongtextDisplayString(longText) {
|
|
11
|
+
if (!longText) return '';
|
|
12
|
+
return longText.text || '';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.getLongtextDisplayString = getLongtextDisplayString;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index = require('../helper/number-precision/index.js');
|
|
6
|
+
var column = require('../constants/column.js');
|
|
7
|
+
var duration = require('./duration.js');
|
|
8
|
+
|
|
9
|
+
var separatorMap = {
|
|
10
|
+
comma: ',',
|
|
11
|
+
dot: '.',
|
|
12
|
+
no: '',
|
|
13
|
+
space: ' '
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* removeZerosFromEnd('0.0100') // '0.01'
|
|
18
|
+
* @param {string} sNumber string of numbers
|
|
19
|
+
*/
|
|
20
|
+
var removeZerosFromEnd = function removeZerosFromEnd(sNumber) {
|
|
21
|
+
if (typeof sNumber !== 'string') return '';
|
|
22
|
+
if (sNumber.endsWith('0')) {
|
|
23
|
+
return sNumber.replace(/(?:\.0*|(\.\d+?)0+)$/, '$1');
|
|
24
|
+
}
|
|
25
|
+
return sNumber;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* e.g. 1.23 // 2
|
|
30
|
+
* @param {number} number
|
|
31
|
+
* @returns digital length
|
|
32
|
+
*/
|
|
33
|
+
var getDecimalDigitsFromNumber = function getDecimalDigitsFromNumber(number) {
|
|
34
|
+
if (Number.isInteger(number)) {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
var decimalPart = String(number).split('.')[1];
|
|
38
|
+
var digitsLength = decimalPart ? decimalPart.length : 8;
|
|
39
|
+
return digitsLength > 8 ? 8 : digitsLength;
|
|
40
|
+
};
|
|
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;
|
|
54
|
+
|
|
55
|
+
// handle numbers in scientific notation
|
|
56
|
+
if (String(number).includes('e')) {
|
|
57
|
+
if (number < 1 && number > -1) {
|
|
58
|
+
// 1.convert to non-scientific number
|
|
59
|
+
var numericString = number.toFixed(enable_precision ? precision : 8);
|
|
60
|
+
|
|
61
|
+
// 2.remove 0 from end of the number which not set precision. e.g. 0.100000
|
|
62
|
+
if (!enable_precision) {
|
|
63
|
+
numericString = removeZerosFromEnd(numericString);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 3.remove minus from number which equal to 0. e.g. '-0.00'
|
|
67
|
+
if (parseFloat(numericString) === 0) {
|
|
68
|
+
return numericString.startsWith('-') ? numericString.substring(1) : numericString;
|
|
69
|
+
}
|
|
70
|
+
return numericString;
|
|
71
|
+
}
|
|
72
|
+
return number;
|
|
73
|
+
}
|
|
74
|
+
var decimalString = separatorMap[decimal];
|
|
75
|
+
var thousandsString = separatorMap[thousands];
|
|
76
|
+
var decimalDigits = enable_precision ? precision : getDecimalDigitsFromNumber(number);
|
|
77
|
+
var floatNumber = parseFloat(number.toFixed(decimalDigits));
|
|
78
|
+
var isMinus = floatNumber < 0;
|
|
79
|
+
var integer = Math.trunc(floatNumber);
|
|
80
|
+
|
|
81
|
+
// format decimal part
|
|
82
|
+
var decimalPart = String(Math.abs(index.NPminus(floatNumber, integer)).toFixed(decimalDigits)).slice(1);
|
|
83
|
+
if (!enable_precision) {
|
|
84
|
+
decimalPart = removeZerosFromEnd(decimalPart);
|
|
85
|
+
}
|
|
86
|
+
if (isCurrency) {
|
|
87
|
+
if (!enable_precision) {
|
|
88
|
+
decimalPart = decimalPart.length === 2 ? decimalPart = decimalPart.padEnd(3, '0') : (decimalPart.substring(0, 3) || '.').padEnd(3, '0');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
decimalPart = decimalPart.replace(/./, decimalString);
|
|
92
|
+
|
|
93
|
+
// format integer part
|
|
94
|
+
var integerNumbers = [];
|
|
95
|
+
var counter = 0;
|
|
96
|
+
integer = Math.abs(integer).toString();
|
|
97
|
+
for (var i = integer.length - 1; i > -1; i--) {
|
|
98
|
+
counter += 1;
|
|
99
|
+
integerNumbers.unshift(integer[i]);
|
|
100
|
+
if (!(counter % 3) && i !== 0) {
|
|
101
|
+
integerNumbers.unshift(thousandsString);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return "".concat(isMinus ? '-' : '').concat(integerNumbers.join('')).concat(decimalPart);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get formatted number
|
|
109
|
+
* @param {number} number e.g. 123
|
|
110
|
+
* @param {object} formats e.g. { format: 'number', decimal: 'dot', ... }
|
|
111
|
+
* @returns formatted number, string
|
|
112
|
+
*/
|
|
113
|
+
var getNumberDisplayString = function getNumberDisplayString(number, formats) {
|
|
114
|
+
var type = Object.prototype.toString.call(number);
|
|
115
|
+
if (type !== '[object Number]') {
|
|
116
|
+
// return formula internal errors directly.
|
|
117
|
+
if (type === '[object String]' && number.startsWith('#')) {
|
|
118
|
+
return number;
|
|
119
|
+
}
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
if (isNaN(number) || number === Infinity || number === -Infinity) return String(number);
|
|
123
|
+
|
|
124
|
+
// 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;
|
|
128
|
+
switch (format) {
|
|
129
|
+
case 'number':
|
|
130
|
+
{
|
|
131
|
+
return toThousands(number, {
|
|
132
|
+
formats: formats,
|
|
133
|
+
isCurrency: false
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
case 'percent':
|
|
137
|
+
{
|
|
138
|
+
return "".concat(toThousands(Number.parseFloat((number * 100).toFixed(8)), {
|
|
139
|
+
formats: formats,
|
|
140
|
+
isCurrency: false
|
|
141
|
+
}), "%");
|
|
142
|
+
}
|
|
143
|
+
case 'yuan':
|
|
144
|
+
{
|
|
145
|
+
return "\uFFE5".concat(toThousands(number, {
|
|
146
|
+
formats: formats
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
case 'dollar':
|
|
150
|
+
{
|
|
151
|
+
return "$".concat(toThousands(number, {
|
|
152
|
+
formats: formats
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
case 'euro':
|
|
156
|
+
{
|
|
157
|
+
return "\u20AC".concat(toThousands(number, {
|
|
158
|
+
formats: formats
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
case 'duration':
|
|
162
|
+
{
|
|
163
|
+
return duration.getDurationDisplayString(number, formats);
|
|
164
|
+
}
|
|
165
|
+
case 'custom_currency':
|
|
166
|
+
{
|
|
167
|
+
if (formats.currency_symbol_position === 'after') {
|
|
168
|
+
return "".concat(toThousands(number, {
|
|
169
|
+
formats: formats
|
|
170
|
+
})).concat(formats.currency_symbol || '');
|
|
171
|
+
}
|
|
172
|
+
return "".concat(formats.currency_symbol || '').concat(toThousands(number, {
|
|
173
|
+
formats: formats
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
{
|
|
178
|
+
return String(number);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Remove illegal characters
|
|
185
|
+
* @param {string} sNum e.g. "1。23"
|
|
186
|
+
* @param {string} format e.g. "number"
|
|
187
|
+
* @param {string} currencySymbol custom symbol
|
|
188
|
+
* @returns legal characters, string
|
|
189
|
+
*/
|
|
190
|
+
var replaceNumberNotAllowInput = function replaceNumberNotAllowInput(sNum, format, currencySymbol) {
|
|
191
|
+
if (!sNum) {
|
|
192
|
+
return '';
|
|
193
|
+
}
|
|
194
|
+
var fixedSNum = sNum.replace(/。/g, '.');
|
|
195
|
+
switch (format) {
|
|
196
|
+
case 'percent':
|
|
197
|
+
{
|
|
198
|
+
return fixedSNum.replace(/[^.-\d,%]/g, '');
|
|
199
|
+
}
|
|
200
|
+
case 'yuan':
|
|
201
|
+
{
|
|
202
|
+
return fixedSNum.replace(/[^.-\d¥¥,]/g, '');
|
|
203
|
+
}
|
|
204
|
+
case 'dollar':
|
|
205
|
+
{
|
|
206
|
+
return fixedSNum.replace(/[^.-\d$,]/g, '');
|
|
207
|
+
}
|
|
208
|
+
case 'euro':
|
|
209
|
+
{
|
|
210
|
+
return fixedSNum.replace(/[^.-\d€,]/g, '');
|
|
211
|
+
}
|
|
212
|
+
case 'custom_currency':
|
|
213
|
+
{
|
|
214
|
+
// eslint-disable-next-line
|
|
215
|
+
var reg = new RegExp('[^.-\d' + currencySymbol + ',]', 'g');
|
|
216
|
+
return fixedSNum.replace(reg, '');
|
|
217
|
+
}
|
|
218
|
+
default:
|
|
219
|
+
{
|
|
220
|
+
// default as number format
|
|
221
|
+
return fixedSNum.replace(/[^.-\d,]/g, '');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
exports.getNumberDisplayString = getNumberDisplayString;
|
|
227
|
+
exports.replaceNumberNotAllowInput = replaceNumberNotAllowInput;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get option name of the given id
|
|
7
|
+
* @param {array} options e.g. [ { id: '', color: '', name: '' } ]
|
|
8
|
+
* @param {string} targetOptionID option id
|
|
9
|
+
* @returns option name, string
|
|
10
|
+
*/
|
|
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
|
+
});
|
|
16
|
+
return targetOption ? targetOption.name : '';
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get concatenated options names of given ids.
|
|
21
|
+
* @param {array} options e.g. [ { id: '', color: '', name: '' }, ... ]
|
|
22
|
+
* @param {array} targetOptionsIds e.g. [ option.id, ... ]
|
|
23
|
+
* @returns concatenated options names, string. e.g. 'name1, name2'
|
|
24
|
+
*/
|
|
25
|
+
var getMultipleOptionName = function getMultipleOptionName(options, targetOptionsIds) {
|
|
26
|
+
if (!Array.isArray(targetOptionsIds) || !Array.isArray(options)) return '';
|
|
27
|
+
var selectedOptions = options.filter(function (option) {
|
|
28
|
+
return targetOptionsIds.includes(option.id);
|
|
29
|
+
});
|
|
30
|
+
if (selectedOptions.length === 0) return '';
|
|
31
|
+
return selectedOptions.map(function (option) {
|
|
32
|
+
return option.name;
|
|
33
|
+
}).join(', ');
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.getMultipleOptionName = getMultipleOptionName;
|
|
37
|
+
exports.getOptionName = getOptionName;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index = require('../helper/number-precision/index.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} sNumber e.g. '1.23'
|
|
9
|
+
* @param {string} format e.g. 'percent'
|
|
10
|
+
* @returns float number from string. e.g. '1.23' = 1.23
|
|
11
|
+
*/
|
|
12
|
+
var getFloatNumber = function getFloatNumber(sNumber, format) {
|
|
13
|
+
if (!sNumber && sNumber !== 0) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof sNumber === 'number') return sNumber;
|
|
17
|
+
if (typeof sNumber !== 'string') return null;
|
|
18
|
+
var parsedNum = parseFloat(sNumber.replace(/[^.-\d]/g, ''));
|
|
19
|
+
if (format === 'percent' && !isNaN(parsedNum)) {
|
|
20
|
+
return index.NPdivide(parsedNum, 100);
|
|
21
|
+
}
|
|
22
|
+
return isNaN(parsedNum) ? null : parsedNum;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* parse string to number depend on formats
|
|
27
|
+
* @param {string} sNum e.g. '1.23'
|
|
28
|
+
* @param {object} formats { format, decimal, ... }
|
|
29
|
+
* @returns parsed number
|
|
30
|
+
*/
|
|
31
|
+
var formatStringToNumber = function formatStringToNumber(sNum, formats) {
|
|
32
|
+
var _ref = formats || {},
|
|
33
|
+
format = _ref.format,
|
|
34
|
+
decimal = _ref.decimal,
|
|
35
|
+
thousands = _ref.thousands,
|
|
36
|
+
enable_precision = _ref.enable_precision,
|
|
37
|
+
precision = _ref.precision;
|
|
38
|
+
var value = sNum;
|
|
39
|
+
if (decimal && thousands && decimal === 'comma') {
|
|
40
|
+
if (thousands === 'dot') {
|
|
41
|
+
value = value.replace(/,/, '@');
|
|
42
|
+
value = value.replace(/\./g, ',');
|
|
43
|
+
value = value.replace(/@/, '.');
|
|
44
|
+
} else {
|
|
45
|
+
value = value.replace(/\./g, '');
|
|
46
|
+
value = value.replace(/,/, '.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
value = getFloatNumber(value, format);
|
|
50
|
+
if (enable_precision && value) {
|
|
51
|
+
var fixedPrecision = format === 'percent' ? precision + 2 : precision;
|
|
52
|
+
value = Number(parseFloat(value).toFixed(fixedPrecision));
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
exports.formatStringToNumber = formatStringToNumber;
|
|
58
|
+
exports.getFloatNumber = getFloatNumber;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var cellType = require('../constants/cell-type.js');
|
|
6
|
+
var formula = require('../constants/formula.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get column type.
|
|
10
|
+
* @param {object} column { type: 'xxx', ... }
|
|
11
|
+
* @returns column type
|
|
12
|
+
*/
|
|
13
|
+
var getCheckType = function getCheckType(column) {
|
|
14
|
+
var type = column.type,
|
|
15
|
+
data = column.data;
|
|
16
|
+
if (formula.FORMULA_COLUMN_TYPES_MAP[type]) {
|
|
17
|
+
var _ref = data || {},
|
|
18
|
+
result_type = _ref.result_type,
|
|
19
|
+
array_type = _ref.array_type;
|
|
20
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.ARRAY) {
|
|
21
|
+
return array_type;
|
|
22
|
+
}
|
|
23
|
+
return result_type;
|
|
24
|
+
}
|
|
25
|
+
if (type === cellType.CellType.LINK) {
|
|
26
|
+
var _ref2 = data || {},
|
|
27
|
+
_array_type = _ref2.array_type;
|
|
28
|
+
return _array_type;
|
|
29
|
+
}
|
|
30
|
+
return type;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get options from single-select/multiple-select column.
|
|
35
|
+
* @param {object} column e.g. { type, data: { options: [] } }
|
|
36
|
+
* @returns options, array
|
|
37
|
+
*/
|
|
38
|
+
var getColumnOptions = function getColumnOptions(column) {
|
|
39
|
+
if (!column || !column.data || !Array.isArray(column.data.options)) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return column.data.options;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.getCheckType = getCheckType;
|
|
46
|
+
exports.getColumnOptions = getColumnOptions;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var common = require('./common.js');
|
|
6
|
+
var column = require('../constants/column.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check whether is date column:
|
|
10
|
+
* - column type is date, ctime or mtime etc.
|
|
11
|
+
* - column type is formula and result_type is date
|
|
12
|
+
* - column type is link/link_fromula and array_type is date, ctime or mtime etc.
|
|
13
|
+
* @param {object} column e.g. { type, data }
|
|
14
|
+
* @returns true/false, bool
|
|
15
|
+
*/
|
|
16
|
+
var isDateColumn = function isDateColumn(column$1) {
|
|
17
|
+
var checkType = common.getCheckType(column$1);
|
|
18
|
+
return column.DATE_COLUMN_OPTIONS.includes(checkType);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.isDateColumn = isDateColumn;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var common = require('./common.js');
|
|
6
|
+
var cellType = require('../constants/cell-type.js');
|
|
7
|
+
var column = require('../constants/column.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check whether is numeric column:
|
|
11
|
+
* - column type is number, duration or rate etc.
|
|
12
|
+
* - column type is formula and result_type is number
|
|
13
|
+
* - column type is link/link_formula and array_type is number, duration or rate etc.
|
|
14
|
+
* @param {object} column e.g. { type, data }
|
|
15
|
+
* @returns true/false, bool
|
|
16
|
+
*/
|
|
17
|
+
var isNumericColumn = function isNumericColumn(column$1) {
|
|
18
|
+
var checkType = common.getCheckType(column$1);
|
|
19
|
+
return column.NUMERIC_COLUMNS_TYPES.includes(checkType);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Check whether is number column:
|
|
24
|
+
* - column type is number
|
|
25
|
+
* - column type is formula and result_type is number
|
|
26
|
+
* - column type is link/link_formula and array_type is number
|
|
27
|
+
* @param {object} column e.g. { type, data }
|
|
28
|
+
* @returns true/false, bool
|
|
29
|
+
*/
|
|
30
|
+
var isNumberColumn = function isNumberColumn(column) {
|
|
31
|
+
var checkType = common.getCheckType(column);
|
|
32
|
+
return checkType === cellType.CellType.NUMBER;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.isNumberColumn = isNumberColumn;
|
|
36
|
+
exports.isNumericColumn = isNumericColumn;
|