Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
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]
|
[![Downloads per month][downloads-image]][downloads-url]
|
||||||
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
||||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
|
||||||
[![PRs Welcome][pr-image]][pr-url]
|
[![PRs Welcome][pr-image]][pr-url]
|
||||||
[![codecov][codecov-image]][codecov-url]
|
[![codecov][codecov-image]][codecov-url]
|
||||||
|
|
||||||
@ -107,8 +106,6 @@ Made with 💖
|
|||||||
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||||
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
||||||
[snky-url]: https://snyk.io/test/github/dolanmiu/docx
|
[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-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
||||||
[pr-url]: http://makeapullrequest.com
|
[pr-url]: http://makeapullrequest.com
|
||||||
[codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg
|
[codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<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>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ import inquirer from "inquirer";
|
|||||||
import { $ } from "execa";
|
import { $ } from "execa";
|
||||||
|
|
||||||
export type Answers = {
|
export type Answers = {
|
||||||
type: "list" | "number";
|
readonly type: "list" | "number";
|
||||||
demoNumber?: number;
|
readonly demoNumber?: number;
|
||||||
demoFile?: number;
|
readonly demoFile?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const dir = "./demo";
|
const dir = "./demo";
|
||||||
@ -15,8 +15,7 @@ const fileNames = fs.readdirSync(dir);
|
|||||||
|
|
||||||
const keys = fileNames.map((f) => path.parse(f).name);
|
const keys = fileNames.map((f) => path.parse(f).name);
|
||||||
const getFileNumber = (file: string): number => {
|
const getFileNumber = (file: string): number => {
|
||||||
const nameParts = file.split("-");
|
const [firstPart] = file.split("-");
|
||||||
const firstPart = nameParts[0];
|
|
||||||
|
|
||||||
return Number(firstPart);
|
return Number(firstPart);
|
||||||
};
|
};
|
||||||
@ -35,15 +34,15 @@ const answers = await inquirer.prompt<Answers>([
|
|||||||
name: "demoFile",
|
name: "demoFile",
|
||||||
message: "What demo do you wish to run?",
|
message: "What demo do you wish to run?",
|
||||||
choices: demoFiles,
|
choices: demoFiles,
|
||||||
filter: (input) => parseInt(input.split("-")[0]),
|
filter: (input) => parseInt(input.split("-")[0], 10),
|
||||||
when: (answers) => answers.type === "list",
|
when: (a) => a.type === "list",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "number",
|
type: "number",
|
||||||
name: "demoNumber",
|
name: "demoNumber",
|
||||||
message: "What demo do you wish to run? (Enter a number)",
|
message: "What demo do you wish to run? (Enter a number)",
|
||||||
default: 1,
|
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]);
|
const filePath = path.join(dir, files[0]);
|
||||||
|
|
||||||
console.log(`Running demo ${demoNumber}: ${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!");
|
console.log("Successfully created document!");
|
||||||
}
|
}
|
||||||
|
2004
package-lock.json
generated
2004
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "8.2.0",
|
"version": "8.2.1",
|
||||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "build/index.umd.cjs",
|
"main": "build/index.umd.js",
|
||||||
"module": "./build/index.js",
|
"module": "./build/index.js",
|
||||||
"types": "./build/index.d.ts",
|
"types": "./build/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"browser": {
|
"browser": {
|
||||||
"default": "./build/index.umd.cjs"
|
"default": "./build/index.umd.js"
|
||||||
},
|
},
|
||||||
"require": "./build/index.cjs",
|
"require": "./build/index.cjs",
|
||||||
"types": "./build/index.d.ts",
|
"types": "./build/index.d.ts",
|
||||||
@ -58,7 +58,6 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^20.3.1",
|
"@types/node": "^20.3.1",
|
||||||
"fflate": "^0.8.0",
|
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"nanoid": "^4.0.2",
|
"nanoid": "^4.0.2",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
@ -78,8 +77,8 @@
|
|||||||
"@types/xml": "^1.0.8",
|
"@types/xml": "^1.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||||
"@typescript-eslint/parser": "^5.36.1",
|
"@typescript-eslint/parser": "^5.36.1",
|
||||||
"@vitest/coverage-v8": "^0.32.0",
|
"@vitest/coverage-v8": "^0.33.0",
|
||||||
"@vitest/ui": "^0.32.0",
|
"@vitest/ui": "^0.33.0",
|
||||||
"cspell": "^6.2.2",
|
"cspell": "^6.2.2",
|
||||||
"docsify-cli": "^4.3.0",
|
"docsify-cli": "^4.3.0",
|
||||||
"eslint": "^8.23.0",
|
"eslint": "^8.23.0",
|
||||||
@ -98,13 +97,13 @@
|
|||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"tsconfig-paths": "^4.0.0",
|
"tsconfig-paths": "^4.0.0",
|
||||||
"typedoc": "^0.24.8",
|
"typedoc": "^0.24.8",
|
||||||
"typescript": "5.1.3",
|
"typescript": "5.1.6",
|
||||||
"unzipper": "^0.10.11",
|
"unzipper": "^0.10.11",
|
||||||
"vite": "^4.3.2",
|
"vite": "^4.3.2",
|
||||||
"vite-plugin-dts": "^2.3.0",
|
"vite-plugin-dts": "^3.3.1",
|
||||||
"vite-plugin-node-polyfills": "^0.9.0",
|
"vite-plugin-node-polyfills": "^0.9.0",
|
||||||
"vite-tsconfig-paths": "^4.2.0",
|
"vite-tsconfig-paths": "^4.2.0",
|
||||||
"vitest": "^0.32.0"
|
"vitest": "^0.33.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
@ -53,7 +53,7 @@ export interface PatchDocumentOptions {
|
|||||||
|
|
||||||
const imageReplacer = new ImageReplacer();
|
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 zipContent = await JSZip.loadAsync(data);
|
||||||
const contexts = new Map<string, IContext>();
|
const contexts = new Map<string, IContext>();
|
||||||
const file = {
|
const file = {
|
||||||
@ -213,7 +213,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
|
|||||||
}
|
}
|
||||||
|
|
||||||
return zip.generateAsync({
|
return zip.generateAsync({
|
||||||
type: "nodebuffer",
|
type: "uint8array",
|
||||||
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
compression: "DEFLATE",
|
compression: "DEFLATE",
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,9 @@ export default defineConfig({
|
|||||||
dts(),
|
dts(),
|
||||||
nodePolyfills({
|
nodePolyfills({
|
||||||
exclude: ["fs"],
|
exclude: ["fs"],
|
||||||
|
globals: {
|
||||||
|
Buffer: false,
|
||||||
|
},
|
||||||
protocolImports: true,
|
protocolImports: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -26,7 +29,25 @@ export default defineConfig({
|
|||||||
lib: {
|
lib: {
|
||||||
entry: [resolve(__dirname, "src/index.ts")],
|
entry: [resolve(__dirname, "src/index.ts")],
|
||||||
name: "docx",
|
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"],
|
formats: ["iife", "es", "cjs", "umd"],
|
||||||
},
|
},
|
||||||
outDir: resolve(__dirname, "build"),
|
outDir: resolve(__dirname, "build"),
|
||||||
|
Reference in New Issue
Block a user