Skip to content

Commit

Permalink
chore: iterate types and isFinite
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjoverm committed Nov 19, 2024
1 parent 5698b6e commit 1b83ebb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Storyblok {
private client: SbFetch;
private maxRetries: number;
private retriesDelay: number;
private throttle;
private throttle: ReturnType<typeof throttledQueue>;
private accessToken: string;
private cache: ISbCache;
private helpers: SbHelpers;
Expand Down Expand Up @@ -145,6 +145,7 @@ class Storyblok {
rateLimit,
1000,
);

this.accessToken = config.accessToken || '';
this.relations = {} as RelationsType;
this.links = {} as LinksType;
Expand Down
12 changes: 2 additions & 10 deletions src/throttlePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@ class AbortError extends Error {
}
}

function isFinite(value: number) {
if (Number.isNaN(value) || value === Infinity || value === -Infinity) {
return false;
}

return true;
}

function throttledQueue<T extends (...args: Parameters<T>) => ReturnType<T>>(
fn: T,
limit: number,
interval: number,
): ISbThrottle<T> {
if (!isFinite(limit)) {
if (!Number.isFinite(limit)) {
throw new TypeError('Expected `limit` to be a finite number');
}

if (!isFinite(interval)) {
if (!Number.isFinite(interval)) {
throw new TypeError('Expected `interval` to be a finite number');
}

Expand Down

0 comments on commit 1b83ebb

Please sign in to comment.