diff --git a/src/esm.ts b/src/esm.ts index 2e221ad..4199e54 100644 --- a/src/esm.ts +++ b/src/esm.ts @@ -8,7 +8,7 @@ export type ESMImport = string | { name: string; as?: string }; export function genImport( specifier: string, imports?: ESMImport | ESMImport[], - options: CodegenOptions = {} + options: CodegenOptions = {}, ) { return _genStatement("import", specifier, imports, options); } @@ -16,7 +16,7 @@ export function genImport( export function genTypeImport( specifier: string, imports: ESMImport[], - options: CodegenOptions = {} + options: CodegenOptions = {}, ) { return _genStatement("import type", specifier, imports, options); } @@ -24,7 +24,7 @@ export function genTypeImport( export function genTypeExport( specifier: string, imports: ESMImport[], - options: CodegenOptions = {} + options: CodegenOptions = {}, ) { return _genStatement("export type", specifier, imports, options); } @@ -32,7 +32,7 @@ export function genTypeExport( export const genInlineTypeImport = ( specifier: string, name = "default", - options: CodegenOptions = {} + options: CodegenOptions = {}, ) => { return `typeof ${genDynamicImport(specifier, { ...options, @@ -47,7 +47,7 @@ export type ESMExport = string | { name: string; as?: string }; export function genExport( specifier: string, exports?: ESMExport | ESMExport[], - options: CodegenOptions = {} + options: CodegenOptions = {}, ) { return _genStatement("export", specifier, exports, options); } @@ -58,7 +58,7 @@ function _genStatement( type: ImportExportType, specifier: string, names?: ESMImportOrExport | ESMImportOrExport[], - options: CodegenOptions = {} + options: CodegenOptions = {}, ) { const specifierString = genString(specifier, options); if (!names) { @@ -85,12 +85,12 @@ function _genStatement( if (nameArray) { return `${type} { ${namesString} } from ${genString( specifier, - options + options, )}${_genAssertClause(type, options.assert)};`; } return `${type} ${namesString} from ${genString( specifier, - options + options, )}${_genAssertClause(type, options.assert)};`; } @@ -118,7 +118,7 @@ export interface DynamicImportOptions extends CodegenOptions { } export function genDynamicImport( specifier: string, - options: DynamicImportOptions = {} + options: DynamicImportOptions = {}, ) { const commentString = options.comment ? ` /* ${options.comment} */` : ""; const wrapperString = options.wrapper === false ? "" : "() => "; @@ -128,7 +128,7 @@ export function genDynamicImport( const optionsString = _genDynamicImportOptions(options); return `${wrapperString}import(${genString( specifier, - options + options, )}${commentString}${optionsString})${ineropString}`; } diff --git a/src/object.ts b/src/object.ts index 59e5e48..6ef5163 100644 --- a/src/object.ts +++ b/src/object.ts @@ -2,7 +2,7 @@ import { genObjectKey, wrapInDelimiters } from "./utils"; export function genObjectFromRaw( object: Record, - indent = "" + indent = "", ): string { return genObjectFromRawEntries(Object.entries(object), indent); } @@ -12,29 +12,29 @@ export function genArrayFromRaw(array: any[], indent = "") { return wrapInDelimiters( array.map((index) => `${newIdent}${genRawValue(index, newIdent)}`), indent, - "[]" + "[]", ); } export function genObjectFromRawEntries( array: [key: string, value: any][], - indent = "" + indent = "", ) { const newIdent = indent + " "; return wrapInDelimiters( array.map( ([key, value]) => - `${newIdent}${genObjectKey(key)}: ${genRawValue(value, newIdent)}` + `${newIdent}${genObjectKey(key)}: ${genRawValue(value, newIdent)}`, ), indent, - "{}" + "{}", ); } // --- Internals --- function genRawValue(value: unknown, indent = ""): string { - if (typeof value === "undefined" || value === undefined) { + if (value === undefined) { return "undefined"; } if (value === null) { diff --git a/src/typescript.ts b/src/typescript.ts index 5b1993e..ce4f1e7 100644 --- a/src/typescript.ts +++ b/src/typescript.ts @@ -20,19 +20,19 @@ export const genTypeObject = (object: TypeObject, indent = ""): string => { } return `${newIndent}${genObjectKey(k)}${optional}: ${genTypeObject( value, - newIndent + newIndent, )}`; }), indent, "{}", - false + false, ); }; export const genInterface = ( name: string, contents?: TypeObject, - options: GenInterfaceOptions = {} + options: GenInterfaceOptions = {}, ) => { const result = [ options.export && "export", @@ -55,7 +55,7 @@ export const genAugmentation = ( interfaces?: Record< string, TypeObject | [TypeObject, Omit] - > + >, ) => { return `declare module ${genString(specifier)} ${wrapInDelimiters( Object.entries(interfaces || {}).map( @@ -63,7 +63,7 @@ export const genAugmentation = ( " " + (Array.isArray(entry) ? genInterface(key, ...entry) - : genInterface(key, entry)) - ) + : genInterface(key, entry)), + ), )}`; }; diff --git a/src/utils.ts b/src/utils.ts index 5f63cd7..1e513d1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,7 +4,7 @@ export function wrapInDelimiters( lines: string[], indent = "", delimiters = "{}", - withComma = true + withComma = true, ) { if (lines.length === 0) { return delimiters;