🎩 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.2.10
to
0.3.1
dist/npm/index-DyoPa2IK.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-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 };
+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-BTXd1val.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-DThm2QBe.js';
import 'fs/promises';
import 'jszip';
import '../index-BdjdsTqn.js';
import '../index-DyoPa2IK.js';
import 'path';

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

var version = "0.2.10";
var version = "0.3.1";

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

@@ -11,3 +11,8 @@ import { Argv, ArgumentsCamelCase } from 'yargs';

declare namespace init {
export { builder$6 as builder, cmd$6 as cmd, desc$6 as desc, handler$6 as handler };
export {
builder$6 as builder,
cmd$6 as cmd,
desc$6 as desc,
handler$6 as handler,
};
}

@@ -21,3 +26,8 @@

declare namespace formats {
export { builder$5 as builder, cmd$5 as cmd, desc$5 as desc, handler$5 as handler };
export {
builder$5 as builder,
cmd$5 as cmd,
desc$5 as desc,
handler$5 as handler,
};
}

@@ -33,3 +43,8 @@

declare namespace list {
export { builder$4 as builder, cmd$4 as cmd, desc$4 as desc, handler$4 as handler };
export {
builder$4 as builder,
cmd$4 as cmd,
desc$4 as desc,
handler$4 as handler,
};
}

@@ -46,3 +61,8 @@

declare namespace pack {
export { builder$3 as builder, cmd$3 as cmd, desc$3 as desc, handler$3 as handler };
export {
builder$3 as builder,
cmd$3 as cmd,
desc$3 as desc,
handler$3 as handler,
};
}

@@ -59,3 +79,8 @@

declare namespace read {
export { builder$2 as builder, cmd$2 as cmd, desc$2 as desc, handler$2 as handler };
export {
builder$2 as builder,
cmd$2 as cmd,
desc$2 as desc,
handler$2 as handler,
};
}

@@ -72,3 +97,8 @@

declare namespace unpack {
export { builder$1 as builder, cmd$1 as cmd, desc$1 as desc, handler$1 as handler };
export {
builder$1 as builder,
cmd$1 as cmd,
desc$1 as desc,
handler$1 as handler,
};
}

@@ -89,5 +119,10 @@

declare namespace write {
export { write_builder as builder, write_cmd as cmd, write_desc as desc, write_handler as handler };
export {
write_builder as builder,
write_cmd as cmd,
write_desc as desc,
write_handler as handler,
};
}
export { formats, init, list, pack, read, unpack, write };

@@ -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-BTXd1val.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-DThm2QBe.js';
import 'fs/promises';
import 'jszip';
import './index-BdjdsTqn.js';
import './index-DyoPa2IK.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-BdjdsTqn.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-DyoPa2IK.js';
import 'jszip';
import 'path';
{
"name": "@ooxml-tools/file",
"description": "Read/write Office Open XML files in nodejs/browser",
"version": "0.2.10",
"version": "0.3.1",
"license": "MIT",

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

"lint": "npx prettier . --check",
"test": "jest",
"test": "jest --coverage",
"lint:format": "npx prettier . --write",

@@ -31,2 +31,3 @@ "build": "npm run build:data && npm run build:npm",

"devDependencies": {
"@codecov/rollup-plugin": "^1.9.1",
"@rollup/plugin-json": "^6.1.0",

@@ -39,3 +40,3 @@ "@rollup/plugin-typescript": "^12.1.2",

"jest": "^29.7.0",
"prettier": "3.4.2",
"prettier": "3.6.2",
"rollup": "^4.18.1",

@@ -58,4 +59,4 @@ "rollup-plugin-copy": "^3.5.0",

"typescript": "^5.5.4",
"yargs": "^17.7.2"
"yargs": "^18.0.0"
}
}

@@ -56,4 +56,9 @@ <h1>

## CI
[![codecov](https://codecov.io/gh/ooxml-tools/file/graph/badge.svg?token=TZ6IV00CPW)](https://codecov.io/gh/ooxml-tools/file)
## 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-BdjdsTqn.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