forked from mdx-js/eslint-mdx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.ts
More file actions
30 lines (26 loc) · 795 Bytes
/
helpers.ts
File metadata and controls
30 lines (26 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { createRequire } from 'node:module'
import type { CjsRequire } from 'eslint-mdx'
export const getGlobals = <
T extends Record<string, unknown> | string[],
G extends Record<string, boolean>,
R extends G = G & Record<T extends Array<infer R> ? R : keyof T, false>,
>(
sources: T,
initialGlobals: G = {} as G,
): R =>
(Array.isArray(sources)
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
(sources as string[])
: Object.keys(sources)
).reduce(
(globals, source) =>
Object.assign(globals, {
[source]: false,
}),
initialGlobals as R,
)
const importMetaUrl = import.meta.url
/* istanbul ignore next */
export const cjsRequire: CjsRequire = importMetaUrl
? createRequire(importMetaUrl)
: require