
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
cloudflare-docx-parser
Advanced tools
A lightweight library to parse .docx files in Cloudflare Workers
A lightweight library to parse Microsoft Word (.docx) files in Cloudflare Workers. This package is written in TypeScript and extracts plain text by unzipping .docx files (which are essentially ZIP archives) and parsing their XML content.
cloudflare-docx-parser
is designed for Cloudflare Workers and other environments that do not have support for Node.js or browser-specific APIs. It leverages:
This makes it an excellent choice for extracting text from docx files in edge environments or serverless functions.
parseDocx
, to extract plain text from a given .docx file.Install the package with npm:
npm install cloudflare-docx-parser
Below is an example of how to use the package in your project. This example is especially suited for Cloudflare Workers.
import { parseDocx } from "cloudflare-docx-parser";
try {
// Read the .docx file from the request body
const fileBuffer = await request.arrayBuffer();
// Parse the .docx and extract plain text
const extractedText = await parseDocx(fileBuffer);
return new Response(extractedText, {
headers: { "Content-Type": "text/plain" },
});
} catch (error: any) {
return new Response(error.message, { status: 400 });
}
For deployment in Cloudflare Workers, bundle the code using a tool such as esbuild.
Add a build script to your package.json
:
"scripts": {
"build": "esbuild src/index.ts --bundle --minify --platform=browser --format=esm --outfile=dist/index.js"
}
Then run:
npm run build
The output bundle will be generated at dist/index.js
.
The package is written in TypeScript and includes type declarations. Ensure your tsconfig.json
is similar to the following for best compatibility:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"declaration": true,
"outDir": "./dist",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
You can test the solution in a Cloudflare Worker by using Cloudflare Wrangler.
npm install -g @cloudflare/wrangler
wrangler init --name cloudflare-docx-parser
Use the example provided above in your Worker script.
wrangler dev
Contributions, bug reports, and feature requests are welcome! Please submit a PR or open an issue on the GitHub repository.
This project is licensed under the MIT License.
FAQs
A lightweight library to parse .docx files in Cloudflare Workers
The npm package cloudflare-docx-parser receives a total of 0 weekly downloads. As such, cloudflare-docx-parser popularity was classified as not popular.
We found that cloudflare-docx-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.