Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 29, 2024
1 parent 0f8fb07 commit 2138f9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions src/esm.ts
Expand Up @@ -8,31 +8,31 @@ 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);
}

export function genTypeImport(
specifier: string,
imports: ESMImport[],
options: CodegenOptions = {}
options: CodegenOptions = {},
) {
return _genStatement("import type", specifier, imports, options);
}

export function genTypeExport(
specifier: string,
imports: ESMImport[],
options: CodegenOptions = {}
options: CodegenOptions = {},
) {
return _genStatement("export type", specifier, imports, options);
}

export const genInlineTypeImport = (
specifier: string,
name = "default",
options: CodegenOptions = {}
options: CodegenOptions = {},
) => {
return `typeof ${genDynamicImport(specifier, {
...options,
Expand All @@ -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);
}
Expand All @@ -58,7 +58,7 @@ function _genStatement(
type: ImportExportType,
specifier: string,
names?: ESMImportOrExport | ESMImportOrExport[],
options: CodegenOptions = {}
options: CodegenOptions = {},
) {
const specifierString = genString(specifier, options);
if (!names) {
Expand All @@ -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)};`;
}

Expand Down Expand Up @@ -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 ? "" : "() => ";
Expand All @@ -128,7 +128,7 @@ export function genDynamicImport(
const optionsString = _genDynamicImportOptions(options);
return `${wrapperString}import(${genString(
specifier,
options
options,
)}${commentString}${optionsString})${ineropString}`;
}

Expand Down
12 changes: 6 additions & 6 deletions src/object.ts
Expand Up @@ -2,7 +2,7 @@ import { genObjectKey, wrapInDelimiters } from "./utils";

export function genObjectFromRaw(
object: Record<string, any>,
indent = ""
indent = "",
): string {
return genObjectFromRawEntries(Object.entries(object), indent);
}
Expand All @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/typescript.ts
Expand Up @@ -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",
Expand All @@ -55,15 +55,15 @@ export const genAugmentation = (
interfaces?: Record<
string,
TypeObject | [TypeObject, Omit<GenInterfaceOptions, "export">]
>
>,
) => {
return `declare module ${genString(specifier)} ${wrapInDelimiters(
Object.entries(interfaces || {}).map(
([key, entry]) =>
" " +
(Array.isArray(entry)
? genInterface(key, ...entry)
: genInterface(key, entry))
)
: genInterface(key, entry)),
),
)}`;
};
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -4,7 +4,7 @@ export function wrapInDelimiters(
lines: string[],
indent = "",
delimiters = "{}",
withComma = true
withComma = true,
) {
if (lines.length === 0) {
return delimiters;
Expand Down

0 comments on commit 2138f9a

Please sign in to comment.