# html-docx-js-typescript

> Convert HTML documents to docx format.

Latest version **0.1.5** (published 2020-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-docx-js-typescript
pnpm add html-docx-js-typescript
yarn add html-docx-js-typescript
bun add html-docx-js-typescript
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2020-05-24 |
| First published | 2020-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 43.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 115 |
| Author | caiyexiang |
| Maintainers | caiyexiang |
| Keywords | html-docx-js, docx, html, typescript, html-to-docx |

## Links

- npm: https://www.npmjs.com/package/html-docx-js-typescript
- Repository: https://github.com/caiyexiang/html-docx-js-typescript
- Homepage: https://github.com/caiyexiang/html-docx-js-typescript#readme
- Issues: https://github.com/caiyexiang/html-docx-js-typescript/issues
- npm.io page: https://npm.io/package/html-docx-js-typescript

## Dependencies (3)

- [jszip](https://npm.io/package/jszip.md) ^3.4.0
- [tslib](https://npm.io/package/tslib.md) ^1.13.0
- [browser-or-node](https://npm.io/package/browser-or-node.md) ^1.2.1

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.1.5 (latest) — 2020-05-24
- 0.1.4 — 2020-05-24
- 0.1.3 — 2020-05-24
- 0.1.2 — 2020-02-11
- 0.1.1 — 2020-01-30
- 0.1.0 — 2020-01-24

## README

# html-docx-js-typescript

[![NPM version][npm-image]][npm-url]

> Rewrite [html-docx-js](https://www.npmjs.com/package/html-docx-js) with Typescript.

Convert HTML documents to docx format.

## Installing

```
npm install html-docx-js-typescript --save-dev
```

## Usage

Support node.js and browser enviroment, including vue/react/angular.

#### Vue.js usage demo:

```js
import { asBlob } from 'html-docx-js-typescript'
// if you want to save the docx file, you need import 'file-saver'
import { saveAs } from 'file-saver'

const htmlString = `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <h1>Welcome</h1>
</body>
</html>`

export default {
  methods: {
    saveDocx() {
      asBlob(htmlString).then(data => {
        saveAs(data, 'file.docx') // save as docx file
      }) // asBlob() return Promise<Blob|Buffer>
    },
  },
}
```

And you can set options including margins and orientation.

```js
const data = await asBlob(htmlString, { orientation: 'landscape', margins: { top: 100 } })
```

#### literal type widen issue

If you use this package in a Typescript file and declare the options to an independent `Object` like:
``` js
import { asBlob } from 'html-docx-js-typescript'
const opt = {
  margin: {
    top: 100
  },
  orientation: 'landscape' // type error: because typescript automatically widen this type to 'string' but not 'Orient' - 'string literal type'
}
await asBlob(html, opt)
```
You can use `as const` to avoid type widening.
``` js
const opt = {
  margin: {
    top: 100
  },
  orientation: 'landscape' as const
}
```

## License

MIT

[npm-image]: https://img.shields.io/npm/v/html-docx-js-typescript
[npm-url]: https://npmjs.com/package/html-docx-js-typescript

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