diff --git a/src/__tests__/images.test.ts b/src/__tests__/images.test.ts index 9a1a08a..8e637c9 100644 --- a/src/__tests__/images.test.ts +++ b/src/__tests__/images.test.ts @@ -423,7 +423,7 @@ it('010: can inject an image in a document that already contains images inserted `); const reportB = await createReport({ - template: Buffer.from(reportA), + template: reportA, cmdDelimiter: '---', data: { injectImg: () => ({ diff --git a/src/main.ts b/src/main.ts index 5581830..3c50856 100644 --- a/src/main.ts +++ b/src/main.ts @@ -39,7 +39,7 @@ const CONTENT_TYPES_PATH = '[Content_Types].xml' as const; const TEMPLATE_PATH = 'word' as const; const XML_FILE_REGEX = new RegExp(`${TEMPLATE_PATH}\\/[^\\/]+\\.xml`); -export async function parseTemplate(template: Buffer) { +export async function parseTemplate(template: ArrayBuffer) { logger.debug('Unzipping...'); const zip = await zipLoad(template); @@ -319,7 +319,7 @@ async function createReport( * @param delimiter the command delimiter (defaults to ['+++', '+++']) */ export async function listCommands( - template: Buffer, + template: ArrayBuffer, delimiter?: string | [string, string] ): Promise { const opts: CreateReportOptions = { @@ -371,7 +371,7 @@ export async function listCommands( * Extract metadata from a document, such as the number of pages or words. * @param template the docx template as a Buffer-like object */ -export async function getMetadata(template: Buffer) { +export async function getMetadata(template: ArrayBuffer) { const app_xml_path = `docProps/app.xml`; const core_xml_path = `docProps/core.xml`; const zip = await zipLoad(template); diff --git a/src/processTemplate.ts b/src/processTemplate.ts index 2ef90a6..5b06b06 100755 --- a/src/processTemplate.ts +++ b/src/processTemplate.ts @@ -848,13 +848,13 @@ const imageToContext = (ctx: Context, img: Image) => { function validateImage(img: Image) { if ( !( - img.data instanceof Buffer || + img.data instanceof Uint8Array || img.data instanceof ArrayBuffer || typeof img.data === 'string' ) ) { throw new Error( - 'image .data property needs to be provided as Buffer, ArrayBuffer, or as a base64-encoded string' + 'image .data property needs to be provided as Uint8Array (e.g. Buffer, ArrayBuffer), or as a base64-encoded string' ); } if (!ImageExtensions.includes(img.extension)) { diff --git a/src/types.ts b/src/types.ts index 455b8ef..bad3e50 100755 --- a/src/types.ts +++ b/src/types.ts @@ -44,9 +44,9 @@ type RunJSFunc = (o: { sandbox: SandBox; ctx: Context }) => { export type UserOptions = { /** - * Docx file template as a NodeJS Buffer or Buffer-like object in Browsers. + * Docx file template as a Uint8Array (or e.g. ArrayBuffer or NodeJS Buffer). */ - template: Buffer; + template: Uint8Array; /** * Object of data to be injected or a (async) function that resolves to the data. The function gets as an argument the contents of the QUERY command as a string. */ @@ -181,7 +181,7 @@ export const ImageExtensions = [ type ImageExtension = (typeof ImageExtensions)[number]; export type Image = { extension: ImageExtension; - data: Buffer | ArrayBuffer | string; + data: ArrayBuffer | string; }; export type Links = { [id: string]: Link }; type Link = { url: string };