Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
63db9f290c | |||
e8bd4bd6c6 | |||
28d93b0c42 | |||
95f8e37006 | |||
87083cb264 | |||
1e8dc95c9c | |||
abfa242c28 | |||
56b5414152 | |||
8f46060be2 | |||
93b17ca2af | |||
66008115b8 | |||
55697a7c32 | |||
e9b259db6b | |||
55c51f7af1 | |||
4e7fd6a6dc | |||
6294ec448f | |||
668198b5d1 | |||
56b2ffe706 | |||
2ab06ffe36 | |||
0c51082bb9 | |||
9a9a2019f6 | |||
d94348f5ca | |||
4c10741862 | |||
222a25e4e2 | |||
5fd4490c4f | |||
e1cc65cb97 | |||
991f837bc1 | |||
87b3035465 | |||
4498305a6c | |||
cac7abba91 |
@ -12,7 +12,6 @@
|
||||
[![Downloads per month][downloads-image]][downloads-url]
|
||||
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
||||
[![PRs Welcome][pr-image]][pr-url]
|
||||
[![codecov][codecov-image]][codecov-url]
|
||||
|
||||
@ -107,8 +106,6 @@ Made with 💖
|
||||
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
||||
[snky-url]: https://snyk.io/test/github/dolanmiu/docx
|
||||
[gitter-image]: https://badges.gitter.im/dolanmiu/docx.svg
|
||||
[gitter-url]: https://gitter.im/docx-lib/Lobby
|
||||
[pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
||||
[pr-url]: http://makeapullrequest.com
|
||||
[codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="../build/index.umd.cjs"></script>
|
||||
<script src="../build/index.umd.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
||||
</head>
|
||||
|
||||
|
@ -5,9 +5,9 @@ import inquirer from "inquirer";
|
||||
import { $ } from "execa";
|
||||
|
||||
export type Answers = {
|
||||
type: "list" | "number";
|
||||
demoNumber?: number;
|
||||
demoFile?: number;
|
||||
readonly type: "list" | "number";
|
||||
readonly demoNumber?: number;
|
||||
readonly demoFile?: number;
|
||||
};
|
||||
|
||||
const dir = "./demo";
|
||||
@ -15,8 +15,7 @@ const fileNames = fs.readdirSync(dir);
|
||||
|
||||
const keys = fileNames.map((f) => path.parse(f).name);
|
||||
const getFileNumber = (file: string): number => {
|
||||
const nameParts = file.split("-");
|
||||
const firstPart = nameParts[0];
|
||||
const [firstPart] = file.split("-");
|
||||
|
||||
return Number(firstPart);
|
||||
};
|
||||
@ -35,15 +34,15 @@ const answers = await inquirer.prompt<Answers>([
|
||||
name: "demoFile",
|
||||
message: "What demo do you wish to run?",
|
||||
choices: demoFiles,
|
||||
filter: (input) => parseInt(input.split("-")[0]),
|
||||
when: (answers) => answers.type === "list",
|
||||
filter: (input) => parseInt(input.split("-")[0], 10),
|
||||
when: (a) => a.type === "list",
|
||||
},
|
||||
{
|
||||
type: "number",
|
||||
name: "demoNumber",
|
||||
message: "What demo do you wish to run? (Enter a number)",
|
||||
default: 1,
|
||||
when: (answers) => answers.type === "number",
|
||||
when: (a) => a.type === "number",
|
||||
},
|
||||
]);
|
||||
|
||||
@ -56,6 +55,7 @@ if (files.length === 0) {
|
||||
const filePath = path.join(dir, files[0]);
|
||||
|
||||
console.log(`Running demo ${demoNumber}: ${files[0]}`);
|
||||
await $`ts-node --project demo/tsconfig.json ${filePath}`;
|
||||
const { stdout } = await $`ts-node --project demo/tsconfig.json ${filePath}`;
|
||||
console.log(stdout);
|
||||
console.log("Successfully created document!");
|
||||
}
|
||||
|
2010
package-lock.json
generated
2010
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,16 +1,13 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "8.2.0",
|
||||
"version": "8.2.2",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"type": "module",
|
||||
"main": "build/index.umd.cjs",
|
||||
"main": "build/index.umd.js",
|
||||
"module": "./build/index.js",
|
||||
"types": "./build/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"browser": {
|
||||
"default": "./build/index.umd.cjs"
|
||||
},
|
||||
"require": "./build/index.cjs",
|
||||
"types": "./build/index.d.ts",
|
||||
"import": "./build/index.js",
|
||||
@ -58,7 +55,6 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/node": "^20.3.1",
|
||||
"fflate": "^0.8.0",
|
||||
"jszip": "^3.10.1",
|
||||
"nanoid": "^4.0.2",
|
||||
"xml": "^1.0.1",
|
||||
@ -78,8 +74,8 @@
|
||||
"@types/xml": "^1.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||
"@typescript-eslint/parser": "^5.36.1",
|
||||
"@vitest/coverage-v8": "^0.32.0",
|
||||
"@vitest/ui": "^0.32.0",
|
||||
"@vitest/coverage-v8": "^0.33.0",
|
||||
"@vitest/ui": "^0.33.0",
|
||||
"cspell": "^6.2.2",
|
||||
"docsify-cli": "^4.3.0",
|
||||
"eslint": "^8.23.0",
|
||||
@ -98,13 +94,13 @@
|
||||
"ts-node": "^10.2.1",
|
||||
"tsconfig-paths": "^4.0.0",
|
||||
"typedoc": "^0.24.8",
|
||||
"typescript": "5.1.3",
|
||||
"typescript": "5.1.6",
|
||||
"unzipper": "^0.10.11",
|
||||
"vite": "^4.3.2",
|
||||
"vite-plugin-dts": "^2.3.0",
|
||||
"vite-plugin-dts": "^3.3.1",
|
||||
"vite-plugin-node-polyfills": "^0.9.0",
|
||||
"vite-tsconfig-paths": "^4.2.0",
|
||||
"vitest": "^0.32.0"
|
||||
"vitest": "^0.33.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
|
@ -53,7 +53,7 @@ export interface PatchDocumentOptions {
|
||||
|
||||
const imageReplacer = new ImageReplacer();
|
||||
|
||||
export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Buffer> => {
|
||||
export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Uint8Array> => {
|
||||
const zipContent = await JSZip.loadAsync(data);
|
||||
const contexts = new Map<string, IContext>();
|
||||
const file = {
|
||||
@ -68,11 +68,11 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
|
||||
const hyperlinkRelationshipAdditions: IHyperlinkRelationshipAddition[] = [];
|
||||
let hasMedia = false;
|
||||
|
||||
const binaryContentMap = new Map<string, Buffer>();
|
||||
const binaryContentMap = new Map<string, Uint8Array>();
|
||||
|
||||
for (const [key, value] of Object.entries(zipContent.files)) {
|
||||
if (!key.endsWith(".xml") && !key.endsWith(".rels")) {
|
||||
binaryContentMap.set(key, await value.async("nodebuffer"));
|
||||
binaryContentMap.set(key, await value.async("uint8array"));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
|
||||
}
|
||||
|
||||
return zip.generateAsync({
|
||||
type: "nodebuffer",
|
||||
type: "uint8array",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
compression: "DEFLATE",
|
||||
});
|
||||
|
@ -9,7 +9,10 @@ export default defineConfig({
|
||||
tsconfigPaths(),
|
||||
dts(),
|
||||
nodePolyfills({
|
||||
exclude: ["fs"],
|
||||
exclude: [],
|
||||
globals: {
|
||||
Buffer: false,
|
||||
},
|
||||
protocolImports: true,
|
||||
}),
|
||||
],
|
||||
@ -26,7 +29,25 @@ export default defineConfig({
|
||||
lib: {
|
||||
entry: [resolve(__dirname, "src/index.ts")],
|
||||
name: "docx",
|
||||
fileName: "index",
|
||||
fileName: (d) => {
|
||||
if (d === "umd") {
|
||||
return "index.umd.js";
|
||||
}
|
||||
|
||||
if (d === "cjs") {
|
||||
return "index.cjs";
|
||||
}
|
||||
|
||||
if (d === "es") {
|
||||
return "index.js";
|
||||
}
|
||||
|
||||
if (d === "iife") {
|
||||
return "index.iife.js";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
},
|
||||
formats: ["iife", "es", "cjs", "umd"],
|
||||
},
|
||||
outDir: resolve(__dirname, "build"),
|
||||
|
Reference in New Issue
Block a user