File tree Expand file tree Collapse file tree 2 files changed +29
-11
lines changed Expand file tree Collapse file tree 2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type {
7
7
RateLimitInfo ,
8
8
ParserOptions ,
9
9
} from './types'
10
+ import { secondsToDate , toInt } from './utilities.js'
10
11
11
12
/**
12
13
* Parses the passed response/headers object and returns rate limit information.
@@ -136,17 +137,6 @@ export function parseCombinedRateLimitHeader(header: string): RateLimitInfo {
136
137
}
137
138
}
138
139
139
- function secondsToDate ( seconds : number ) : Date {
140
- const d = new Date ( )
141
- d . setSeconds ( d . getSeconds ( ) + seconds )
142
- return d
143
- }
144
-
145
- function toInt ( input : string | number | undefined ) : number {
146
- if ( typeof input === 'number' ) return input
147
- return Number . parseInt ( input ?? '' , 10 )
148
- }
149
-
150
140
function getHeader ( headers : HeadersObject , name : string ) : string | undefined {
151
141
if ( 'get' in headers && typeof headers . get === 'function' ) {
152
142
return headers . get ( name ) ?? undefined // Returns null if missing, but everything else is undefined for missing values
Original file line number Diff line number Diff line change
1
+ // source/utilities.ts
2
+ // The utility functions for the library
3
+
4
+ /**
5
+ * Adds the given number of seconds to the current time and returns a `Date`.
6
+ *
7
+ * @param seconds {number} - The number of seconds to add to the current time.
8
+ *
9
+ * @return {Date } - The date, with a timestamp n seconds from now.
10
+ */
11
+ export const secondsToDate = ( seconds : number ) : Date => {
12
+ const date = new Date ( )
13
+ date . setSeconds ( date . getSeconds ( ) + seconds )
14
+ return date
15
+ }
16
+
17
+ /**
18
+ * Converts a string/number to a number.
19
+ *
20
+ * @param input {string | number | undefined} - The input to convert to a number.
21
+ *
22
+ * @return {number } - The parsed integer.
23
+ * @throws {Error } - Thrown if the string does not contain a valid number.
24
+ */
25
+ export const toInt = ( input : string | number | undefined ) : number => {
26
+ if ( typeof input === 'number' ) return input
27
+ return Number . parseInt ( input ?? '' , 10 )
28
+ }
You can’t perform that action at this time.
0 commit comments