-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-bare-specifier.mts
38 lines (34 loc) · 999 Bytes
/
is-bare-specifier.mts
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
31
32
33
34
35
36
37
38
/**
* @file isBareSpecifier
* @module mlly/lib/isBareSpecifier
*/
import isAbsoluteSpecifier from '#lib/is-absolute-specifier'
import isRelativeSpecifier from '#lib/is-relative-specifier'
import { isBuiltin } from '@flex-development/is-builtin'
import type { ModuleId } from '@flex-development/mlly'
/**
* Check if `specifier` is a *bare specifier*.
*
* ::: warning
* Only checks specifier syntax. Does **not** guarantee the specifier references
* a file that exists.
* :::
*
* @see {@linkcode ModuleId}
* @see https://nodejs.org/api/esm.html#terminology
*
* @param {ModuleId} specifier
* Specifier to check
* @return {boolean}
* `true` if `specifier` is bare specifier, `false` otherwise
*/
function isBareSpecifier(specifier: ModuleId): boolean {
if (isBuiltin(specifier)) return true
return (
typeof specifier === 'string' &&
!!specifier.length &&
!isAbsoluteSpecifier(specifier) &&
!isRelativeSpecifier(specifier)
)
}
export default isBareSpecifier