@etsoo/shared 1.2.11 → 1.2.12
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/__tests__/ArrayUtils.ts +31 -1
- package/lib/cjs/ArrayUtils.js +3 -6
- package/lib/mjs/ArrayUtils.js +3 -6
- package/package.json +1 -1
- package/src/ArrayUtils.ts +2 -3
package/__tests__/ArrayUtils.ts
CHANGED
|
@@ -63,7 +63,7 @@ test('Tests for maxItem / minItem', () => {
|
|
|
63
63
|
expect(emptyItems.maxItem('amount')).toBeUndefined();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
test('Tests for sortIds', () => {
|
|
66
|
+
test('Tests for sortIds 1', () => {
|
|
67
67
|
const source = [
|
|
68
68
|
{
|
|
69
69
|
id: 'zh-Hans',
|
|
@@ -91,3 +91,33 @@ test('Tests for sortIds', () => {
|
|
|
91
91
|
const ids = source.map((s) => s.id);
|
|
92
92
|
expect(ids).toStrictEqual(['en', 'zh-Hans', 'zh-Hant', 'fr', 'de']);
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
test('Tests for sortIds 2', () => {
|
|
96
|
+
const source = [
|
|
97
|
+
{ id: 'AUD', label: '澳元' },
|
|
98
|
+
{ id: 'CAD', label: '加元' },
|
|
99
|
+
{ id: 'CNY', label: '人民币' },
|
|
100
|
+
{ id: 'EUR', label: '欧元' },
|
|
101
|
+
{ id: 'GBP', label: '英镑' },
|
|
102
|
+
{ id: 'HKD', label: '港币' },
|
|
103
|
+
{ id: 'JPY', label: '日元' },
|
|
104
|
+
{ id: 'NZD', label: '纽币' },
|
|
105
|
+
{ id: 'SGD', label: '新币' },
|
|
106
|
+
{ id: 'USD', label: '美元' }
|
|
107
|
+
];
|
|
108
|
+
source.sortByProperty('id', ['USD', 'CNY']);
|
|
109
|
+
|
|
110
|
+
const ids = source.map((s) => s.id);
|
|
111
|
+
expect(ids).toStrictEqual([
|
|
112
|
+
'USD',
|
|
113
|
+
'CNY',
|
|
114
|
+
'AUD',
|
|
115
|
+
'CAD',
|
|
116
|
+
'EUR',
|
|
117
|
+
'GBP',
|
|
118
|
+
'HKD',
|
|
119
|
+
'JPY',
|
|
120
|
+
'NZD',
|
|
121
|
+
'SGD'
|
|
122
|
+
]);
|
|
123
|
+
});
|
package/lib/cjs/ArrayUtils.js
CHANGED
|
@@ -47,12 +47,9 @@ Array.prototype.sortByProperty = function (property, values) {
|
|
|
47
47
|
const bi = values.indexOf(b[property]);
|
|
48
48
|
if (ai === bi)
|
|
49
49
|
return 0;
|
|
50
|
-
if (ai < 0)
|
|
51
|
-
return bi;
|
|
52
|
-
|
|
53
|
-
return -ai;
|
|
54
|
-
else
|
|
55
|
-
return ai - bi;
|
|
50
|
+
if (ai < 0 || bi < 0)
|
|
51
|
+
return bi === 0 ? 1 : bi;
|
|
52
|
+
return ai - bi;
|
|
56
53
|
});
|
|
57
54
|
};
|
|
58
55
|
Array.prototype.sum = function (field) {
|
package/lib/mjs/ArrayUtils.js
CHANGED
|
@@ -41,12 +41,9 @@ Array.prototype.sortByProperty = function (property, values) {
|
|
|
41
41
|
const bi = values.indexOf(b[property]);
|
|
42
42
|
if (ai === bi)
|
|
43
43
|
return 0;
|
|
44
|
-
if (ai < 0)
|
|
45
|
-
return bi;
|
|
46
|
-
|
|
47
|
-
return -ai;
|
|
48
|
-
else
|
|
49
|
-
return ai - bi;
|
|
44
|
+
if (ai < 0 || bi < 0)
|
|
45
|
+
return bi === 0 ? 1 : bi;
|
|
46
|
+
return ai - bi;
|
|
50
47
|
});
|
|
51
48
|
};
|
|
52
49
|
Array.prototype.sum = function (field) {
|
package/package.json
CHANGED
package/src/ArrayUtils.ts
CHANGED
|
@@ -151,9 +151,8 @@ Array.prototype.sortByProperty = function <T, P extends keyof T>(
|
|
|
151
151
|
const bi = values.indexOf(b[property]);
|
|
152
152
|
|
|
153
153
|
if (ai === bi) return 0;
|
|
154
|
-
if (ai < 0) return bi;
|
|
155
|
-
|
|
156
|
-
else return ai - bi;
|
|
154
|
+
if (ai < 0 || bi < 0) return bi === 0 ? 1 : bi;
|
|
155
|
+
return ai - bi;
|
|
157
156
|
});
|
|
158
157
|
};
|
|
159
158
|
|