Skip to content

Commit 678086d

Browse files
committed
fix: better type-safety
1 parent 220b916 commit 678086d

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

packages/xl-docx-exporter/src/docx/docxExporter.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const DEFAULT_TAB_STOP =
4040
export class DOCXExporter<
4141
B extends BlockSchema,
4242
S extends StyleSchema,
43-
I extends InlineContentSchema
43+
I extends InlineContentSchema,
4444
> extends Exporter<
4545
B,
4646
I,
@@ -71,7 +71,7 @@ export class DOCXExporter<
7171
IRunPropertiesOptions,
7272
TextRun
7373
>["mappings"],
74-
options?: Partial<ExporterOptions>
74+
options?: Partial<ExporterOptions>,
7575
) {
7676
const defaults = {
7777
colors: COLORS_DEFAULT,
@@ -93,7 +93,7 @@ export class DOCXExporter<
9393

9494
const styles: IRunPropertiesOptions = Object.assign(
9595
{} as IRunPropertiesOptions,
96-
...stylesArray
96+
...stylesArray,
9797
);
9898

9999
return new TextRun({
@@ -108,7 +108,7 @@ export class DOCXExporter<
108108
*/
109109
public async transformBlocks(
110110
blocks: Block<B, I, S>[],
111-
nestingLevel = 0
111+
nestingLevel = 0,
112112
): Promise<Array<Paragraph | Table>> {
113113
const ret: Array<Paragraph | Table> = [];
114114

@@ -123,7 +123,7 @@ export class DOCXExporter<
123123
c.addRunToFront(
124124
new TextRun({
125125
children: [new Tab()],
126-
})
126+
}),
127127
);
128128
}
129129
return c;
@@ -143,15 +143,15 @@ export class DOCXExporter<
143143
// "./src/fonts/Inter-VariableFont_opsz,wght.ttf",
144144

145145
let interFont = await loadFileBuffer(
146-
await import("@shared/assets/fonts/inter/Inter_18pt-Regular.ttf")
146+
await import("@shared/assets/fonts/inter/Inter_18pt-Regular.ttf"),
147147
);
148148
let geistMonoFont = await loadFileBuffer(
149-
await import("@shared/assets/fonts/GeistMono-Regular.ttf")
149+
await import("@shared/assets/fonts/GeistMono-Regular.ttf"),
150150
);
151151

152152
if (
153153
interFont instanceof ArrayBuffer ||
154-
geistMonoFont instanceof Uint8Array
154+
geistMonoFont instanceof ArrayBuffer
155155
) {
156156
// conversion with Polyfill needed because docxjs requires Buffer
157157
// NOTE: the buffer/ import is intentional and as documented in
@@ -160,18 +160,18 @@ export class DOCXExporter<
160160
const Buffer = (await import("buffer/")).Buffer;
161161

162162
if (interFont instanceof ArrayBuffer) {
163-
interFont = Buffer.from(interFont);
163+
interFont = Buffer.from(interFont) as unknown as Buffer;
164164
}
165165
if (geistMonoFont instanceof ArrayBuffer) {
166-
geistMonoFont = Buffer.from(geistMonoFont);
166+
geistMonoFont = Buffer.from(geistMonoFont) as unknown as Buffer;
167167
}
168168
}
169169

170170
return [
171-
{ name: "Inter", data: interFont as Buffer },
171+
{ name: "Inter", data: interFont },
172172
{
173173
name: "GeistMono",
174-
data: geistMonoFont as Buffer,
174+
data: geistMonoFont,
175175
},
176176
];
177177
}
@@ -239,7 +239,7 @@ export class DOCXExporter<
239239
} = {
240240
sectionOptions: {},
241241
documentOptions: {},
242-
}
242+
},
243243
) {
244244
const doc = await this.toDocxJsDocument(blocks, options);
245245
type GlobalThis = typeof globalThis & { Buffer?: any };
@@ -268,7 +268,7 @@ export class DOCXExporter<
268268
} = {
269269
sectionOptions: {},
270270
documentOptions: {},
271-
}
271+
},
272272
) {
273273
const doc = new Document({
274274
...(await this.createDefaultDocumentOptions()),
@@ -285,7 +285,7 @@ export class DOCXExporter<
285285
doc.Document.Relationships.createRelationship(
286286
doc.Document.Relationships.RelationshipCount + 1,
287287
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
288-
"fontTable.xml"
288+
"fontTable.xml",
289289
);
290290

291291
return doc;

shared/util/fileUtil.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
export async function loadFileDataUrl(
88
requireUrl: { default: string },
9-
mimeType: string
9+
mimeType: string,
1010
) {
1111
if (import.meta.env.NODE_ENV === "test") {
1212
const buffer = await loadFileBuffer(requireUrl);
@@ -26,7 +26,7 @@ export async function loadFontDataUrl(requireUrl: { default: string }) {
2626

2727
export async function loadFileBuffer(requireUrl: {
2828
default: string;
29-
}) {
29+
}): Promise<Buffer | ArrayBuffer> {
3030
if (import.meta.env.NODE_ENV === "test") {
3131
// in vitest, this is the url we need to load with readfilesync
3232
// eslint-disable-next-line

0 commit comments

Comments
 (0)