dtable-utils 0.0.4-beta.1 → 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.
- package/README.md +14 -0
- package/es/column/option.js +2 -4
- package/es/filter/core.js +1 -1
- package/es/sort/sort-column/number.js +9 -3
- package/es/sort/sort-column/single-select.js +9 -3
- package/es/sort/sort-column/text.js +12 -4
- package/lib/column/option.js +2 -4
- package/lib/filter/core.js +1 -1
- package/lib/sort/sort-column/number.js +9 -3
- package/lib/sort/sort-column/single-select.js +9 -3
- package/lib/sort/sort-column/text.js +12 -4
- package/package.json +1 -1
package/README.md
CHANGED
package/es/column/option.js
CHANGED
|
@@ -86,10 +86,9 @@ var createOption = function createOption(options, optionName) {
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Generate cell option by name.
|
|
89
|
-
* Return the option id if exist, otherwise generate a new option
|
|
90
89
|
* @param {array} options e.g. [{ id, ... }, ...]
|
|
91
90
|
* @param {string} optionName used as the option name
|
|
92
|
-
* @returns option id
|
|
91
|
+
* @returns return the option id if exist, otherwise generate a new option, object
|
|
93
92
|
*/
|
|
94
93
|
var generatorCellOption = function generatorCellOption(options, optionName) {
|
|
95
94
|
var existOption = options.find(function (option) {
|
|
@@ -109,10 +108,9 @@ var generatorCellOption = function generatorCellOption(options, optionName) {
|
|
|
109
108
|
|
|
110
109
|
/**
|
|
111
110
|
* Generate cell options by names.
|
|
112
|
-
* Return the options ids if exist, otherwise generate new options
|
|
113
111
|
* @param {array} options e.g. [{ id, ... }, ...]
|
|
114
112
|
* @param {array} optionNames used as the options names
|
|
115
|
-
* @returns options ids
|
|
113
|
+
* @returns Return the options ids if exist, otherwise generate new options, object
|
|
116
114
|
*/
|
|
117
115
|
var generatorCellOptions = function generatorCellOptions(options, optionNames) {
|
|
118
116
|
var cellOptions = [];
|
package/es/filter/core.js
CHANGED
|
@@ -54,7 +54,7 @@ var otherDate = function otherDate(filterTermModifier, filterTerm) {
|
|
|
54
54
|
var month = today.getMonth(); // use js month representation: 0 - 11
|
|
55
55
|
var day = today.getDate();
|
|
56
56
|
|
|
57
|
-
// 0 1 2 3 4 5 6 7 8 9 10 11
|
|
57
|
+
// 0 1 2 3 4 5 6 7 8 9 10 11 days in every month
|
|
58
58
|
var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
59
59
|
days[1] = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28; // is leap year
|
|
60
60
|
switch (filterTermModifier) {
|
|
@@ -10,9 +10,15 @@ import { SORT_TYPE } from '../../constants/sort.js';
|
|
|
10
10
|
var sortNumber = function sortNumber(leftNumber, rightNumber, sortType) {
|
|
11
11
|
var emptyLeftNumber = !leftNumber && leftNumber !== 0;
|
|
12
12
|
var emptyRightNumber = !rightNumber && rightNumber !== 0;
|
|
13
|
-
if (emptyLeftNumber && emptyRightNumber)
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (emptyLeftNumber && emptyRightNumber) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
if (emptyLeftNumber) {
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
if (emptyRightNumber) {
|
|
20
|
+
return -1;
|
|
21
|
+
}
|
|
16
22
|
if (leftNumber > rightNumber) {
|
|
17
23
|
return sortType === SORT_TYPE.UP ? 1 : -1;
|
|
18
24
|
}
|
|
@@ -15,9 +15,15 @@ var sortSingleSelect = function sortSingleSelect(leftOptionId, rightOptionId, _r
|
|
|
15
15
|
var nextOptionIdIndex = option_id_index_map[rightOptionId];
|
|
16
16
|
var emptyLeftOptionId = !currentOptionIdIndex && currentOptionIdIndex !== 0;
|
|
17
17
|
var emptyRightOptionId = !nextOptionIdIndex && nextOptionIdIndex !== 0;
|
|
18
|
-
if (emptyLeftOptionId && emptyRightOptionId)
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (emptyLeftOptionId && emptyRightOptionId) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
if (emptyLeftOptionId) {
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
if (emptyRightOptionId) {
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
21
27
|
if (currentOptionIdIndex > nextOptionIdIndex) {
|
|
22
28
|
return sort_type === SORT_TYPE.UP ? 1 : -1;
|
|
23
29
|
}
|
|
@@ -51,10 +51,18 @@ var compareString = function compareString(leftString, rightString) {
|
|
|
51
51
|
var sortText = function sortText(leftText, rightText, sortType) {
|
|
52
52
|
var emptyLeftText = !leftText;
|
|
53
53
|
var emptyRightText = !rightText;
|
|
54
|
-
if (emptyLeftText && emptyRightText)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
54
|
+
if (emptyLeftText && emptyRightText) {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
if (emptyLeftText) {
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
if (emptyRightText) {
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
if (rightText === leftText) {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
58
66
|
return sortType === SORT_TYPE.UP ? compareString(leftText, rightText) : -1 * compareString(leftText, rightText);
|
|
59
67
|
};
|
|
60
68
|
|
package/lib/column/option.js
CHANGED
|
@@ -90,10 +90,9 @@ var createOption = function createOption(options, optionName) {
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Generate cell option by name.
|
|
93
|
-
* Return the option id if exist, otherwise generate a new option
|
|
94
93
|
* @param {array} options e.g. [{ id, ... }, ...]
|
|
95
94
|
* @param {string} optionName used as the option name
|
|
96
|
-
* @returns option id
|
|
95
|
+
* @returns return the option id if exist, otherwise generate a new option, object
|
|
97
96
|
*/
|
|
98
97
|
var generatorCellOption = function generatorCellOption(options, optionName) {
|
|
99
98
|
var existOption = options.find(function (option) {
|
|
@@ -113,10 +112,9 @@ var generatorCellOption = function generatorCellOption(options, optionName) {
|
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
* Generate cell options by names.
|
|
116
|
-
* Return the options ids if exist, otherwise generate new options
|
|
117
115
|
* @param {array} options e.g. [{ id, ... }, ...]
|
|
118
116
|
* @param {array} optionNames used as the options names
|
|
119
|
-
* @returns options ids
|
|
117
|
+
* @returns Return the options ids if exist, otherwise generate new options, object
|
|
120
118
|
*/
|
|
121
119
|
var generatorCellOptions = function generatorCellOptions(options, optionNames) {
|
|
122
120
|
var cellOptions = [];
|
package/lib/filter/core.js
CHANGED
|
@@ -62,7 +62,7 @@ var otherDate = function otherDate(filterTermModifier, filterTerm) {
|
|
|
62
62
|
var month = today.getMonth(); // use js month representation: 0 - 11
|
|
63
63
|
var day = today.getDate();
|
|
64
64
|
|
|
65
|
-
// 0 1 2 3 4 5 6 7 8 9 10 11
|
|
65
|
+
// 0 1 2 3 4 5 6 7 8 9 10 11 days in every month
|
|
66
66
|
var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
67
67
|
days[1] = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28; // is leap year
|
|
68
68
|
switch (filterTermModifier) {
|
|
@@ -14,9 +14,15 @@ var sort = require('../../constants/sort.js');
|
|
|
14
14
|
var sortNumber = function sortNumber(leftNumber, rightNumber, sortType) {
|
|
15
15
|
var emptyLeftNumber = !leftNumber && leftNumber !== 0;
|
|
16
16
|
var emptyRightNumber = !rightNumber && rightNumber !== 0;
|
|
17
|
-
if (emptyLeftNumber && emptyRightNumber)
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (emptyLeftNumber && emptyRightNumber) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
if (emptyLeftNumber) {
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
if (emptyRightNumber) {
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
20
26
|
if (leftNumber > rightNumber) {
|
|
21
27
|
return sortType === sort.SORT_TYPE.UP ? 1 : -1;
|
|
22
28
|
}
|
|
@@ -19,9 +19,15 @@ var sortSingleSelect = function sortSingleSelect(leftOptionId, rightOptionId, _r
|
|
|
19
19
|
var nextOptionIdIndex = option_id_index_map[rightOptionId];
|
|
20
20
|
var emptyLeftOptionId = !currentOptionIdIndex && currentOptionIdIndex !== 0;
|
|
21
21
|
var emptyRightOptionId = !nextOptionIdIndex && nextOptionIdIndex !== 0;
|
|
22
|
-
if (emptyLeftOptionId && emptyRightOptionId)
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (emptyLeftOptionId && emptyRightOptionId) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
if (emptyLeftOptionId) {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
if (emptyRightOptionId) {
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
25
31
|
if (currentOptionIdIndex > nextOptionIdIndex) {
|
|
26
32
|
return sort_type === sort.SORT_TYPE.UP ? 1 : -1;
|
|
27
33
|
}
|
|
@@ -55,10 +55,18 @@ var compareString = function compareString(leftString, rightString) {
|
|
|
55
55
|
var sortText = function sortText(leftText, rightText, sortType) {
|
|
56
56
|
var emptyLeftText = !leftText;
|
|
57
57
|
var emptyRightText = !rightText;
|
|
58
|
-
if (emptyLeftText && emptyRightText)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
58
|
+
if (emptyLeftText && emptyRightText) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (emptyLeftText) {
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
if (emptyRightText) {
|
|
65
|
+
return -1;
|
|
66
|
+
}
|
|
67
|
+
if (rightText === leftText) {
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
62
70
|
return sortType === sort.SORT_TYPE.UP ? compareString(leftText, rightText) : -1 * compareString(leftText, rightText);
|
|
63
71
|
};
|
|
64
72
|
|