@flex-development/mlly 1.0.0-alpha.1 → 1.0.0-alpha.11
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.
- package/CHANGELOG.md +431 -3
- package/README.md +6 -4
- package/changelog.config.ts +404 -0
- package/dist/enums/assert-type.d.mts +21 -0
- package/dist/enums/assert-type.mjs +10 -0
- package/dist/enums/assert-type.mjs.map +6 -0
- package/dist/enums/format.d.mts +17 -0
- package/dist/enums/format.mjs +13 -0
- package/dist/enums/format.mjs.map +6 -0
- package/dist/enums/index.d.mts +10 -0
- package/dist/enums/index.mjs +15 -0
- package/dist/enums/index.mjs.map +6 -0
- package/dist/enums/kind-specifier-syntax.d.mts +14 -0
- package/dist/enums/kind-specifier-syntax.mjs +10 -0
- package/dist/enums/kind-specifier-syntax.mjs.map +6 -0
- package/dist/enums/kind-specifier.d.mts +17 -0
- package/dist/enums/kind-specifier.mjs +11 -0
- package/dist/enums/kind-specifier.mjs.map +6 -0
- package/dist/enums/kind-statement-syntax.d.mts +22 -0
- package/dist/enums/kind-statement-syntax.mjs +18 -0
- package/dist/enums/kind-statement-syntax.mjs.map +6 -0
- package/dist/enums/kind-statement.d.mts +15 -0
- package/dist/enums/kind-statement.mjs +11 -0
- package/dist/enums/kind-statement.mjs.map +6 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +6 -0
- package/dist/interfaces/import-assertions.d.mts +20 -0
- package/dist/interfaces/import-dynamic.d.mts +26 -6
- package/dist/interfaces/import-static.d.mts +22 -4
- package/dist/interfaces/index.d.mts +12 -0
- package/dist/interfaces/index.mjs +1 -0
- package/dist/interfaces/index.mjs.map +6 -0
- package/dist/interfaces/options-fill-module.d.mts +23 -0
- package/dist/interfaces/options-find-subpath.d.mts +49 -0
- package/dist/interfaces/options-get-format.d.mts +83 -0
- package/dist/interfaces/options-get-source.d.mts +63 -0
- package/dist/interfaces/options-parse-module-id.d.mts +33 -0
- package/dist/interfaces/options-parse-subpath.d.mts +31 -0
- package/dist/interfaces/options-resolve-alias.d.mts +26 -42
- package/dist/interfaces/options-resolve-module.d.mts +64 -0
- package/dist/interfaces/options-resolve.d.mts +7 -52
- package/dist/interfaces/package-scope.d.mts +25 -0
- package/dist/interfaces/parsed-data-url.d.mts +56 -0
- package/dist/interfaces/parsed-module-id.d.mts +80 -0
- package/dist/interfaces/parsed-subpath.d.mts +40 -0
- package/dist/interfaces/statement-export.d.mts +22 -9
- package/dist/interfaces/statement-import.d.mts +15 -4
- package/dist/interfaces/statement-require.d.mts +15 -4
- package/dist/interfaces/statement.d.mts +24 -8
- package/dist/internal/escape-reg-exp.d.mts +16 -0
- package/dist/internal/escape-reg-exp.mjs +10 -0
- package/dist/internal/escape-reg-exp.mjs.map +6 -0
- package/dist/internal/format-type-map.d.mts +17 -0
- package/dist/internal/format-type-map.mjs +13 -0
- package/dist/internal/format-type-map.mjs.map +6 -0
- package/dist/internal/get-specifier-kind.d.mts +17 -0
- package/dist/internal/get-specifier-kind.mjs +14 -0
- package/dist/internal/get-specifier-kind.mjs.map +6 -0
- package/dist/internal/get-subpaths.d.mts +25 -0
- package/dist/internal/get-subpaths.mjs +10 -0
- package/dist/internal/get-subpaths.mjs.map +6 -0
- package/dist/internal/is-array-index.d.mts +15 -0
- package/dist/internal/is-array-index.mjs +9 -0
- package/dist/internal/is-array-index.mjs.map +6 -0
- package/dist/internal/is-directory.d.mts +13 -0
- package/dist/internal/is-directory.mjs +16 -0
- package/dist/internal/is-directory.mjs.map +6 -0
- package/dist/internal/is-file.d.mts +13 -0
- package/dist/internal/is-file.mjs +16 -0
- package/dist/internal/is-file.mjs.map +6 -0
- package/dist/internal/is-function.d.mts +12 -0
- package/dist/internal/is-function.mjs +8 -0
- package/dist/internal/is-function.mjs.map +6 -0
- package/dist/internal/regex-encoded-sep.d.mts +13 -0
- package/dist/internal/regex-encoded-sep.mjs +6 -0
- package/dist/internal/regex-encoded-sep.mjs.map +6 -0
- package/dist/internal/regex-internal-specifier.d.mts +14 -0
- package/dist/internal/regex-internal-specifier.mjs +6 -0
- package/dist/internal/regex-internal-specifier.mjs.map +6 -0
- package/dist/internal/regex-package-name.d.mts +13 -0
- package/dist/internal/regex-package-name.mjs +6 -0
- package/dist/internal/regex-package-name.mjs.map +6 -0
- package/dist/internal/regex-package-path.d.mts +15 -0
- package/dist/internal/regex-package-path.mjs +6 -0
- package/dist/internal/regex-package-path.mjs.map +6 -0
- package/dist/internal/resolver.d.mts +130 -0
- package/dist/internal/resolver.mjs +500 -0
- package/dist/internal/resolver.mjs.map +6 -0
- package/dist/internal/validate-boolean.d.mts +20 -0
- package/dist/internal/validate-boolean.mjs +11 -0
- package/dist/internal/validate-boolean.mjs.map +6 -0
- package/dist/internal/validate-object.d.mts +23 -0
- package/dist/internal/validate-object.mjs +11 -0
- package/dist/internal/validate-object.mjs.map +6 -0
- package/dist/internal/validate-set.d.mts +23 -0
- package/dist/internal/validate-set.mjs +11 -0
- package/dist/internal/validate-set.mjs.map +6 -0
- package/dist/internal/validate-string.d.mts +20 -0
- package/dist/internal/validate-string.mjs +11 -0
- package/dist/internal/validate-string.mjs.map +6 -0
- package/dist/internal/validate-url-string.d.mts +22 -0
- package/dist/internal/validate-url-string.mjs +12 -0
- package/dist/internal/validate-url-string.mjs.map +6 -0
- package/dist/types/declaration.d.mts +1 -1
- package/dist/types/fn-change-ext.d.mts +28 -0
- package/dist/types/index.d.mts +8 -4
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +6 -0
- package/dist/types/mime-type.d.mts +7 -5
- package/dist/types/module-id.d.mts +13 -0
- package/dist/types/module-specifier-type.d.mts +11 -0
- package/dist/types/protocol.d.mts +14 -0
- package/dist/types/syntax-kind-export.d.mts +12 -0
- package/dist/types/syntax-kind-import.d.mts +12 -0
- package/dist/types/syntax-kind-require.d.mts +12 -0
- package/dist/utils/compare-subpaths.d.mts +25 -0
- package/dist/utils/compare-subpaths.mjs +24 -0
- package/dist/utils/compare-subpaths.mjs.map +6 -0
- package/dist/utils/conditions.d.mts +13 -0
- package/dist/utils/conditions.mjs +6 -0
- package/dist/utils/conditions.mjs.map +6 -0
- package/dist/{lib → utils}/detect-syntax.d.mts +4 -4
- package/dist/{lib → utils}/detect-syntax.mjs +1 -0
- package/dist/utils/detect-syntax.mjs.map +6 -0
- package/dist/utils/extension-format-map.d.mts +16 -0
- package/dist/utils/extension-format-map.mjs +22 -0
- package/dist/utils/extension-format-map.mjs.map +6 -0
- package/dist/utils/extract-statements.d.mts +21 -0
- package/dist/{lib → utils}/extract-statements.mjs +4 -1
- package/dist/utils/extract-statements.mjs.map +6 -0
- package/dist/utils/fill-modules.d.mts +23 -0
- package/dist/utils/fill-modules.mjs +64 -0
- package/dist/utils/fill-modules.mjs.map +6 -0
- package/dist/utils/find-dynamic-imports.d.mts +18 -0
- package/dist/utils/find-dynamic-imports.mjs +39 -0
- package/dist/utils/find-dynamic-imports.mjs.map +6 -0
- package/dist/utils/find-exports.d.mts +21 -0
- package/dist/utils/find-exports.mjs +95 -0
- package/dist/utils/find-exports.mjs.map +6 -0
- package/dist/utils/find-requires.d.mts +18 -0
- package/dist/utils/find-requires.mjs +32 -0
- package/dist/utils/find-requires.mjs.map +6 -0
- package/dist/utils/find-static-imports.d.mts +18 -0
- package/dist/utils/find-static-imports.mjs +34 -0
- package/dist/utils/find-static-imports.mjs.map +6 -0
- package/dist/utils/find-subpath.d.mts +30 -0
- package/dist/utils/find-subpath.mjs +106 -0
- package/dist/utils/find-subpath.mjs.map +6 -0
- package/dist/utils/get-format.d.mts +24 -0
- package/dist/utils/get-format.mjs +111 -0
- package/dist/utils/get-format.mjs.map +6 -0
- package/dist/utils/get-source.d.mts +22 -0
- package/dist/utils/get-source.mjs +63 -0
- package/dist/utils/get-source.mjs.map +6 -0
- package/dist/{lib → utils}/has-cjs-syntax.d.mts +5 -2
- package/dist/utils/has-cjs-syntax.mjs +11 -0
- package/dist/utils/has-cjs-syntax.mjs.map +6 -0
- package/dist/{lib → utils}/has-esm-syntax.d.mts +5 -2
- package/dist/utils/has-esm-syntax.mjs +11 -0
- package/dist/utils/has-esm-syntax.mjs.map +6 -0
- package/dist/utils/index.d.mts +42 -0
- package/dist/utils/index.mjs +79 -0
- package/dist/utils/index.mjs.map +6 -0
- package/dist/utils/is-absolute-specifier.d.mts +19 -0
- package/dist/utils/is-absolute-specifier.mjs +25 -0
- package/dist/utils/is-absolute-specifier.mjs.map +6 -0
- package/dist/utils/is-bare-specifier.d.mts +19 -0
- package/dist/utils/is-bare-specifier.mjs +10 -0
- package/dist/utils/is-bare-specifier.mjs.map +6 -0
- package/dist/utils/is-exports-sugar.d.mts +25 -0
- package/dist/utils/is-exports-sugar.mjs +26 -0
- package/dist/utils/is-exports-sugar.mjs.map +6 -0
- package/dist/utils/is-relative-specifier.d.mts +20 -0
- package/dist/utils/is-relative-specifier.mjs +11 -0
- package/dist/utils/is-relative-specifier.mjs.map +6 -0
- package/dist/utils/lookup-package-scope.d.mts +26 -0
- package/dist/utils/lookup-package-scope.mjs +38 -0
- package/dist/utils/lookup-package-scope.mjs.map +6 -0
- package/dist/utils/parse-data-url.d.mts +25 -0
- package/dist/utils/parse-data-url.mjs +25 -0
- package/dist/utils/parse-data-url.mjs.map +6 -0
- package/dist/utils/parse-module-id.d.mts +22 -0
- package/dist/utils/parse-module-id.mjs +122 -0
- package/dist/utils/parse-module-id.mjs.map +6 -0
- package/dist/utils/parse-subpath.d.mts +35 -0
- package/dist/utils/parse-subpath.mjs +54 -0
- package/dist/utils/parse-subpath.mjs.map +6 -0
- package/dist/utils/pattern-character.d.mts +11 -0
- package/dist/utils/pattern-character.mjs +6 -0
- package/dist/utils/pattern-character.mjs.map +6 -0
- package/dist/utils/read-package-json.d.mts +26 -0
- package/dist/utils/read-package-json.mjs +43 -0
- package/dist/utils/read-package-json.mjs.map +6 -0
- package/dist/utils/resolve-alias.d.mts +20 -0
- package/dist/utils/resolve-alias.mjs +106 -0
- package/dist/utils/resolve-alias.mjs.map +6 -0
- package/dist/utils/resolve-aliases.d.mts +19 -0
- package/dist/utils/resolve-aliases.mjs +28 -0
- package/dist/utils/resolve-aliases.mjs.map +6 -0
- package/dist/utils/resolve-extensions.d.mts +14 -0
- package/dist/utils/resolve-extensions.mjs +22 -0
- package/dist/utils/resolve-extensions.mjs.map +6 -0
- package/dist/utils/resolve-module.d.mts +39 -0
- package/dist/utils/resolve-module.mjs +64 -0
- package/dist/utils/resolve-module.mjs.map +6 -0
- package/dist/utils/resolve-modules.d.mts +25 -0
- package/dist/{lib → utils}/resolve-modules.mjs +7 -10
- package/dist/utils/resolve-modules.mjs.map +6 -0
- package/dist/{lib → utils}/to-absolute-specifier.d.mts +6 -6
- package/dist/utils/to-absolute-specifier.mjs +8 -0
- package/dist/utils/to-absolute-specifier.mjs.map +6 -0
- package/dist/utils/to-bare-specifier.d.mts +42 -0
- package/dist/utils/to-bare-specifier.mjs +90 -0
- package/dist/utils/to-bare-specifier.mjs.map +6 -0
- package/dist/{lib → utils}/to-data-url.d.mts +6 -5
- package/dist/{lib → utils}/to-data-url.mjs +4 -0
- package/dist/utils/to-data-url.mjs.map +6 -0
- package/dist/utils/to-node-url.d.mts +19 -0
- package/dist/utils/to-node-url.mjs +10 -0
- package/dist/utils/to-node-url.mjs.map +6 -0
- package/dist/{lib → utils}/to-relative-specifier.d.mts +6 -6
- package/dist/{lib → utils}/to-relative-specifier.mjs +7 -3
- package/dist/utils/to-relative-specifier.mjs.map +6 -0
- package/dist/utils/to-url.d.mts +22 -0
- package/dist/utils/to-url.mjs +12 -0
- package/dist/utils/to-url.mjs.map +6 -0
- package/dist/utils/validate-assertions.d.mts +23 -0
- package/dist/utils/validate-assertions.mjs +52 -0
- package/dist/utils/validate-assertions.mjs.map +6 -0
- package/dist/utils/validate-exports.d.mts +24 -0
- package/dist/utils/validate-exports.mjs +72 -0
- package/dist/utils/validate-exports.mjs.map +6 -0
- package/package.json +106 -83
- package/src/enums/assert-type.ts +23 -0
- package/src/enums/format.ts +19 -0
- package/src/enums/index.ts +11 -0
- package/src/enums/kind-specifier-syntax.ts +16 -0
- package/src/enums/kind-specifier.ts +19 -0
- package/src/enums/kind-statement-syntax.ts +24 -0
- package/src/enums/kind-statement.ts +17 -0
- package/src/index.ts +9 -0
- package/src/interfaces/import-assertions.ts +24 -0
- package/src/interfaces/import-dynamic.ts +48 -0
- package/src/interfaces/import-static.ts +50 -0
- package/src/interfaces/index.ts +25 -0
- package/src/interfaces/options-fill-module.ts +26 -0
- package/src/interfaces/options-find-subpath.ts +56 -0
- package/src/interfaces/options-get-format.ts +92 -0
- package/src/interfaces/options-get-source.ts +70 -0
- package/src/interfaces/options-parse-module-id.ts +38 -0
- package/src/interfaces/options-parse-subpath.ts +36 -0
- package/src/interfaces/options-resolve-alias.ts +59 -0
- package/src/interfaces/options-resolve-module.ts +72 -0
- package/src/interfaces/options-resolve.ts +17 -0
- package/src/interfaces/package-scope.ts +30 -0
- package/src/interfaces/parsed-data-url.ts +63 -0
- package/src/interfaces/parsed-module-id.ts +90 -0
- package/src/interfaces/parsed-subpath.ts +47 -0
- package/src/interfaces/statement-export.ts +52 -0
- package/src/interfaces/statement-import.ts +45 -0
- package/src/interfaces/statement-require.ts +45 -0
- package/src/interfaces/statement.ts +64 -0
- package/src/internal/escape-reg-exp.ts +24 -0
- package/src/internal/format-type-map.ts +26 -0
- package/src/internal/get-specifier-kind.ts +38 -0
- package/src/internal/get-subpaths.ts +41 -0
- package/src/internal/is-array-index.ts +28 -0
- package/src/internal/is-directory.ts +25 -0
- package/src/internal/is-file.ts +25 -0
- package/src/internal/is-function.ts +16 -0
- package/src/internal/regex-encoded-sep.ts +15 -0
- package/src/internal/regex-internal-specifier.ts +17 -0
- package/src/internal/regex-package-name.ts +16 -0
- package/src/internal/regex-package-path.ts +18 -0
- package/src/internal/resolver.ts +783 -0
- package/src/internal/validate-boolean.ts +27 -0
- package/src/internal/validate-object.ts +30 -0
- package/src/internal/validate-set.ts +33 -0
- package/src/internal/validate-string.ts +27 -0
- package/src/internal/validate-url-string.ts +31 -0
- package/src/types/declaration.ts +22 -0
- package/src/types/fn-change-ext.ts +33 -0
- package/src/types/index.ts +14 -0
- package/src/types/mime-type.ts +19 -0
- package/src/types/module-id.ts +15 -0
- package/src/types/module-specifier-type.ts +13 -0
- package/src/types/protocol.ts +40 -0
- package/src/types/syntax-kind-export.ts +20 -0
- package/src/types/syntax-kind-import.ts +22 -0
- package/src/types/syntax-kind-require.ts +15 -0
- package/src/utils/compare-subpaths.ts +100 -0
- package/src/utils/conditions.ts +15 -0
- package/src/utils/detect-syntax.ts +40 -0
- package/src/utils/extension-format-map.ts +34 -0
- package/src/utils/extract-statements.ts +42 -0
- package/src/utils/fill-modules.ts +116 -0
- package/src/utils/find-dynamic-imports.ts +75 -0
- package/src/utils/find-exports.ts +164 -0
- package/src/utils/find-requires.ts +75 -0
- package/src/utils/find-static-imports.ts +89 -0
- package/src/utils/find-subpath.ts +241 -0
- package/src/utils/get-format.ts +222 -0
- package/src/utils/get-source.ts +129 -0
- package/src/utils/has-cjs-syntax.ts +44 -0
- package/src/utils/has-esm-syntax.ts +40 -0
- package/src/utils/index.ts +43 -0
- package/src/utils/is-absolute-specifier.ts +48 -0
- package/src/utils/is-bare-specifier.ts +30 -0
- package/src/utils/is-exports-sugar.ts +74 -0
- package/src/utils/is-relative-specifier.ts +34 -0
- package/src/utils/lookup-package-scope.ts +97 -0
- package/src/utils/parse-data-url.ts +71 -0
- package/src/utils/parse-module-id.ts +186 -0
- package/src/utils/parse-subpath.ts +173 -0
- package/src/utils/pattern-character.ts +13 -0
- package/src/utils/read-package-json.ts +101 -0
- package/src/utils/resolve-alias.ts +219 -0
- package/src/utils/resolve-aliases.ts +58 -0
- package/src/utils/resolve-extensions.ts +33 -0
- package/src/utils/resolve-module.ts +153 -0
- package/src/utils/resolve-modules.ts +62 -0
- package/src/utils/to-absolute-specifier.ts +30 -0
- package/src/utils/to-bare-specifier.ts +201 -0
- package/src/utils/to-data-url.ts +42 -0
- package/src/utils/to-node-url.ts +27 -0
- package/src/utils/to-relative-specifier.ts +47 -0
- package/src/utils/to-url.ts +31 -0
- package/src/utils/validate-assertions.ts +119 -0
- package/src/utils/validate-exports.ts +124 -0
- package/changelog.config.cts +0 -204
- package/dist/constants.d.mts +0 -19
- package/dist/constants.mjs +0 -24
- package/dist/interfaces/import-dynamic.mjs +0 -0
- package/dist/interfaces/import-static.mjs +0 -0
- package/dist/interfaces/options-resolve-alias.mjs +0 -0
- package/dist/interfaces/options-resolve.mjs +0 -0
- package/dist/interfaces/statement-export.mjs +0 -0
- package/dist/interfaces/statement-import.mjs +0 -0
- package/dist/interfaces/statement-require.mjs +0 -0
- package/dist/interfaces/statement.mjs +0 -0
- package/dist/internal/compiler-options-json.d.mts +0 -111
- package/dist/internal/compiler-options-json.mjs +0 -0
- package/dist/internal/constants.d.mts +0 -70
- package/dist/internal/constants.mjs +0 -18
- package/dist/internal/get-compiler-options.d.mts +0 -21
- package/dist/internal/get-compiler-options.mjs +0 -14
- package/dist/internal/index.d.mts +0 -7
- package/dist/internal/index.mjs +0 -5
- package/dist/lib/extract-statements.d.mts +0 -21
- package/dist/lib/find-dynamic-imports.d.mts +0 -15
- package/dist/lib/find-dynamic-imports.mjs +0 -20
- package/dist/lib/find-exports.d.mts +0 -15
- package/dist/lib/find-exports.mjs +0 -53
- package/dist/lib/find-requires.d.mts +0 -17
- package/dist/lib/find-requires.mjs +0 -19
- package/dist/lib/find-static-imports.d.mts +0 -15
- package/dist/lib/find-static-imports.mjs +0 -20
- package/dist/lib/has-cjs-syntax.mjs +0 -6
- package/dist/lib/has-esm-syntax.mjs +0 -6
- package/dist/lib/index.d.mts +0 -20
- package/dist/lib/index.mjs +0 -34
- package/dist/lib/resolve-alias.d.mts +0 -20
- package/dist/lib/resolve-alias.mjs +0 -41
- package/dist/lib/resolve-aliases.d.mts +0 -17
- package/dist/lib/resolve-aliases.mjs +0 -34
- package/dist/lib/resolve-module.d.mts +0 -31
- package/dist/lib/resolve-module.mjs +0 -74
- package/dist/lib/resolve-modules.d.mts +0 -19
- package/dist/lib/to-absolute-specifier.mjs +0 -20
- package/dist/lib/to-bare-specifier.d.mts +0 -28
- package/dist/lib/to-bare-specifier.mjs +0 -78
- package/dist/types/declaration.mjs +0 -0
- package/dist/types/ext.d.mts +0 -9
- package/dist/types/ext.mjs +0 -0
- package/dist/types/mime-type.mjs +0 -0
- package/dist/types/specifier-type.d.mts +0 -11
- package/dist/types/specifier-type.mjs +0 -0
- package/dist/types/statement-type.d.mts +0 -9
- package/dist/types/statement-type.mjs +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks if given `value` is a boolean.
|
|
10
|
+
*
|
|
11
|
+
* Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not a boolean.
|
|
12
|
+
*
|
|
13
|
+
* [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
|
|
14
|
+
*
|
|
15
|
+
* @see {@linkcode ERR_INVALID_ARG_TYPE}
|
|
16
|
+
*
|
|
17
|
+
* @param {unknown} value - Value supplied by user
|
|
18
|
+
* @param {string} name - Name of invalid argument or property
|
|
19
|
+
* @return {value is boolean} `true` if `value` is a boolean
|
|
20
|
+
* @throws {NodeError<TypeError>} If `value` is not a boolean
|
|
21
|
+
*/
|
|
22
|
+
const validateBoolean = (value: unknown, name: string): value is boolean => {
|
|
23
|
+
if (typeof value === 'boolean') return true
|
|
24
|
+
throw new ERR_INVALID_ARG_TYPE(name, 'boolean', value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default validateBoolean
|
|
@@ -0,0 +1,30 @@
|
|
|
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 type { ObjectPlain } from '@flex-development/tutils'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if given `value` is an object.
|
|
11
|
+
*
|
|
12
|
+
* **Note**: Array values are not considered objects.
|
|
13
|
+
*
|
|
14
|
+
* Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not an object.
|
|
15
|
+
*
|
|
16
|
+
* [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
|
|
17
|
+
*
|
|
18
|
+
* @see {@linkcode ERR_INVALID_ARG_TYPE}
|
|
19
|
+
*
|
|
20
|
+
* @param {unknown} value - Value supplied by user
|
|
21
|
+
* @param {string} name - Name of invalid argument or property
|
|
22
|
+
* @return {value is ObjectPlain} `true` if `value` is an object
|
|
23
|
+
* @throws {NodeError<TypeError>} If `value` is not an object
|
|
24
|
+
*/
|
|
25
|
+
const validateObject = (value: unknown, name: string): value is ObjectPlain => {
|
|
26
|
+
if (typeof value === 'object' && value && !Array.isArray(value)) return true
|
|
27
|
+
throw new ERR_INVALID_ARG_TYPE(name, 'object', value)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default validateObject
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks if given `value` is an instance of {@linkcode Set}.
|
|
10
|
+
*
|
|
11
|
+
* Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not a {@linkcode Set}
|
|
12
|
+
* instance.
|
|
13
|
+
*
|
|
14
|
+
* [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
|
|
15
|
+
*
|
|
16
|
+
* @see {@linkcode ERR_INVALID_ARG_TYPE}
|
|
17
|
+
*
|
|
18
|
+
* @template T - Item type(s)
|
|
19
|
+
*
|
|
20
|
+
* @param {unknown} value - Value supplied by user
|
|
21
|
+
* @param {string} name - Name of invalid argument or property
|
|
22
|
+
* @return {value is Set} `true` if `value` is instance of {@linkcode Set}
|
|
23
|
+
* @throws {NodeError<TypeError>} If `value` is an instance of {@linkcode Set}
|
|
24
|
+
*/
|
|
25
|
+
function validateSet<T = unknown>(
|
|
26
|
+
value: unknown,
|
|
27
|
+
name: string
|
|
28
|
+
): value is Set<T> {
|
|
29
|
+
if (value instanceof Set) return true
|
|
30
|
+
throw new ERR_INVALID_ARG_TYPE(name, ['Set'], value)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default validateSet
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks if given `value` is a string.
|
|
10
|
+
*
|
|
11
|
+
* Throws [`ERR_INVALID_ARG_TYPE`][1] if the `value` is not a string.
|
|
12
|
+
*
|
|
13
|
+
* [1]: https://nodejs.org/api/errors.html#err_invalid_arg_value
|
|
14
|
+
*
|
|
15
|
+
* @see {@linkcode ERR_INVALID_ARG_TYPE}
|
|
16
|
+
*
|
|
17
|
+
* @param {unknown} value - Value supplied by user
|
|
18
|
+
* @param {string} name - Name of invalid argument or property
|
|
19
|
+
* @return {value is string} `true` if `value` is a string
|
|
20
|
+
* @throws {NodeError<TypeError>} If `value` is not a string
|
|
21
|
+
*/
|
|
22
|
+
const validateString = (value: unknown, name: string): value is string => {
|
|
23
|
+
if (typeof value === 'string') return true
|
|
24
|
+
throw new ERR_INVALID_ARG_TYPE(name, 'string', value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default validateString
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { URL } from 'node:url'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if given `value` is an instance of {@linkcode URL} or a string.
|
|
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
|
+
* @param {unknown} value - Value supplied by user
|
|
19
|
+
* @param {string} name - Name of invalid argument or property
|
|
20
|
+
* @return {value is URL | string} `true` if `value` is `URL` instance or string
|
|
21
|
+
* @throws {NodeError<TypeError>} If `value` is not `URL` instance or string
|
|
22
|
+
*/
|
|
23
|
+
const validateURLString = (
|
|
24
|
+
value: unknown,
|
|
25
|
+
name: string
|
|
26
|
+
): value is URL | string => {
|
|
27
|
+
if (value instanceof URL || typeof value === 'string') return true
|
|
28
|
+
throw new ERR_INVALID_ARG_TYPE(name, ['URL', 'string'], value)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default validateURLString
|
|
@@ -0,0 +1,22 @@
|
|
|
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 }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Definitions - ChangeExtFn
|
|
3
|
+
* @module mlly/types/ChangeExtFn
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { 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 Ext - File extension type(s)
|
|
23
|
+
*
|
|
24
|
+
* @param {string} specifier - Original module specifier
|
|
25
|
+
* @param {URL} url - Resolved module URL
|
|
26
|
+
* @return {Ext | PromiseLike<Ext>} New file extension, `null`, or `undefined`
|
|
27
|
+
*/
|
|
28
|
+
type ChangeExtFn<Ext extends Nilable<string> = Nilable<string>> = (
|
|
29
|
+
specifier: string,
|
|
30
|
+
url: URL
|
|
31
|
+
) => Ext | PromiseLike<Ext>
|
|
32
|
+
|
|
33
|
+
export type { ChangeExtFn as default }
|
|
@@ -0,0 +1,14 @@
|
|
|
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'
|
|
@@ -0,0 +1,19 @@
|
|
|
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 }
|
|
@@ -0,0 +1,15 @@
|
|
|
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 }
|
|
@@ -0,0 +1,13 @@
|
|
|
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 }
|
|
@@ -0,0 +1,40 @@
|
|
|
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 }
|
|
@@ -0,0 +1,20 @@
|
|
|
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 }
|
|
@@ -0,0 +1,22 @@
|
|
|
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 }
|
|
@@ -0,0 +1,15 @@
|
|
|
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 }
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file extractStatements
|
|
3
|
+
* @module mlly/utils/extractStatements
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Statement } from '#src/interfaces'
|
|
7
|
+
import validateString from '#src/internal/validate-string'
|
|
8
|
+
import type { NodeError } from '@flex-development/errnode'
|
|
9
|
+
import findDynamicImports from './find-dynamic-imports'
|
|
10
|
+
import findExports from './find-exports'
|
|
11
|
+
import findRequires from './find-requires'
|
|
12
|
+
import findStaticImports from './find-static-imports'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Finds all `export`, `import`, and/or `require` statements in `code`.
|
|
16
|
+
*
|
|
17
|
+
* Ignores matches in comments.
|
|
18
|
+
*
|
|
19
|
+
* @see {@linkcode findDynamicImports}
|
|
20
|
+
* @see {@linkcode findExports}
|
|
21
|
+
* @see {@linkcode findRequires}
|
|
22
|
+
* @see {@linkcode findStaticImports}
|
|
23
|
+
*
|
|
24
|
+
* @param {string} [code=''] - Code to evaluate
|
|
25
|
+
* @return {Statement[]} Extracted statements
|
|
26
|
+
* @throws {NodeError<TypeError>} If `code` is not a string
|
|
27
|
+
*/
|
|
28
|
+
const extractStatements = (code: string = ''): Statement[] => {
|
|
29
|
+
validateString(code, 'code')
|
|
30
|
+
|
|
31
|
+
// code shorter than first shortest keyword => no possible matches
|
|
32
|
+
if (code.trim().length < 'export'.length) return []
|
|
33
|
+
|
|
34
|
+
return [
|
|
35
|
+
...findDynamicImports(code),
|
|
36
|
+
...findExports(code),
|
|
37
|
+
...findRequires(code),
|
|
38
|
+
...findStaticImports(code)
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default extractStatements
|