Skip to content

Commit be9d03e

Browse files
author
Thomas Leung
committed
Fix lint warnings in parseDuration.js
Signed-off-by: Thomas Leung <[email protected]>
1 parent 1b0348e commit be9d03e

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

packages/apollo/src/utils/parseDuration.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const unit = Object.create(null);
22

33
const m = 60000,
4-
h = m * 60,
5-
d = h * 24,
6-
y = d * 365.25;
4+
h = m * 60,
5+
d = h * 24,
6+
y = d * 365.25;
77

88
unit.year = unit.yr = unit.y = y;
99
unit.month = unit.mo = unit.mth = y / 12;
@@ -37,34 +37,34 @@ export default function parse(str = '', format = 'ms') {
3737

3838
String(str)
3939
.replace(
40-
new RegExp(`(\\d)[${parse.unit.placeholder}${parse.unit.group}](\\d)`, 'g'),
41-
'$1$2'
40+
new RegExp(`(\\d)[${parse.unit.placeholder}${parse.unit.group}](\\d)`, 'g'),
41+
'$1$2'
4242
) // clean up group separators / placeholders
4343
.replace(parse.unit.decimal, '.') // normalize decimal separator
4444
.replace(durationRE, (_, n, units) => {
45-
// if no units, find next smallest units or fall back to format value
46-
// eg. 1h30 -> 1h30m
47-
if (!units) {
48-
if (prevUnits) {
49-
for (const u in parse.unit) {
50-
if (parse.unit[u] < prevUnits) {
51-
units = u;
52-
break;
53-
}
45+
// if no units, find next smallest units or fall back to format value
46+
// eg. 1h30 -> 1h30m
47+
if (!units) {
48+
if (prevUnits) {
49+
for (const u in parse.unit) {
50+
if (parse.unit[u] < prevUnits) {
51+
units = u;
52+
break;
53+
}
54+
}
55+
} else {
56+
units = format;
57+
}
58+
} else {
59+
units = units.toLowerCase();
5460
}
55-
} else {
56-
units = format;
57-
}
58-
} else {
59-
units = units.toLowerCase();
60-
}
6161

62-
prevUnits = units = parse.unit[units] || parse.unit[units.replace(/s$/, '')];
62+
prevUnits = units = parse.unit[units] || parse.unit[units.replace(/s$/, '')];
6363

64-
if (units) {
65-
result = (result || 0) + n * units;
66-
}
64+
if (units) {
65+
result = (result || 0) + n * units;
66+
}
6767
});
6868

6969
return result && (result / (parse.unit[format] || 1)) * (str[0] === '-' ? -1 : 1);
70-
}
70+
}

0 commit comments

Comments
 (0)