Skip to content

Commit

Permalink
Fixed default fs import for top-level await
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Apr 18, 2024
1 parent ac1a148 commit 6936afd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/objects.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
export function filterObject<T extends object, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K> {
const entries = <[K, T[K]][]>Object.entries(object);
return <Omit<T, K>>(<unknown>Object.fromEntries(entries.filter(([key]) => keys.includes(key))));
}

import type * as FS from 'fs';

// default fs for FileMap
let _fs: typeof FS;
try {
_fs = await import('fs');
} catch (e) {
_fs = null;
import('fs').then(_ => (_fs = _));

export function filterObject<T extends object, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K> {
const entries = <[K, T[K]][]>Object.entries(object);
return <Omit<T, K>>(<unknown>Object.fromEntries(entries.filter(([key]) => keys.includes(key))));
}

export function isJSON(str: string) {
Expand Down

0 comments on commit 6936afd

Please sign in to comment.