-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Config expiresIn can contain periods. i.e, 1.5 weeks
- Loading branch information
Showing
4 changed files
with
61 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const ALPHA_NUMERIC_DOT = /([0-9.]+)([a-zA-Z]+)/g; | ||
const TIMES = { | ||
ms: 1, | ||
millisecond: 1, | ||
milliseconds: 1, | ||
s: 1000, | ||
sec: 1000, | ||
secs: 1000, | ||
second: 1000, | ||
seconds: 1000, | ||
m: 60000, | ||
min: 60000, | ||
mins: 60000, | ||
minute: 60000, | ||
minutes: 60000, | ||
h: 3600000, | ||
hr: 3600000, | ||
hrs: 3600000, | ||
hour: 3600000, | ||
hours: 3600000, | ||
d: 86400000, | ||
day: 86400000, | ||
days: 86400000, | ||
w: 604800000, | ||
wk: 604800000, | ||
wks: 604800000, | ||
week: 604800000, | ||
weeks: 604800000, | ||
y: 31536000000, | ||
yr: 31536000000, | ||
yrs: 31536000000, | ||
year: 31536000000, | ||
years: 31536000000 | ||
}; | ||
|
||
export default function dehumanizeTime(input) { | ||
if (typeof input !== 'string') { | ||
return NaN; | ||
} | ||
|
||
const parts = input.replace(/ /g, '').match(ALPHA_NUMERIC_DOT); | ||
const sets = parts.map(part => part.split(ALPHA_NUMERIC_DOT).filter(o => o)); | ||
|
||
return sets.reduce((accum, [number, unit]) => { | ||
return accum + parseFloat(number) * TIMES[unit]; | ||
}, 0); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters