Interfaces
TypeScript interfaces exported from mlly
.
DynamicImport
Dynamic import statement object.
ts
interface DynamicImport extends ImportStatement {
/**
* Import expression.
*
* @example
* 'import("foo.json")'
* @example
* 'import(foo)'
*/
expression: LiteralUnion<EmptyString, string>
/**
* Options bag.
*
* @see https://github.com/tc39/proposal-import-assertions#dynamic-import
*
* @example
* '{ assert: { type: "json" } }'
*/
options: LiteralUnion<EmptyString, string>
/**
* Statement syntax kind.
*/
syntax: StatementSyntaxKind.DYNAMIC
}
See Also
ExportStatement
Export statement object.
ts
interface ExportStatement extends Statement {
/**
* Export declaration, if any.
*/
declaration: Nullable<Declaration>
/**
* Export names.
*/
exports: string[]
/**
* Statement kind.
*/
kind: StatementKind.EXPORT
/**
* Modifier keywords.
*/
modifiers: string[]
/**
* Statement syntax kind.
*/
syntax: SyntaxKindExport
/**
* Type-only export statement check.
*/
type: boolean
}
See Also
FillModuleOptions
Options for fully specifying modules.
ts
interface FillModuleOptions extends ResolveModuleOptions {
/**
* File extension to add to absolute and relative specifiers or a function
* that returns a file extension.
*/
ext: ChangeExtFn<string> | string
}
See Also
FindSubpathOptions
Subpath search options.
ts
interface FindSubpathOptions {
/**
* Export condition to apply.
*
* @see https://nodejs.org/api/packages.html#conditional-exports
*
* @default 'default'
*/
condition?: Optional<string>
/**
* Export conditions.
*
* **Note**: Should be sorted by priority.
*
* @see https://nodejs.org/api/packages.html#conditional-exports
*
* @default CONDITIONS
*/
conditions?: Optional<Set<string>>
/**
* URL of directory containing relevant `package.json` file.
*/
dir: ModuleId
/**
* Package [`imports`][1] hint.
*
* [1]: https://nodejs.org/api/packages.html#imports
*
* @default false
*/
internal?: Optional<boolean>
/**
* URL of module to resolve from.
*
* **Note**: Used for error reporting only.
*/
parent: ModuleId
}
See Also
GetFormatOptions
Module format retrieval options.
ts
interface GetFormatOptions {
/**
* Enable support for JSON modules.
*
* @see https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_json_modules
*
* @default true
*/
experimental_json_modules?: Optional<boolean>
/**
* Enable support for network based modules.
*
* **Note**: Requires [`node-fetch`][1].
*
* [1]: https://github.com/node-fetch/node-fetch
*
* @see https://nodejs.org/docs/latest-v16.x/api/esm.html#https-and-http-imports
*
* @default false
*/
experimental_network_imports?: Optional<boolean>
/**
* Enable support for WebAssembly modules.
*
* @see https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_wasm_modules
*
* @default false
*/
experimental_wasm_modules?: Optional<boolean>
/**
* Map file extensions to module formats.
*
* @default EXTENSION_FORMAT_MAP
*/
extension_format_map?: Optional<Map<EmptyString | Ext, Format>>
/**
* Return `undefined` when module format is not found, rather than `null`.
*
* An explicit `undefined` return value indicates [`load`][1] hooks should
* re-run module format checks.
*
* [1]: https://nodejs.org/docs/latest-v16.x/api/esm.html#loadurl-context-nextload
*
* @default false
*/
ignore_errors?: Optional<boolean>
/**
* Request options for network based modules.
*
* Only applicable if {@linkcode experimental_network_imports} is enabled.
*
* @see [`RequestInit`](https://github.com/node-fetch/node-fetch/blob/v3.3.0/@types/index.d.ts#L71-L112)
*
* @default {}
*/
req?: Optional<import('node-fetch').RequestInit>
}
See Also
GetSourceOptions
Source code retrieval options.
ts
interface GetSourceOptions {
/**
* Enable support for network based modules.
*
* **Note**: Requires [`node-fetch`][1].
*
* [1]: https://github.com/node-fetch/node-fetch
*
* @see https://nodejs.org/docs/latest-v16.x/api/esm.html#https-and-http-imports
*
* @default false
*/
experimental_network_imports?: Optional<boolean>
/**
* Module format hint.
*
* @see [`Format`](/api/enums#format)
*
* @default undefined
*/
format?: Optional<OrLowercase<Format>>
/**
* Ignore [`ERR_UNSUPPORTED_ESM_URL_SCHEME`][1] if thrown.
*
* [1]: https://nodejs.org/api/errors.html#err_unsupported_esm_url_scheme
*
* @default false
*/
ignore_errors?: Optional<boolean>
/**
* Request options for network based modules.
*
* Only applicable if {@linkcode experimental_network_imports} is enabled.
*
* @see [`RequestInit`](https://github.com/node-fetch/node-fetch/blob/v3.3.0/@types/index.d.ts#L71-L112)
*
* @default {}
*/
req?: Optional<import('node-fetch').RequestInit>
}
See Also
ImportAssertions
import
assertions schema.
ts
interface ImportAssertions {
[key: string]: string
/**
* Assertion type.
*/
type?: LiteralUnion<AssertType, string>
}
See Also
ImportStatement
Import statement object.
ts
interface ImportStatement extends Statement {
/**
* Import names.
*/
imports: string[]
/**
* Statement kind.
*/
kind: StatementKind.IMPORT
/**
* Module specifier.
*/
specifier: NonNullable<Statement['specifier']>
/**
* Module specifier syntax type.
*/
specifier_syntax: NonNullable<Statement['specifier_syntax']>
/**
* Statement syntax kind.
*/
syntax: SyntaxKindImport
}
See Also
PackageScope
Object representing a package scope.
ts
interface PackageScope {
/**
* URL of directory containing `package.json` file.
*/
dir: string
/**
* URL of `package.json` file.
*/
pkg: string
/**
* `package.json` object.
*/
pkgjson: PackageJson
}
See Also
ParsedDataUrl
Object representing a data:
URL.
ts
interface ParsedDataUrl {
/**
* [base64][1] encoding check.
*
* [1]: https://developer.mozilla.org/docs/Glossary/Base64
*/
base64: boolean
/**
* Data portion of URL.
*
* If {@linkcode base64} is `true`, `data` is base64-encoded.
*/
data: LiteralUnion<EmptyString, string>
/**
* Serialized `data:` URL.
*
* @see https://nodejs.org/api/url.html#urlhref
*/
href: URL['href']
/**
* MIME type.
*
* @see https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types
*/
mime: LiteralUnion<MimeType, string>
/**
* Path portion of URL.
*
* @see https://nodejs.org/api/url.html#urlpathname
*/
pathname: URL['pathname']
/**
* Protocol portion of URL.
*
* @see https://nodejs.org/api/url.html#urlprotocol
*/
protocol: Extract<Protocol, 'data:'>
}
See Also
ParsedModuleId
Object representing a ECMAScript module id.
ts
interface ParsedModuleId {
/**
* Subpath import (internal specifier) check.
*
* @see https://nodejs.org/api/packages.html#imports
* @see https://nodejs.org/api/packages.html#subpath-imports
*/
internal: boolean
/**
* One of the following:
*
* - Possible [subpath export][1] (includes leading `'.'`)
* - Possible [subpath import][2]
* - URL [`host`][3], [`pathname`][4], and [`port`][5]
* - Raw module id ({@linkcode raw})
*
* [1]: https://nodejs.org/api/packages.html#subpath-exports
* [2]: https://nodejs.org/api/packages.html#subpath-imports
* [3]: https://nodejs.org/api/url.html#urlhost
* [4]: https://nodejs.org/api/url.html#urlpathname
* [5]: https://nodejs.org/api/url.html#urlport
*/
path: string
/**
* Package name if module id begins with valid package name (e.g. is a [bare
* specifier][1]).
*
* If the module id is a bare specifier *and* [internal][2], this value will
* instead be the first path segement in the module id (i.e. `'#src'` given
* `'#src/foo'`). This **may or may not** be the subpath defined by the
* package maintainer.
*
* [1]: https://nodejs.org/api/esm.html#terminology
* [2]: https://nodejs.org/api/packages.html#subpath-imports
*/
pkg: LiteralUnion<EmptyString, string>
/**
* URL scheme if module id is a URL.
*/
protocol: LiteralUnion<EmptyString | Protocol, string>
/**
* Raw module id.
*/
raw: string
/**
* Package scope if module id begins with valid package name (e.g. is a [bare
* specifier][1]).
*
* [1]: https://nodejs.org/api/esm.html#terminology
*/
scope: LiteralUnion<EmptyString, string>
/**
* Package version if specified and module id begins with valid package name
* (e.g. is a [bare specifier][1]).
*
* **Note**: Version follows [Semantic Versioning 2.0.0][2] specification.
*
* [1]: https://nodejs.org/api/esm.html#terminology
* [2]: https://semver.org/spec/v2.0.0.html
*/
version: LiteralUnion<EmptyString | SemanticVersion, string>
/**
* Package {@linkcode version} prefix.
*/
version_prefix: LiteralUnion<EmptyString | 'v', string>
}
See Also
ParsedSubpath
Object representing a package subpath.
ts
interface ParsedSubpath {
/**
* Subpath without entry prefix ({@linkcode key}).
*/
base: LiteralUnion<EmptyString, string>
/**
* Subpath import check.
*
* @see https://nodejs.org/api/packages.html#imports
* @see https://nodejs.org/api/packages.html#subpath-imports
*/
internal: boolean
/**
* Subpath defined in `package.json` file.
*
* @see https://nodejs.org/api/packages.html#exports
* @see https://nodejs.org/api/packages.html#imports
*/
key: string
/**
* Subpath passed by user in module specifier.
*/
raw: string
/**
* Module specifier passed by user.
*/
specifier: string
/**
* Package target as documented in `package.json` file.
*/
target: Nullable<string>
}
See Also
ParseModuleIdOptions
Module id parsing options.
ts
interface ParseModuleIdOptions {
/**
* Ensure module id is a valid internal specifier, syntactically.
*
* @see https://nodejs.org/api/packages.html#subpath-imports
*
* @default id instanceof URL ? false : id.startsWith('#')
*/
internal?: Optional<boolean>
/**
* URL of module to resolve from.
*
* **Note**: Used for error reporting only.
*
* @default undefined
*/
parent?: Optional<ModuleId>
/**
* Ensure module id begins with a valid package name.
*/
pkgname?: Optional<boolean>
}
See Also
ParseSubpathOptions
Subpath parsing options.
ts
interface ParseSubpathOptions {
/**
* Export condition to apply.
*
* @see https://nodejs.org/api/packages.html#conditional-exports
*
* @default 'default'
*/
condition?: Optional<string>
/**
* Export conditions.
*
* **Note**: Should be sorted by priority.
*
* @see https://nodejs.org/api/packages.html#conditional-exports
*
* @default CONDITIONS
*/
conditions?: Optional<Set<string> | string[]>
/**
* URL of directory containing relevant `package.json` file.
*/
dir: ModuleId
/**
* Package [`imports`][1] hint.
*
* [1]: https://nodejs.org/api/packages.html#imports
*
* @default specifier.startsWith('#')
*/
internal?: Optional<boolean>
/**
* URL of module to resolve from.
*
* **Note**: Used for error reporting only.
*/
parent: ModuleId
}
See Also
RequireStatement
Require statement object.
ts
interface RequireStatement extends Statement {
/**
* Import names.
*/
imports: string[]
/**
* Statement kind.
*/
kind: StatementKind.REQUIRE
/**
* Module specifier.
*/
specifier: NonNullable<Statement['specifier']>
/**
* Module specifier syntax type.
*/
specifier_syntax: NonNullable<Statement['specifier_syntax']>
/**
* Statement syntax kind.
*/
syntax: SyntaxKindRequire
}
See Also
ResolveAliasOptions
Path alias resolution options.
ts
interface ResolveAliasOptions extends ResolveModuleOptions {
/**
* Return resolved module URL as absolute specifier (a [`file:` URL][1]).
*
* If `false`, return resolved module URL as bare or relative specifier.
*
* [1]: https://nodejs.org/api/esm.html#file-urls
*
* @see https://nodejs.org/api/esm.html#terminology
*
* @default true
*/
absolute?: Optional<boolean>
/**
* Path mappings.
*
* **Note**: Paths should be relative to {@linkcode cwd}.
*
* @default {}
*/
aliases?: Optional<MapLike<OneOrMany<string>>>
/**
* Directory to resolve non-absolute modules from.
*
* @default pathToFileURL('.')
*/
cwd?: Optional<ModuleId>
/**
* Id of module to resolve from.
*
* **Note**: Should be an absolute path or [`file:` URL][1].
*
* [1]: https://nodejs.org/api/esm.html#file-urls
*
* @default import.meta.url
*/
parent?: Optional<ModuleId>
}
See Also
ResolveModuleOptions
Module resolution options.
ts
interface ResolveModuleOptions {
/**
* Export condition to apply.
*
* @see https://nodejs.org/api/packages.html#conditional-exports
*
* @default 'default'
*/
condition?: Optional<string>
/**
* Export conditions.
*
* **Note**: Should be sorted by priority.
*
* @see https://nodejs.org/api/packages.html#conditional-exports
*
* @default CONDITIONS
*/
conditions?: Optional<Set<string> | string[]>
/**
* Replacement file extension or function that returns a file extension.
*
* An empty string (`''`) will remove a file extension; `null` or `undefined`
* will skip extension replacement.
*
* @default undefined
*/
ext?: ChangeExtFn | Nilable<string>
/**
* Module extensions to probe for.
*
* **Note**: Should be sorted by priority.
*
* @default RESOLVE_EXTENSIONS
*/
extensions?: Optional<Set<string> | string[]>
/**
* URL of module to resolve from.
*
* @see [`ModuleId`](/api/types#moduleid)
*
* @default import.meta.url
*/
parent?: Optional<ModuleId>
/**
* Keep symlinks instead of resolving them.
*
* @default false
*/
preserveSymlinks?: Optional<boolean>
}
See Also
ResolveOptions
Resolution options.
ts
interface ResolveOptions extends ResolveModuleOptions {}
See Also
Statement
CommonJS or ESM statement object.
ts
interface Statement {
/**
* Statement snippet.
*/
code: string
/**
* End index of {@linkcode code} in source content.
*/
end: number
/**
* Statement kind.
*/
kind: StatementKind
/**
* Module specifier.
*/
specifier: Nullable<string>
/**
* Module specifier type.
*/
specifier_kind: Nullable<SpecifierKind>
/**
* Module specifier syntax type.
*/
specifier_syntax: Nullable<SpecifierSyntaxKind>
/**
* Start index of {@linkcode code} in source content.
*/
start: number
/**
* Statement syntax kind.
*/
syntax: StatementSyntaxKind
}
See Also
- [
SpecifierKind
]({@linkcode SpecifierKind}) SpecifierSyntaxKind
StatementKind
StatementSyntaxKind
StaticImport
Static import statement object.
ts
interface StaticImport extends ImportStatement {
/**
* Assertion options.
*
* @see https://github.com/tc39/proposal-import-assertions#import-statements
*
* @example
* '{ type: "json" }'
*/
assertion: LiteralUnion<EmptyString, string>
/**
* Statement syntax kind.
*/
syntax:
| StatementSyntaxKind.DEFAULT
| StatementSyntaxKind.DEFAULT_WITH_NAMED
| StatementSyntaxKind.DEFAULT_WITH_NAMESPACE
| StatementSyntaxKind.NAMED
| StatementSyntaxKind.NAMESPACE
| StatementSyntaxKind.SIDE_EFFECT
/**
* Type-only import statement check.
*/
type: boolean
}