🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@ooxml-tools/file

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ooxml-tools/file - npm Package Compare versions

Comparing version
0.3.1
to
0.4.0
dist/npm/index-ClYnXEp7.js

Sorry, the diff of this file is too big to display

+246
import { writeFile, stat, mkdir } from 'fs/promises';
import JSZip from 'jszip';
import { F as FORMATS, f as formatFromFilename, O as OfficeOpenXml, d as docxBlankFiles, o as open, _ as __asyncValues } from './index-ClYnXEp7.js';
import { glob } from 'glob';
import { relative, join, dirname } from 'path';
import { openAsBlob } from 'fs';
const blankContents = {
docx: docxBlankFiles,
// xlsx: xlsxBlankFiles,
// pptx: pptxBlankFiles,
};
const cmd$6 = "init <docxpath>";
const desc$6 = `initializes a blank file (${FORMATS.join(", ")})`;
const builder$6 = (yargs) => {
yargs.positional("docxpath", {
type: "string",
describe: "",
});
};
async function handler$6({ docxpath, }) {
const zip = new JSZip();
const format = formatFromFilename(docxpath);
if (format !== "docx") {
throw new Error(`${format} not currently supported`);
}
const doc = new OfficeOpenXml(format, zip);
doc.writeFiles(blankContents[format]);
const buffer = await doc.pack("uint8array");
await writeFile(docxpath, buffer);
}
var init = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$6,
cmd: cmd$6,
desc: desc$6,
handler: handler$6
});
const cmd$5 = "formats";
const desc$5 = `list valid formats`;
const builder$5 = (yargs) => {
};
async function handler$5() {
console.log(FORMATS.join("\n"));
}
var formats = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$5,
cmd: cmd$5,
desc: desc$5,
handler: handler$5
});
async function openAsArrayBuffer(filepath) {
return await (await openAsBlob(filepath)).arrayBuffer();
}
const cmd$4 = "list <docxpath>";
const desc$4 = "list files in docx";
const builder$4 = (yargs) => {
yargs.positional("docxpath", {
type: "string",
describe: "",
});
};
async function handler$4({ docxpath, }) {
const zip = new JSZip();
await zip.loadAsync(await openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
console.log(doc.list().join("\n"));
}
var list = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$4,
cmd: cmd$4,
desc: desc$4,
handler: handler$4
});
const cmd$3 = "pack <docxpath> <dirpath>";
const desc$3 = "pack directory to docx file";
const builder$3 = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("dirpath", {
type: "string",
describe: "",
});
};
async function handler$3({ docxpath, dirpath, }) {
const zip = new JSZip();
const doc = open(formatFromFilename(docxpath), zip);
const files = await glob(`${dirpath}/**/*`, {
ignore: "**/.DS_Store",
dot: true,
});
for (const localFilepath of files) {
const filepath = relative(dirpath, localFilepath);
const isFile = (await stat(localFilepath)).isFile();
if (isFile) {
doc.writeFile(filepath, await openAsArrayBuffer(localFilepath));
}
}
const buffer = await doc.pack("uint8array");
await writeFile(docxpath, buffer);
}
var pack = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$3,
cmd: cmd$3,
desc: desc$3,
handler: handler$3
});
const cmd$2 = "read <docxpath> <filepath>";
const desc$2 = "read file inside docx to sdtout";
const builder$2 = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("filepath", {
type: "string",
describe: "",
});
};
async function handler$2({ docxpath, filepath, }) {
const zip = new JSZip();
await zip.loadAsync(openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
if (!doc.list().includes(filepath)) {
console.error(`Missing file: ${filepath}`);
process.exit(1);
}
else {
const content = await doc.readFile(filepath, "uint8array");
const stringContent = new TextDecoder().decode(content);
console.log(stringContent);
process.exit(0);
}
}
var read = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$2,
cmd: cmd$2,
desc: desc$2,
handler: handler$2
});
const cmd$1 = "unpack <docxpath> <dirpath>";
const desc$1 = "unpack docx to a directory";
const builder$1 = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("dirpath", {
type: "string",
describe: "",
});
};
async function handler$1({ docxpath, dirpath, }) {
const zip = new JSZip();
await zip.loadAsync(openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
for (const docxpath of doc.list()) {
if (doc.isDirectory(docxpath)) {
await mkdir(docxpath, { recursive: true });
}
else {
const outpath = join(dirpath, docxpath);
await mkdir(dirname(outpath), { recursive: true });
const data = await doc.readFile(docxpath, "uint8array");
await writeFile(outpath, data);
}
}
}
var unpack = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$1,
cmd: cmd$1,
desc: desc$1,
handler: handler$1
});
const cmd = "write <docxpath> <filepath>";
const desc = "create/override file in docx";
const builder = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("filepath", {
type: "string",
describe: "",
});
};
async function handler({ docxpath, filepath, }) {
var _a, e_1, _b, _c;
const buffers = [];
try {
for (var _d = true, _e = __asyncValues(process.stdin), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const data = _c;
buffers.push(data);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
const inputData = new Blob([Buffer.concat(buffers)]);
const zip = new JSZip();
await zip.loadAsync(openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
doc.writeFile(filepath, await inputData.arrayBuffer());
const buffer = await doc.pack("uint8array");
await writeFile(docxpath, buffer);
}
var write = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder,
cmd: cmd,
desc: desc,
handler: handler
});
export { handler$4 as A, cmd$2 as B, desc$2 as C, builder$2 as D, handler$2 as E, cmd as F, desc as G, builder as H, handler as I, cmd$6 as a, builder$5 as b, cmd$5 as c, desc$5 as d, desc$6 as e, formats as f, builder$6 as g, handler$5 as h, init as i, handler$6 as j, cmd$3 as k, list as l, desc$3 as m, builder$3 as n, handler$3 as o, pack as p, cmd$1 as q, read as r, desc$1 as s, builder$1 as t, unpack as u, handler$1 as v, write as w, cmd$4 as x, desc$4 as y, builder$4 as z };
+3
-3
#!/usr/bin/env node
import yargs from 'yargs/yargs';
import { c as cmd, d as desc, b as builder, h as handler, a as cmd$1, e as desc$1, g as builder$1, j as handler$1, k as cmd$2, m as desc$2, n as builder$2, o as handler$2, q as cmd$3, s as desc$3, t as builder$3, v as handler$3, x as cmd$4, y as desc$4, z as builder$4, A as handler$4, B as cmd$5, C as desc$5, D as builder$5, E as handler$5, F as cmd$6, G as desc$6, H as builder$6, I as handler$6 } from '../write-DThm2QBe.js';
import { c as cmd, d as desc, b as builder, h as handler, a as cmd$1, e as desc$1, g as builder$1, j as handler$1, k as cmd$2, m as desc$2, n as builder$2, o as handler$2, q as cmd$3, s as desc$3, t as builder$3, v as handler$3, x as cmd$4, y as desc$4, z as builder$4, A as handler$4, B as cmd$5, C as desc$5, D as builder$5, E as handler$5, F as cmd$6, G as desc$6, H as builder$6, I as handler$6 } from '../write-Cjfn_G9H.js';
import 'fs/promises';
import 'jszip';
import '../index-DyoPa2IK.js';
import '../index-ClYnXEp7.js';
import 'path';

@@ -11,3 +11,3 @@ import 'glob';

var version = "0.3.1";
var version = "0.4.0";

@@ -14,0 +14,0 @@ const scriptName = "ooxml-file";

@@ -1,7 +0,7 @@

export { f as formats, i as init, l as list, p as pack, r as read, u as unpack, w as write } from './write-DThm2QBe.js';
export { f as formats, i as init, l as list, p as pack, r as read, u as unpack, w as write } from './write-Cjfn_G9H.js';
import 'fs/promises';
import 'jszip';
import './index-DyoPa2IK.js';
import './index-ClYnXEp7.js';
import 'path';
import 'glob';
import 'fs';

@@ -1,3 +0,3 @@

export { F as FORMATS, M as MIME_TYPES, O as OfficeOpenXml, a as assertValidType, d as docxBlankFiles, f as formatFromFilename, g as getMimeType, i as init, o as open, p as pptxBlankFiles, x as xlsxBlankFiles } from './index-DyoPa2IK.js';
export { F as FORMATS, M as MIME_TYPES, O as OfficeOpenXml, a as assertValidType, d as docxBlankFiles, f as formatFromFilename, g as getMimeType, i as init, o as open, p as pptxBlankFiles, x as xlsxBlankFiles } from './index-ClYnXEp7.js';
import 'jszip';
import 'path';
{
"name": "@ooxml-tools/file",
"description": "Read/write Office Open XML files in nodejs/browser",
"version": "0.3.1",
"version": "0.4.0",
"license": "MIT",

@@ -14,3 +14,4 @@ "main": "./dist/npm/index.js",

"lint": "npx prettier . --check",
"test": "jest --coverage",
"test": "vitest",
"test:ci": "vitest run --coverage --reporter=junit --outputFile=test-report.junit.xml",
"lint:format": "npx prettier . --write",

@@ -36,6 +37,5 @@ "build": "npm run build:data && npm run build:npm",

"@tsconfig/node22": "^22.0.0",
"@types/jest": "^29.5.14",
"@types/yargs": "^17.0.32",
"jest": "^29.7.0",
"prettier": "3.6.2",
"@vitest/coverage-v8": "^4.0.15",
"prettier": "3.7.4",
"rollup": "^4.18.1",

@@ -46,6 +46,6 @@ "rollup-plugin-copy": "^3.5.0",

"rollup-plugin-typescript-paths": "^1.5.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"tsx": "^4.17.0"
"tsx": "^4.17.0",
"vitest": "^4.0.15"
},

@@ -56,3 +56,3 @@ "engines": {

"dependencies": {
"glob": "^11.0.0",
"glob": "^13.0.0",
"jszip": "^3.10.1",

@@ -59,0 +59,0 @@ "typescript": "^5.5.4",

@@ -14,3 +14,3 @@ <h1>

- ✅ `.docx` — [WordprocessingML](http://officeopenxml.com/anatomyofOOXML.php)
- 👷 `.xlsx` — [SpreadsheetML](http://officeopenxml.com/anatomyofOOXML-xlsx.php) (coming soon)
- ✅ `.xlsx` — [SpreadsheetML](http://officeopenxml.com/anatomyofOOXML-xlsx.php) (coming soon)
- 👷 `.pptx` — [PresentationML](http://officeopenxml.com/anatomyofOOXML-pptx.php) (coming soon)

@@ -61,5 +61,4 @@

## License
MIT

Sorry, the diff of this file is too big to display

import { writeFile, stat, mkdir } from 'fs/promises';
import JSZip from 'jszip';
import { F as FORMATS, f as formatFromFilename, O as OfficeOpenXml, d as docxBlankFiles, o as open, _ as __asyncValues } from './index-DyoPa2IK.js';
import { glob } from 'glob';
import { relative, join, dirname } from 'path';
import { openAsBlob } from 'fs';
const blankContents = {
docx: docxBlankFiles,
// xlsx: xlsxBlankFiles,
// pptx: pptxBlankFiles,
};
const cmd$6 = "init <docxpath>";
const desc$6 = `initializes a blank file (${FORMATS.join(", ")})`;
const builder$6 = (yargs) => {
yargs.positional("docxpath", {
type: "string",
describe: "",
});
};
async function handler$6({ docxpath, }) {
const zip = new JSZip();
const format = formatFromFilename(docxpath);
if (format !== "docx") {
throw new Error(`${format} not currently supported`);
}
const doc = new OfficeOpenXml(format, zip);
doc.writeFiles(blankContents[format]);
const buffer = await doc.pack("uint8array");
await writeFile(docxpath, buffer);
}
var init = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$6,
cmd: cmd$6,
desc: desc$6,
handler: handler$6
});
const cmd$5 = "formats";
const desc$5 = `list valid formats`;
const builder$5 = (yargs) => {
};
async function handler$5() {
console.log(FORMATS.join("\n"));
}
var formats = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$5,
cmd: cmd$5,
desc: desc$5,
handler: handler$5
});
async function openAsArrayBuffer(filepath) {
return await (await openAsBlob(filepath)).arrayBuffer();
}
const cmd$4 = "list <docxpath>";
const desc$4 = "list files in docx";
const builder$4 = (yargs) => {
yargs.positional("docxpath", {
type: "string",
describe: "",
});
};
async function handler$4({ docxpath, }) {
const zip = new JSZip();
await zip.loadAsync(await openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
console.log(doc.list().join("\n"));
}
var list = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$4,
cmd: cmd$4,
desc: desc$4,
handler: handler$4
});
const cmd$3 = "pack <docxpath> <dirpath>";
const desc$3 = "pack directory to docx file";
const builder$3 = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("dirpath", {
type: "string",
describe: "",
});
};
async function handler$3({ docxpath, dirpath, }) {
const zip = new JSZip();
const doc = open(formatFromFilename(docxpath), zip);
const files = await glob(`${dirpath}/**/*`, {
ignore: "**/.DS_Store",
dot: true,
});
for (const localFilepath of files) {
const filepath = relative(dirpath, localFilepath);
const isFile = (await stat(localFilepath)).isFile();
if (isFile) {
doc.writeFile(filepath, await openAsArrayBuffer(localFilepath));
}
}
const buffer = await doc.pack("uint8array");
await writeFile(docxpath, buffer);
}
var pack = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$3,
cmd: cmd$3,
desc: desc$3,
handler: handler$3
});
const cmd$2 = "read <docxpath> <filepath>";
const desc$2 = "read file inside docx to sdtout";
const builder$2 = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("filepath", {
type: "string",
describe: "",
});
};
async function handler$2({ docxpath, filepath, }) {
const zip = new JSZip();
await zip.loadAsync(openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
if (!doc.list().includes(filepath)) {
console.error(`Missing file: ${filepath}`);
process.exit(1);
}
else {
const content = await doc.readFile(filepath, "uint8array");
const stringContent = new TextDecoder().decode(content);
console.log(stringContent);
process.exit(0);
}
}
var read = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$2,
cmd: cmd$2,
desc: desc$2,
handler: handler$2
});
const cmd$1 = "unpack <docxpath> <dirpath>";
const desc$1 = "unpack docx to a directory";
const builder$1 = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("dirpath", {
type: "string",
describe: "",
});
};
async function handler$1({ docxpath, dirpath, }) {
const zip = new JSZip();
await zip.loadAsync(openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
for (const docxpath of doc.list()) {
if (doc.isDirectory(docxpath)) {
await mkdir(docxpath, { recursive: true });
}
else {
const outpath = join(dirpath, docxpath);
await mkdir(dirname(outpath), { recursive: true });
const data = await doc.readFile(docxpath, "uint8array");
await writeFile(outpath, data);
}
}
}
var unpack = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder$1,
cmd: cmd$1,
desc: desc$1,
handler: handler$1
});
const cmd = "write <docxpath> <filepath>";
const desc = "create/override file in docx";
const builder = (yargs) => {
yargs
.positional("docxpath", {
type: "string",
describe: "",
})
.positional("filepath", {
type: "string",
describe: "",
});
};
async function handler({ docxpath, filepath, }) {
var _a, e_1, _b, _c;
const buffers = [];
try {
for (var _d = true, _e = __asyncValues(process.stdin), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const data = _c;
buffers.push(data);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
const inputData = new Blob([Buffer.concat(buffers)]);
const zip = new JSZip();
await zip.loadAsync(openAsArrayBuffer(docxpath));
const doc = open(formatFromFilename(docxpath), zip);
doc.writeFile(filepath, await inputData.arrayBuffer());
const buffer = await doc.pack("uint8array");
await writeFile(docxpath, buffer);
}
var write = /*#__PURE__*/Object.freeze({
__proto__: null,
builder: builder,
cmd: cmd,
desc: desc,
handler: handler
});
export { handler$4 as A, cmd$2 as B, desc$2 as C, builder$2 as D, handler$2 as E, cmd as F, desc as G, builder as H, handler as I, cmd$6 as a, builder$5 as b, cmd$5 as c, desc$5 as d, desc$6 as e, formats as f, builder$6 as g, handler$5 as h, init as i, handler$6 as j, cmd$3 as k, list as l, desc$3 as m, builder$3 as n, handler$3 as o, pack as p, cmd$1 as q, read as r, desc$1 as s, builder$1 as t, unpack as u, handler$1 as v, write as w, cmd$4 as x, desc$4 as y, builder$4 as z };

Sorry, the diff of this file is too big to display