# docx_editor

> Tool for editing .docx files as plain js objects

Latest version **0.5.0** (published 2021-08-16) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install docx_editor
pnpm add docx_editor
yarn add docx_editor
bun add docx_editor
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2021-08-16 |
| First published | 2021-08-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Sergey Sovgut |
| Maintainers | sovgut |
| Keywords | docx, word, js, editor, raw |

## Links

- npm: https://www.npmjs.com/package/docx_editor
- Repository: https://github.com/Sovgut/docx_editor
- Homepage: https://github.com/Sovgut/docx_editor#README
- Issues: https://github.com/Sovgut/docx_editor/issues
- npm.io page: https://npm.io/package/docx_editor

## Dependencies (4)

- [he](https://npm.io/package/he.md) ^1.2.0
- [jszip](https://npm.io/package/jszip.md) ^3.7.1
- [nanoid](https://npm.io/package/nanoid.md) ^3.1.25
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^3.19.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.5.0 (latest) — 2021-08-16
- 0.4.1 — 2021-08-14
- 0.3.0 — 2021-08-12
- 0.2.1 — 2021-08-12
- 0.2.0 — 2021-08-12
- 0.1.1 — 2021-08-12
- 0.1.0 — 2021-08-12

## README

# Docx Editor
Tool for editing .docx files as plain js objects

# Code examples

```javascript
const path = require("path");
const fs = require("fs");
const DocumentEditor = require("docx_editor");

(async () => {
    const data = fs.readFileSync(path.join(process.cwd(), "document.docx"));
    const img = fs.readFileSync(path.join(process.cwd(), "example.png"));
    const docEditor = await new DocumentEditor().extract(data);
    
    docEditor.parse("docProps/app.xml", (doc) => {
        doc["Properties"]["Lines"] = 2;
    });
    
    docEditor.parse("word/document.xml", (doc) => {
        doc["w:document"]["w:body"]["w:p"][0]["w:r"] = [{ "w:t": "Hello World!" }];
    });
    
    docEditor.mkdir("word/media");
    docEditor.writeFile("word/media/img.png", img);
    
    const updatedDocument = await docEditor.archive();
    fs.writeFileSync(path.join(process.cwd(), "document-edited.docx"), updatedDocument);
})()
```



# Options
You can pass options to constructor for changing working directory, default document name or for enabling logging

```typescript
{
    // Default: false
    showLogs: boolean
    
    // Default: os.tmpdir()
    workDirectory: string
    
    // Default: `document_${nanoid(8)}_${Date.now()}`
    documentName: string
}
```

# Installation
```bash
$ npm i docx_editor
```

---
_Source: https://npm.io/package/docx_editor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
