-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis-relative-specifier.mts
More file actions
42 lines (37 loc) · 925 Bytes
/
is-relative-specifier.mts
File metadata and controls
42 lines (37 loc) · 925 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
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @file isRelativeSpecifier
* @module mlly/lib/isRelativeSpecifier
*/
import pathe from '@flex-development/pathe'
/**
* Check if `value` is a *relative specifier*.
*
* ::: warning
* Only checks specifier syntax.
* Does **not** guarantee the specifier references an existing module.
* :::
*
* @see https://nodejs.org/api/esm.html#terminology
*
* @this {void}
*
* @param {unknown} value
* The value to check
* @return {boolean}
* `true` if `value` is relative specifier, `false` otherwise
*/
function isRelativeSpecifier(this: void, value: unknown): boolean {
if (typeof value === 'string') {
if (value[0] === pathe.dot) {
if (value.length === 1 || value[1] === pathe.sep) return true
if (
value[1] === pathe.dot &&
(value.length === 2 || value[2] === pathe.sep)
) {
return true
}
}
}
return false
}
export default isRelativeSpecifier