Skip to content

Commit

Permalink
utils: adjust checkOpts to work in proxied envs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Feb 9, 2024
1 parent 2df3b11 commit 2e49a16
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,12 @@ export function concatBytes(...arrays: Uint8Array[]): Uint8Array {
return res;
}

// Check if object doens't have custom constructor (like Uint8Array/Array)
const isPlainObject = (obj: any) =>
Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;

type EmptyObj = {};
export function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(
defaults: T1,
opts?: T2
opts: T2
): T1 & T2 {
if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
throw new Error('options must be object or undefined');
if (opts == null || typeof opts !== 'object') throw new Error('options must be defined');
const merged = Object.assign(defaults, opts);
return merged as T1 & T2;
}
Expand Down

0 comments on commit 2e49a16

Please sign in to comment.