@flex-development/mlly 1.0.0-alpha.16 → 1.0.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/index.mjs.map +4 -5
  3. package/dist/internal/dequote.mjs +1 -0
  4. package/dist/internal/dequote.mjs.map +8 -0
  5. package/dist/internal/format-type-map.mjs +1 -0
  6. package/dist/internal/format-type-map.mjs.map +8 -0
  7. package/dist/internal/get-specifier-kind.mjs +1 -0
  8. package/dist/internal/get-specifier-kind.mjs.map +8 -0
  9. package/dist/internal/get-subpaths.mjs +1 -0
  10. package/dist/internal/get-subpaths.mjs.map +8 -0
  11. package/dist/internal/regex-encoded-sep.mjs +1 -0
  12. package/dist/internal/regex-encoded-sep.mjs.map +8 -0
  13. package/dist/internal/regex-internal-specifier.mjs +1 -0
  14. package/dist/internal/regex-internal-specifier.mjs.map +8 -0
  15. package/dist/internal/regex-invalid-segment.mjs +1 -0
  16. package/dist/internal/regex-invalid-segment.mjs.map +8 -0
  17. package/dist/internal/regex-package-name.mjs +1 -0
  18. package/dist/internal/regex-package-name.mjs.map +8 -0
  19. package/dist/internal/regex-package-path.mjs +1 -0
  20. package/dist/internal/regex-package-path.mjs.map +8 -0
  21. package/dist/internal/resolver.mjs +1 -0
  22. package/dist/internal/resolver.mjs.map +8 -0
  23. package/dist/internal/validate-array-set.mjs +1 -0
  24. package/dist/internal/validate-array-set.mjs.map +8 -0
  25. package/dist/internal/validate-boolean.mjs +1 -0
  26. package/dist/internal/validate-boolean.mjs.map +8 -0
  27. package/dist/internal/validate-map.mjs +1 -0
  28. package/dist/internal/validate-map.mjs.map +8 -0
  29. package/dist/internal/validate-object.mjs +1 -0
  30. package/dist/internal/validate-object.mjs.map +8 -0
  31. package/dist/internal/validate-set.mjs +1 -0
  32. package/dist/internal/validate-set.mjs.map +8 -0
  33. package/dist/internal/validate-string.mjs +1 -0
  34. package/dist/internal/validate-string.mjs.map +8 -0
  35. package/dist/internal/validate-url-string.mjs +1 -0
  36. package/dist/internal/validate-url-string.mjs.map +8 -0
  37. package/dist/utils/compare-subpaths.mjs.map +4 -5
  38. package/dist/utils/conditions.mjs.map +4 -5
  39. package/dist/utils/detect-syntax.mjs.map +4 -5
  40. package/dist/utils/extension-format-map.mjs.map +4 -5
  41. package/dist/utils/extract-statements.mjs.map +4 -5
  42. package/dist/utils/fill-modules.mjs.map +5 -8
  43. package/dist/utils/find-dynamic-imports.mjs.map +5 -8
  44. package/dist/utils/find-exports.mjs.map +5 -8
  45. package/dist/utils/find-requires.mjs.map +5 -8
  46. package/dist/utils/find-static-imports.mjs.map +5 -8
  47. package/dist/utils/find-subpath.mjs.map +5 -9
  48. package/dist/utils/get-format.mjs.map +5 -8
  49. package/dist/utils/get-source.mjs.map +4 -5
  50. package/dist/utils/has-cjs-syntax.mjs.map +4 -5
  51. package/dist/utils/has-esm-syntax.mjs.map +4 -5
  52. package/dist/utils/index.mjs.map +5 -8
  53. package/dist/utils/is-absolute-specifier.mjs.map +4 -5
  54. package/dist/utils/is-bare-specifier.mjs.map +4 -5
  55. package/dist/utils/is-directory.mjs.map +4 -5
  56. package/dist/utils/is-exports-sugar.mjs.map +4 -5
  57. package/dist/utils/is-file.mjs.map +4 -5
  58. package/dist/utils/is-relative-specifier.mjs.map +4 -5
  59. package/dist/utils/lookup-package-scope.mjs.map +4 -5
  60. package/dist/utils/parse-data-url.mjs.map +4 -5
  61. package/dist/utils/parse-module-id.mjs.map +5 -9
  62. package/dist/utils/parse-subpath.mjs.map +5 -8
  63. package/dist/utils/pattern-character.mjs.map +4 -5
  64. package/dist/utils/read-package-json.mjs.map +4 -5
  65. package/dist/utils/resolve-alias.mjs.map +5 -9
  66. package/dist/utils/resolve-aliases.mjs.map +4 -5
  67. package/dist/utils/resolve-extensions.mjs.map +4 -5
  68. package/dist/utils/resolve-module.mjs.map +4 -5
  69. package/dist/utils/resolve-modules.mjs.map +4 -5
  70. package/dist/utils/to-absolute-specifier.mjs.map +4 -5
  71. package/dist/utils/to-bare-specifier.mjs.map +4 -5
  72. package/dist/utils/to-data-url.mjs.map +4 -5
  73. package/dist/utils/to-node-url.mjs.map +4 -5
  74. package/dist/utils/to-relative-specifier.mjs.map +4 -5
  75. package/dist/utils/to-url.mjs.map +4 -5
  76. package/dist/utils/validate-assertions.mjs.map +5 -8
  77. package/dist/utils/validate-exports.mjs.map +4 -5
  78. package/package.json +8 -9
  79. package/src/enums/assert-type.ts +0 -23
  80. package/src/enums/format.ts +0 -19
  81. package/src/enums/index.ts +0 -11
  82. package/src/enums/kind-specifier-syntax.ts +0 -16
  83. package/src/enums/kind-specifier.ts +0 -19
  84. package/src/enums/kind-statement-syntax.ts +0 -24
  85. package/src/enums/kind-statement.ts +0 -17
  86. package/src/index.ts +0 -9
  87. package/src/interfaces/import-assertions.ts +0 -24
  88. package/src/interfaces/import-dynamic.ts +0 -46
  89. package/src/interfaces/import-static.ts +0 -46
  90. package/src/interfaces/index.ts +0 -25
  91. package/src/interfaces/options-fill-module.ts +0 -26
  92. package/src/interfaces/options-find-subpath.ts +0 -57
  93. package/src/interfaces/options-get-format.ts +0 -80
  94. package/src/interfaces/options-get-source.ts +0 -59
  95. package/src/interfaces/options-parse-module-id.ts +0 -39
  96. package/src/interfaces/options-parse-subpath.ts +0 -57
  97. package/src/interfaces/options-resolve-alias.ts +0 -59
  98. package/src/interfaces/options-resolve-module.ts +0 -72
  99. package/src/interfaces/options-resolve.ts +0 -17
  100. package/src/interfaces/package-scope.ts +0 -30
  101. package/src/interfaces/parsed-data-url.ts +0 -63
  102. package/src/interfaces/parsed-module-id.ts +0 -90
  103. package/src/interfaces/parsed-subpath.ts +0 -56
  104. package/src/interfaces/statement-export.ts +0 -52
  105. package/src/interfaces/statement-import.ts +0 -45
  106. package/src/interfaces/statement-require.ts +0 -45
  107. package/src/interfaces/statement.ts +0 -64
  108. package/src/internal/dequote.ts +0 -18
  109. package/src/internal/format-type-map.ts +0 -28
  110. package/src/internal/get-specifier-kind.ts +0 -41
  111. package/src/internal/get-subpaths.ts +0 -43
  112. package/src/internal/regex-encoded-sep.ts +0 -17
  113. package/src/internal/regex-internal-specifier.ts +0 -19
  114. package/src/internal/regex-invalid-segment.ts +0 -25
  115. package/src/internal/regex-package-name.ts +0 -18
  116. package/src/internal/regex-package-path.ts +0 -20
  117. package/src/internal/resolver.ts +0 -790
  118. package/src/internal/validate-array-set.ts +0 -35
  119. package/src/internal/validate-boolean.ts +0 -30
  120. package/src/internal/validate-map.ts +0 -36
  121. package/src/internal/validate-object.ts +0 -30
  122. package/src/internal/validate-set.ts +0 -32
  123. package/src/internal/validate-string.ts +0 -31
  124. package/src/internal/validate-url-string.ts +0 -34
  125. package/src/types/declaration.ts +0 -22
  126. package/src/types/fn-change-ext.ts +0 -33
  127. package/src/types/index.ts +0 -14
  128. package/src/types/mime-type.ts +0 -19
  129. package/src/types/module-id.ts +0 -15
  130. package/src/types/module-specifier-type.ts +0 -13
  131. package/src/types/protocol.ts +0 -40
  132. package/src/types/syntax-kind-export.ts +0 -20
  133. package/src/types/syntax-kind-import.ts +0 -22
  134. package/src/types/syntax-kind-require.ts +0 -15
  135. package/src/utils/compare-subpaths.ts +0 -100
  136. package/src/utils/conditions.ts +0 -15
  137. package/src/utils/detect-syntax.ts +0 -40
  138. package/src/utils/extension-format-map.ts +0 -34
  139. package/src/utils/extract-statements.ts +0 -46
  140. package/src/utils/fill-modules.ts +0 -133
  141. package/src/utils/find-dynamic-imports.ts +0 -75
  142. package/src/utils/find-exports.ts +0 -156
  143. package/src/utils/find-requires.ts +0 -75
  144. package/src/utils/find-static-imports.ts +0 -86
  145. package/src/utils/find-subpath.ts +0 -251
  146. package/src/utils/get-format.ts +0 -249
  147. package/src/utils/get-source.ts +0 -144
  148. package/src/utils/has-cjs-syntax.ts +0 -44
  149. package/src/utils/has-esm-syntax.ts +0 -40
  150. package/src/utils/index.ts +0 -45
  151. package/src/utils/is-absolute-specifier.ts +0 -53
  152. package/src/utils/is-bare-specifier.ts +0 -36
  153. package/src/utils/is-directory.ts +0 -25
  154. package/src/utils/is-exports-sugar.ts +0 -81
  155. package/src/utils/is-file.ts +0 -25
  156. package/src/utils/is-relative-specifier.ts +0 -34
  157. package/src/utils/lookup-package-scope.ts +0 -97
  158. package/src/utils/parse-data-url.ts +0 -71
  159. package/src/utils/parse-module-id.ts +0 -197
  160. package/src/utils/parse-subpath.ts +0 -331
  161. package/src/utils/pattern-character.ts +0 -13
  162. package/src/utils/read-package-json.ts +0 -113
  163. package/src/utils/resolve-alias.ts +0 -224
  164. package/src/utils/resolve-aliases.ts +0 -58
  165. package/src/utils/resolve-extensions.ts +0 -33
  166. package/src/utils/resolve-module.ts +0 -181
  167. package/src/utils/resolve-modules.ts +0 -60
  168. package/src/utils/to-absolute-specifier.ts +0 -30
  169. package/src/utils/to-bare-specifier.ts +0 -211
  170. package/src/utils/to-data-url.ts +0 -42
  171. package/src/utils/to-node-url.ts +0 -27
  172. package/src/utils/to-relative-specifier.ts +0 -55
  173. package/src/utils/to-url.ts +0 -30
  174. package/src/utils/validate-assertions.ts +0 -126
  175. package/src/utils/validate-exports.ts +0 -131
@@ -1,35 +0,0 @@
1
- /**
2
- * @file Internal - validateArraySet
3
- * @module mlly/internal/validateArraySet
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isArray, isSet } from '@flex-development/tutils'
8
-
9
- /**
10
- * Checks if `value` is an array or an instance of {@linkcode Set}.
11
- *
12
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is of neither type.
13
- *
14
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
15
- *
16
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
17
- *
18
- * @internal
19
- *
20
- * @template T - Item type
21
- *
22
- * @param {unknown} value - Value supplied by user
23
- * @param {string} name - Name of invalid argument or property
24
- * @return {value is Set<T> | T[]} `true` if `value` is array or `Set`
25
- * @throws {NodeError<TypeError>} If `value` is not an array or `Set`
26
- */
27
- const validateArraySet = <T>(
28
- value: unknown,
29
- name: string
30
- ): value is Set<T> | T[] => {
31
- if (isArray<T>(value) || isSet<T>(value)) return true
32
- throw new ERR_INVALID_ARG_TYPE(name, ['Array', 'Set'], value)
33
- }
34
-
35
- export default validateArraySet
@@ -1,30 +0,0 @@
1
- /**
2
- * @file Internal - validateBoolean
3
- * @module mlly/internal/validateBoolean
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isBoolean } from '@flex-development/tutils'
8
-
9
- /**
10
- * Checks if `value` is a boolean.
11
- *
12
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a boolean.
13
- *
14
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
15
- *
16
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
17
- *
18
- * @internal
19
- *
20
- * @param {unknown} value - Value supplied by user
21
- * @param {string} name - Name of invalid argument or property
22
- * @return {value is boolean} `true` if `value` is a boolean
23
- * @throws {NodeError<TypeError>} If `value` is not a boolean
24
- */
25
- const validateBoolean = (value: unknown, name: string): value is boolean => {
26
- if (isBoolean(value)) return true
27
- throw new ERR_INVALID_ARG_TYPE(name, 'boolean', value)
28
- }
29
-
30
- export default validateBoolean
@@ -1,36 +0,0 @@
1
- /**
2
- * @file Internal - validateMap
3
- * @module mlly/internal/validateMap
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isMap, type PropertyKey } from '@flex-development/tutils'
8
-
9
- /**
10
- * Checks if `value` is a {@linkcode Map} instance.
11
- *
12
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a {@linkcode Map}.
13
- *
14
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
15
- *
16
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
17
- *
18
- * @internal
19
- *
20
- * @template K - Map key type
21
- * @template V - Map item type
22
- *
23
- * @param {unknown} value - Value supplied by user
24
- * @param {string} name - Name of invalid argument or property
25
- * @return {value is Map<K, V>} `true` if `value` is a `Map`
26
- * @throws {NodeError<TypeError>} If `value` is not a `Map`
27
- */
28
- const validateMap = <K = PropertyKey, V = unknown>(
29
- value: unknown,
30
- name: string
31
- ): value is Map<K, V> => {
32
- if (isMap<K, V>(value)) return true
33
- throw new ERR_INVALID_ARG_TYPE(name, ['Map'], value)
34
- }
35
-
36
- export default validateMap
@@ -1,30 +0,0 @@
1
- /**
2
- * @file Internal - validateObject
3
- * @module mlly/internal/validateObject
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isObjectCurly, type ObjectCurly } from '@flex-development/tutils'
8
-
9
- /**
10
- * Checks if `value` is a curly-braced object.
11
- *
12
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a curly-braced object.
13
- *
14
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
15
- *
16
- * @see {@linkcode isObjectCurly}
17
- *
18
- * @internal
19
- *
20
- * @param {unknown} value - Value supplied by user
21
- * @param {string} name - Name of invalid argument or property
22
- * @return {value is ObjectCurly} `true` if `value` is a curly-braced object
23
- * @throws {NodeError<TypeError>} If `value` is not a curly-braced object
24
- */
25
- const validateObject = (value: unknown, name: string): value is ObjectCurly => {
26
- if (isObjectCurly(value)) return true
27
- throw new ERR_INVALID_ARG_TYPE(name, 'object', value)
28
- }
29
-
30
- export default validateObject
@@ -1,32 +0,0 @@
1
- /**
2
- * @file Internal - validateSet
3
- * @module mlly/internal/validateSet
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isSet } from '@flex-development/tutils'
8
-
9
- /**
10
- * Checks if given `value` is a {@linkcode Set}.
11
- *
12
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a {@linkcode Set}.
13
- *
14
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
15
- *
16
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
17
- *
18
- * @internal
19
- *
20
- * @template T - Set item type
21
- *
22
- * @param {unknown} value - Value supplied by user
23
- * @param {string} name - Name of invalid argument or property
24
- * @return {value is Set<T>} `true` if `value` is a `Set`
25
- * @throws {NodeError<TypeError>} If `value` is not a `Set`
26
- */
27
- const validateSet = <T>(value: unknown, name: string): value is Set<T> => {
28
- if (isSet<T>(value)) return true
29
- throw new ERR_INVALID_ARG_TYPE(name, ['Set'], value)
30
- }
31
-
32
- export default validateSet
@@ -1,31 +0,0 @@
1
- /**
2
- * @file Internal - validateString
3
- * @module mlly/internal/validateString
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isString } from '@flex-development/tutils'
8
-
9
- /**
10
- * Checks if `value` is a string.
11
- *
12
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is not a string.
13
- *
14
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
15
- *
16
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
17
- * @see {@linkcode NodeError}
18
- *
19
- * @internal
20
- *
21
- * @param {unknown} value - Value supplied by user
22
- * @param {string} name - Name of invalid argument or property
23
- * @return {value is string} `true` if `value` is a string
24
- * @throws {NodeError<TypeError>} If `value` is not a string
25
- */
26
- const validateString = (value: unknown, name: string): value is string => {
27
- if (isString(value)) return true
28
- throw new ERR_INVALID_ARG_TYPE(name, 'string', value)
29
- }
30
-
31
- export default validateString
@@ -1,34 +0,0 @@
1
- /**
2
- * @file Internal - validateURLString
3
- * @module mlly/internal/validateURLString
4
- */
5
-
6
- import { ERR_INVALID_ARG_TYPE, type NodeError } from '@flex-development/errnode'
7
- import { isString } from '@flex-development/tutils'
8
- import { URL } from 'node:url'
9
-
10
- /**
11
- * Checks if `value` is an instance of {@linkcode URL} or a string.
12
- *
13
- * Throws [`ERR_INVALID_ARG_TYPE`][1] if `value` is of neither type.
14
- *
15
- * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
16
- *
17
- * @see {@linkcode ERR_INVALID_ARG_TYPE}
18
- *
19
- * @internal
20
- *
21
- * @param {unknown} value - Value supplied by user
22
- * @param {string} name - Name of invalid argument or property
23
- * @return {value is URL | string} `true` if `value` is `URL` instance or string
24
- * @throws {NodeError<TypeError>} If `value` is not `URL` instance or string
25
- */
26
- const validateURLString = (
27
- value: unknown,
28
- name: string
29
- ): value is URL | string => {
30
- if (value instanceof URL || isString(value)) return true
31
- throw new ERR_INVALID_ARG_TYPE(name, ['URL', 'string'], value)
32
- }
33
-
34
- export default validateURLString
@@ -1,22 +0,0 @@
1
- /**
2
- * @file Type Definitions - Declaration
3
- * @module mlly/types/Declaration
4
- */
5
-
6
- /**
7
- * Export declaration kinds.
8
- */
9
- type Declaration =
10
- | 'class'
11
- | 'const enum'
12
- | 'const'
13
- | 'enum'
14
- | 'function'
15
- | 'function*'
16
- | 'interface'
17
- | 'let'
18
- | 'namespace'
19
- | 'type'
20
- | 'var'
21
-
22
- export type { Declaration as default }
@@ -1,33 +0,0 @@
1
- /**
2
- * @file Type Definitions - ChangeExtFn
3
- * @module mlly/types/ChangeExtFn
4
- */
5
-
6
- import type { Fn, Nilable } from '@flex-development/tutils'
7
- import type { URL } from 'node:url'
8
-
9
- /**
10
- * Function that returns a new file extension for the given module `specifier`.
11
- *
12
- * Returning an empty string (`''`) will remove the original file extension;
13
- * returning `null` or `undefined` will skip extension replacement.
14
- *
15
- * ::: info
16
- * The new file extension need not begin with a dot character (`'.'`).
17
- * :::
18
- *
19
- * @see {@linkcode URL}
20
- * @see https://github.com/flex-development/pathe/tree/1.0.3#changeextpath-string-ext-nullablestring-string
21
- *
22
- * @template X - File extension type
23
- *
24
- * @param {string} specifier - Original module specifier
25
- * @param {URL} url - Resolved module URL
26
- * @return {PromiseLike<X> | X} New file extension, `null`, or `undefined`
27
- */
28
- type ChangeExtFn<X extends Nilable<string> = Nilable<string>> = Fn<
29
- [specifier: string, url: URL],
30
- PromiseLike<X> | X
31
- >
32
-
33
- export type { ChangeExtFn as default }
@@ -1,14 +0,0 @@
1
- /**
2
- * @file Type Definitions
3
- * @module mlly/types
4
- */
5
-
6
- export type { default as Declaration } from './declaration'
7
- export type { default as ChangeExtFn } from './fn-change-ext'
8
- export type { default as MimeType } from './mime-type'
9
- export type { default as ModuleId } from './module-id'
10
- export type { default as ModuleSpecifierType } from './module-specifier-type'
11
- export type { default as Protocol } from './protocol'
12
- export type { default as SyntaxKindExport } from './syntax-kind-export'
13
- export type { default as SyntaxKindImport } from './syntax-kind-import'
14
- export type { default as SyntaxKindRequire } from './syntax-kind-require'
@@ -1,19 +0,0 @@
1
- /**
2
- * @file Type Definitions - MimeType
3
- * @module mlly/types/MimeType
4
- */
5
-
6
- /**
7
- * Supported [MIME types][1].
8
- *
9
- * [1]: https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types
10
- *
11
- * @see https://nodejs.org/api/esm.html#esm_data_imports
12
- */
13
- type MimeType =
14
- | 'application/json'
15
- | 'application/typescript'
16
- | 'application/wasm'
17
- | 'text/javascript'
18
-
19
- export type { MimeType as default }
@@ -1,15 +0,0 @@
1
- /**
2
- * @file Type Definitions - ModuleId
3
- * @module mlly/types/ModuleId
4
- */
5
-
6
- import type { URL } from 'node:url'
7
-
8
- /**
9
- * ECMAScript (ES) module identifier.
10
- *
11
- * @see {@linkcode URL}
12
- */
13
- type ModuleId = URL | string
14
-
15
- export type { ModuleId as default }
@@ -1,13 +0,0 @@
1
- /**
2
- * @file Type Definitions - ModuleSpecifierType
3
- * @module mlly/types/ModuleSpecifierType
4
- */
5
-
6
- /**
7
- * Module specifier types.
8
- *
9
- * @see https://nodejs.org/api/esm.html#terminology
10
- */
11
- type ModuleSpecifierType = 'absolute' | 'bare' | 'relative'
12
-
13
- export type { ModuleSpecifierType as default }
@@ -1,40 +0,0 @@
1
- /**
2
- * @file Type Definitions - Protocol
3
- * @module mlly/types/Protocol
4
- */
5
-
6
- import type { LiteralUnion } from '@flex-development/tutils'
7
-
8
- /**
9
- * URL protocols.
10
- *
11
- * @see https://nodejs.org/api/url.html#urlprotocol
12
- * @see https://iana.org/assignments/uri-schemes/uri-schemes.xhtml
13
- * @see https://url.spec.whatwg.org/#special-scheme
14
- */
15
- type Protocol = LiteralUnion<
16
- `${
17
- | 'blob'
18
- | 'content'
19
- | 'cvs'
20
- | 'data'
21
- | 'dns'
22
- | 'file'
23
- | 'fish'
24
- | 'ftp'
25
- | 'git'
26
- | 'http'
27
- | 'https'
28
- | 'mvn'
29
- | 'redis'
30
- | 'sftp'
31
- | 'ssh'
32
- | 'svn'
33
- | 'urn'
34
- | 'view-source'
35
- | 'ws'
36
- | 'wss'}:`,
37
- `${string}:`
38
- >
39
-
40
- export type { Protocol as default }
@@ -1,20 +0,0 @@
1
- /**
2
- * @file Type Definitions - SyntaxKindExport
3
- * @module mlly/types/SyntaxKindExport
4
- */
5
-
6
- import type { StatementSyntaxKind } from '#src/enums'
7
-
8
- /**
9
- * `export` statement syntax kinds.
10
- *
11
- * @see {@linkcode StatementSyntaxKind}
12
- */
13
- type SyntaxKindExport =
14
- | StatementSyntaxKind.DECLARATION
15
- | StatementSyntaxKind.DEFAULT
16
- | StatementSyntaxKind.LIST
17
- | StatementSyntaxKind.NAMED
18
- | StatementSyntaxKind.NAMESPACE
19
-
20
- export type { SyntaxKindExport as default }
@@ -1,22 +0,0 @@
1
- /**
2
- * @file Type Definitions - SyntaxKindImport
3
- * @module mlly/types/SyntaxKindImport
4
- */
5
-
6
- import type { StatementSyntaxKind } from '#src/enums'
7
-
8
- /**
9
- * `import` statement syntax kinds.
10
- *
11
- * @see {@linkcode StatementSyntaxKind}
12
- */
13
- type SyntaxKindImport =
14
- | StatementSyntaxKind.DEFAULT
15
- | StatementSyntaxKind.DEFAULT_WITH_NAMED
16
- | StatementSyntaxKind.DEFAULT_WITH_NAMESPACE
17
- | StatementSyntaxKind.DYNAMIC
18
- | StatementSyntaxKind.NAMED
19
- | StatementSyntaxKind.NAMESPACE
20
- | StatementSyntaxKind.SIDE_EFFECT
21
-
22
- export type { SyntaxKindImport as default }
@@ -1,15 +0,0 @@
1
- /**
2
- * @file Type Definitions - SyntaxKindRequire
3
- * @module mlly/types/SyntaxKindRequire
4
- */
5
-
6
- import type { StatementSyntaxKind } from '#src/enums'
7
-
8
- /**
9
- * `require` statement syntax kinds.
10
- *
11
- * @see {@linkcode StatementSyntaxKind}
12
- */
13
- type SyntaxKindRequire = StatementSyntaxKind.REQUIRE
14
-
15
- export type { SyntaxKindRequire as default }
@@ -1,100 +0,0 @@
1
- /**
2
- * @file compareSubpaths
3
- * @module mlly/utils/compareSubpaths
4
- */
5
-
6
- import validateString from '#src/internal/validate-string'
7
- import type { NodeError } from '@flex-development/errnode'
8
- import { CompareResult } from '@flex-development/tutils'
9
- import assert from 'node:assert'
10
- import PATTERN_CHARACTER from './pattern-character'
11
-
12
- /**
13
- * Returns a number indicating if a subpath pattern is equal to, greater than,
14
- * or less than another subpath pattern.
15
- *
16
- * - `-1`: `subpath2` is less than `subpath1`
17
- * - `0`: `subpath2` is equal to `subpath1`
18
- * - `1`: `subpath2` is greater than `subpath1`
19
- *
20
- * Implements the `PATTERN_KEY_COMPARE` algorithm.
21
- *
22
- * @see https://nodejs.org/api/esm.html#resolution-algorithm
23
- *
24
- * @param {string} subpath1 - Subpath to be compared
25
- * @param {string} subpath2 - Subpath to compare `subpath1` to
26
- * @return {CompareResult} Comparsion result
27
- * @throws {NodeError<Error | TypeError>} If either either subpath contains more
28
- * than pattern character (`'*'`) or is not a string
29
- */
30
- const compareSubpaths = (subpath1: string, subpath2: string): CompareResult => {
31
- validateString(subpath1, 'subpath1')
32
- validateString(subpath2, 'subpath2')
33
-
34
- /**
35
- * Index of {@linkcode pattern_char} in {@linkcode subpath1}.
36
- *
37
- * @const {number} pattern1
38
- */
39
- let pattern1: number = -1
40
-
41
- /**
42
- * Index of {@linkcode pattern_char} in {@linkcode subpath2}.
43
- *
44
- * @const {number} pattern2
45
- */
46
- let pattern2: number = -1
47
-
48
- // ensure subpaths contain a single '*'
49
- for (const [index, subpath] of [subpath1, subpath2].entries()) {
50
- /**
51
- * Error message thrown if {@linkcode subpath} contains more than one `'*'`.
52
- *
53
- * @const {string} message
54
- */
55
- const message: string = `'${subpath}' is expected to contain a single '*'`
56
-
57
- /**
58
- * Index of {@linkcode PATTERN_CHARACTER} in {@linkcode subpath}.
59
- *
60
- * @const {number} pattern
61
- */
62
- const pattern_index: number = subpath.indexOf(PATTERN_CHARACTER)
63
-
64
- // ensure respective subpath contains no more than one '*'
65
- assert(pattern_index === subpath.lastIndexOf(PATTERN_CHARACTER), message)
66
-
67
- // set index of pattern character in respective subpath
68
- index === 0 ? (pattern1 = pattern_index) : (pattern2 = pattern_index)
69
- }
70
-
71
- /**
72
- * Base length of {@linkcode subpath1}.
73
- *
74
- * @const {number} length1
75
- */
76
- const length1: number = pattern1 === -1 ? subpath1.length : pattern1 + 1
77
-
78
- /**
79
- * Base length of {@linkcode subpath2}.
80
- *
81
- * @const {number} length2
82
- */
83
- const length2: number = pattern2 === -1 ? subpath2.length : pattern2 + 1
84
-
85
- return length1 > length2
86
- ? CompareResult.LESS_THAN
87
- : length2 > length1
88
- ? CompareResult.GREATER_THAN
89
- : pattern1 === -1
90
- ? CompareResult.GREATER_THAN
91
- : pattern2 === -1
92
- ? CompareResult.LESS_THAN
93
- : subpath1.length > subpath2.length
94
- ? CompareResult.LESS_THAN
95
- : subpath2.length > subpath1.length
96
- ? CompareResult.GREATER_THAN
97
- : CompareResult.EQUAL
98
- }
99
-
100
- export default compareSubpaths
@@ -1,15 +0,0 @@
1
- /**
2
- * @file CONDITIONS
3
- * @module mlly/utils/CONDITIONS
4
- */
5
-
6
- /**
7
- * Default export conditions.
8
- *
9
- * @see https://nodejs.org/api/packages.html#conditional-exports
10
- *
11
- * @const {Set<string>} CONDITIONS
12
- */
13
- const CONDITIONS: Set<string> = new Set(['node', 'import'])
14
-
15
- export default CONDITIONS
@@ -1,40 +0,0 @@
1
- /**
2
- * @file detectSyntax
3
- * @module mlly/utils/detectSyntax
4
- */
5
-
6
- import hasCJSSyntax from './has-cjs-syntax'
7
- import hasESMSyntax from './has-esm-syntax'
8
-
9
- /**
10
- * Detects if `code` contains CommonJS syntax, ESM syntax, or a mixture of both.
11
- *
12
- * Ignores matches in comments.
13
- *
14
- * @see {@linkcode hasCJSSyntax}
15
- * @see {@linkcode hasESMSyntax}
16
- *
17
- * @param {string} code - Code to evaluate
18
- * @return {{ cjs: boolean; esm: boolean; mixed: boolean }} Detection result
19
- */
20
- const detectSyntax = (
21
- code: string
22
- ): { cjs: boolean; esm: boolean; mixed: boolean } => {
23
- /**
24
- * CommonJS syntax check.
25
- *
26
- * @const {boolean} cjs
27
- */
28
- const cjs: boolean = hasCJSSyntax(code)
29
-
30
- /**
31
- * ESM syntax check.
32
- *
33
- * @const {boolean} esm
34
- */
35
- const esm: boolean = hasESMSyntax(code)
36
-
37
- return { cjs, esm, mixed: cjs && esm }
38
- }
39
-
40
- export default detectSyntax
@@ -1,34 +0,0 @@
1
- /**
2
- * @file EXTENSION_FORMAT_MAP
3
- * @module mlly/utils/EXTENSION_FORMAT_MAP
4
- */
5
-
6
- import { Format } from '#src/enums'
7
- import type { Ext } from '@flex-development/pathe'
8
-
9
- /**
10
- * Default file extension to module formats map.
11
- *
12
- * @see {@linkcode Ext}
13
- * @see {@linkcode Format}
14
- *
15
- * @const {Map<Ext, Format>} EXTENSION_FORMAT_MAP
16
- */
17
- const EXTENSION_FORMAT_MAP: Map<Ext, Format> = new Map<Ext, Format>([
18
- ['.cjs', Format.COMMONJS],
19
- ['.cts', Format.COMMONJS],
20
- ['.d.cts', Format.COMMONJS],
21
- ['.d.mts', Format.MODULE],
22
- ['.d.ts', Format.MODULE],
23
- ['.js', Format.MODULE],
24
- ['.json', Format.JSON],
25
- ['.jsx', Format.MODULE],
26
- ['.mjs', Format.MODULE],
27
- ['.mts', Format.MODULE],
28
- ['.node', Format.COMMONJS],
29
- ['.ts', Format.MODULE],
30
- ['.tsx', Format.MODULE],
31
- ['.wasm', Format.WASM]
32
- ])
33
-
34
- export default EXTENSION_FORMAT_MAP