Gathering detailed insights and metrics for html-docx-ts-improve
Gathering detailed insights and metrics for html-docx-ts-improve
npm install html-docx-ts-improve
Typescript
Module System
Node Version
NPM Version
69.8
Supply Chain
94.8
Quality
77.6
Maintenance
100
Vulnerability
99.6
License
TypeScript (99.79%)
JavaScript (0.21%)
Total Downloads
889
Last Day
4
Last Week
15
Last Month
35
Last Year
889
25 Commits
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.3
Package Id
html-docx-ts-improve@1.1.3
Unpacked Size
124.38 kB
Size
30.96 kB
File Count
62
NPM Version
8.11.0
Node Version
16.16.0
Publised On
11 May 2024
Cumulative downloads
Total Downloads
Last day
300%
4
Compared to previous day
Last week
275%
15
Compared to previous week
Last month
45.8%
35
Compared to previous month
Last year
0%
889
Compared to previous year
Rewrite html-docx-js with Typescript.
Convert HTML documents to docx format.
npm install html-docx-ts-improve --save-dev
Support node.js and browser enviroment, including vue/react/angular.
1import { asBlob } from 'html-docx-ts-improve' 2// if you want to save the docx file, you need import 'file-saver' 3import { saveAs } from 'file-saver' 4 5const htmlString = `<!DOCTYPE html> 6<html lang="en"> 7<head> 8 <meta charset="UTF-8"> 9 <title>Document</title> 10</head> 11<body> 12 <h1>Welcome</h1> 13</body> 14</html>` 15 16export default { 17 methods: { 18 saveDocx() { 19 asBlob(htmlString).then(data => { 20 saveAs(data, 'file.docx') // save as docx file 21 }) // asBlob() return Promise<Blob|Buffer> 22 }, 23 }, 24}
And you can set options including margins and orientation.
1const data = await asBlob(htmlString, { orientation: 'landscape', margins: { top: 100 } })
1const data = await asBlob(htmlString, { orientation: 'landscape', margins: { top: 100 }, size: 'A4' })
or
1const data = await asBlob(htmlString, { orientation: 'landscape', margins: { top: 100 }, width: 12240, height: 20160 })
If you use this package in a Typescript file and declare the options to an independent Object
like:
1import { asBlob } from 'html-docx-js-typescript' 2const opt = { 3 margin: { 4 top: 100 5 }, 6 orientation: 'landscape' // type error: because typescript automatically widen this type to 'string' but not 'Orient' - 'string literal type' 7} 8await asBlob(html, opt)
You can use as const
to avoid type widening.
1const opt = { 2 margin: { 3 top: 100 4 }, 5 orientation: 'landscape' as const 6}
MIT
No vulnerabilities found.
No security vulnerabilities found.