Skip to content

Commit

Permalink
Make types for template more liberal: what works with Buffer should w…
Browse files Browse the repository at this point in the history
…ork with ArrayBuffer, with the benefit that browsers don't need a polyfill.
  • Loading branch information
jjhbw committed Jan 12, 2024
1 parent c07c393 commit b6d7fb2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<CommandSummary[]> {
const opts: CreateReportOptions = {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type UserOptions = {
/**
* Docx file template as a NodeJS Buffer or Buffer-like object in Browsers.
*/
template: Buffer;
template: ArrayBuffer;
/**
* 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.
*/
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit b6d7fb2

Please sign in to comment.