@stacksjs/dtsx
Version:
A modern, fast .d.ts generation tool, powered by Bun.
100 lines (99 loc) • 2.22 kB
TypeScript
/**
* Parse an import statement
*/
export declare function parseImport(statement: string): ParsedImport | null;
/**
* Detect the group for an import source
*/
export declare function detectGroup(source: string, isTypeOnly?: boolean): ImportGroup;
/**
* Sort imports according to configuration
*/
export declare function sortImports(imports: string[], config?: ImportSortConfig): string[];
/**
* Sort imports in a file content
*/
export declare function sortImportsInContent(content: string, config?: ImportSortConfig): string;
/**
* Create a configured import sorter
*/
export declare function createImportSorter(config?: ImportSortConfig): {
sort: (imports: string[]) => string[]
sortContent: (content: string) => string
parse: typeof parseImport
detectGroup: typeof detectGroup
};
/**
* Default import group order
*/
export declare const DEFAULT_GROUP_ORDER: ImportGroup[];
/**
* Preset configurations
*/
export declare const presets: {
/**
* Default preset - groups by type, alphabetizes
*/
default: unknown;
/**
* Node.js style - node: first, then external, then relative
*/
node: unknown;
/**
* Bun style - bun first
*/
bun: unknown;
/**
* Type imports separated
*/
typeSeparated: unknown;
/**
* No grouping, just alphabetize
*/
alphabetical: unknown;
/**
* Keep original order
*/
none: unknown
};
/**
* Import sorting module for organizing imports in declaration files
*/
/**
* Import sorting configuration
*/
export declare interface ImportSortConfig {
order?: string[]
groupByType?: boolean
groups?: ImportGroup[]
alphabetize?: boolean
caseInsensitive?: boolean
typeImportsLast?: boolean
separateTypeImports?: boolean
customGroups?: Record<string, string[]>
}
/**
* Parsed import information
*/
export declare interface ParsedImport {
statement: string
source: string
isTypeOnly: boolean
group: ImportGroup
specifiers: string[]
defaultImport?: string
namespaceImport?: string
lineNumber?: number
}
/**
* Import group types
*/
export type ImportGroup = | 'builtin'
| 'external'
| 'internal'
| 'parent'
| 'sibling'
| 'index'
| 'type'
| 'unknown'
| string // Custom group name;