Skip to content

Commit 91ca223

Browse files
committedNov 11, 2020
chore(parse): Improve backward compatibility
Avoid using Set and Array.from to maximize compatibility.
1 parent 1eed25b commit 91ca223

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

‎parse.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ const fieldsConfig: FieldConfig[] = [
6969
{ name: "Year", min: 1970, max: 3000, adjustment: 0, names: {} },
7070
];
7171

72+
function uniq<T>(source: T[]): T[] {
73+
const target = [];
74+
for (const item of source) {
75+
if (target.indexOf(item) < 0) {
76+
target.push(item);
77+
}
78+
}
79+
return target;
80+
}
81+
7282
function parseField(input: string, field: Field): number[] | undefined {
7383
if (input === "*") return undefined;
7484
const config = fieldsConfig[field];
@@ -103,9 +113,7 @@ function parseField(input: string, field: Field): number[] | undefined {
103113
return range;
104114
}
105115

106-
return Array.from(new Set(input.split(",").map(parseValue))).sort(
107-
(a, b) => a - b
108-
);
116+
return uniq(input.split(",").map(parseValue)).sort((a, b) => a - b);
109117
}
110118

111119
/**

0 commit comments

Comments
 (0)
Please sign in to comment.