Skip to content

Commit 3c2c6ee

Browse files
authoredJun 24, 2023
fix: update MinMax plugin 1. ignore the 'null' in args 2. return the only one arg (#2330)
1 parent 013968f commit 3c2c6ee

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎src/plugin/minMax/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
export default (o, c, d) => {
22
const sortBy = (method, dates) => {
3-
if (!dates || !dates.length || !dates[0] || (dates.length === 1 && !dates[0].length)) {
3+
if (
4+
!dates ||
5+
!dates.length ||
6+
(dates.length === 1 && !dates[0]) ||
7+
(dates.length === 1 && Array.isArray(dates[0]) && !dates[0].length)
8+
) {
49
return null
510
}
611
if (dates.length === 1 && dates[0].length > 0) {
712
[dates] = dates
813
}
9-
let result
14+
dates = dates.filter(date => date)
15+
let result;
1016
[result] = dates
1117
for (let i = 1; i < dates.length; i += 1) {
1218
if (!dates[i].isValid() || dates[i][method](result)) {

‎test/plugin/minMax.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ it('If Invalid Date return Invalid Date', () => {
5555
expect(dayjs.min([arg1, arg2, arg3, arg4]).format())
5656
.toBe(arg4.format())
5757
})
58+
59+
it('Ignore if exists an "null" argument', () => {
60+
expect(dayjs.max(null, null, arg1, arg2, null, arg3).format())
61+
.toBe(arg1.format())
62+
expect(dayjs.min([null, null, arg1, arg2, null, arg3]).format())
63+
.toBe(arg3.format())
64+
})
65+
66+
it('Return the only date if just provided one argument', () => {
67+
expect(dayjs.max(arg1).format())
68+
.toBe(arg1.format())
69+
expect(dayjs.min([arg1]).format())
70+
.toBe(arg1.format())
71+
})

0 commit comments

Comments
 (0)
Please sign in to comment.