@ooxml-tools/file
Advanced tools
| import JSZip from 'jszip'; | ||
| /****************************************************************************** | ||
| Copyright (c) Microsoft Corporation. | ||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted. | ||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
| REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
| INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
| LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
| OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
| PERFORMANCE OF THIS SOFTWARE. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise, SuppressedError, Symbol */ | ||
| function __values(o) { | ||
| var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
| if (m) return m.call(o); | ||
| if (o && typeof o.length === "number") return { | ||
| next: function () { | ||
| if (o && i >= o.length) o = void 0; | ||
| return { value: o && o[i++], done: !o }; | ||
| } | ||
| }; | ||
| throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
| } | ||
| function __await(v) { | ||
| return this instanceof __await ? (this.v = v, this) : new __await(v); | ||
| } | ||
| function __asyncGenerator(thisArg, _arguments, generator) { | ||
| if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
| var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
| return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
| function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; } | ||
| function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } } | ||
| function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
| function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
| function fulfill(value) { resume("next", value); } | ||
| function reject(value) { resume("throw", value); } | ||
| function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } | ||
| } | ||
| function __asyncValues(o) { | ||
| if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
| var m = o[Symbol.asyncIterator], i; | ||
| return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
| function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
| function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
| } | ||
| typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
| var e = new Error(message); | ||
| return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
| }; | ||
| class OpenOfficeXml { | ||
| constructor(zip) { | ||
| this.zip = zip; | ||
| } | ||
| pack() { | ||
| return this.zip.generateAsync({ | ||
| type: "blob", | ||
| mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
| compression: "DEFLATE", | ||
| }); | ||
| } | ||
| unpack() { | ||
| const obj = this; | ||
| return { | ||
| [Symbol.asyncIterator]() { | ||
| return __asyncGenerator(this, arguments, function* _a() { | ||
| const files = yield __await(obj.list()); | ||
| for (const filepath of files) { | ||
| if (obj.zip.files[filepath].dir) { | ||
| yield yield __await({ type: "directory", filepath }); | ||
| } | ||
| else { | ||
| const buffer = obj.zip.file(filepath); | ||
| yield yield __await({ type: "file", filepath, buffer }); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| list() { | ||
| return Object.keys(this.zip.files); | ||
| } | ||
| readdir(dirpath) { | ||
| const obj = this.zip.file(dirpath); | ||
| if (!obj) | ||
| throw new Error(); | ||
| if (!obj.dir) | ||
| throw new Error(); | ||
| return obj; | ||
| } | ||
| isDirectory(dirpath) { | ||
| const obj = this.zip.files[dirpath]; | ||
| if (!obj) | ||
| throw new Error(`Doesn't exist ${dirpath}`); | ||
| return obj.dir; | ||
| } | ||
| mkdir(dirpath) { | ||
| this.zip.folder(dirpath); | ||
| } | ||
| writeFile(filepath, data) { | ||
| this.zip.file(filepath, data); | ||
| } | ||
| async readFile(filepath) { | ||
| const obj = this.zip.file(filepath); | ||
| if (!obj) | ||
| throw new Error(); | ||
| if (obj.dir) | ||
| throw new Error(); | ||
| return await obj.async("uint8array"); | ||
| } | ||
| } | ||
| function open(zip) { | ||
| return new OpenOfficeXml(zip); | ||
| } | ||
| function init() { | ||
| const zip = new JSZip(); | ||
| return new OpenOfficeXml(zip); | ||
| } | ||
| export { OpenOfficeXml as O, __asyncValues as _, init as i, open as o }; |
| import { readFile, stat, writeFile, mkdir } from 'fs/promises'; | ||
| import JSZip from 'jszip'; | ||
| import { o as open, _ as __asyncValues } from './index-7YYBw2Sl.js'; | ||
| import { glob } from 'glob'; | ||
| import { relative, join, dirname } from 'path'; | ||
| 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(); | ||
| const data = await readFile(docxpath); | ||
| await zip.loadAsync(data); | ||
| const doc = open(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(zip); | ||
| const files = await glob(`${dirpath}/**/*`, { ignore: '**/.DS_Store', dot: true }); | ||
| for (const localFilepath of files) { | ||
| const filepath = relative(dirpath, localFilepath); | ||
| const isDir = (await stat(localFilepath)).isDirectory(); | ||
| if (isDir) ; | ||
| else { | ||
| doc.writeFile(filepath, await readFile(localFilepath)); | ||
| } | ||
| } | ||
| const buffer = await zip.generateAsync({ | ||
| type: "nodebuffer", | ||
| mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
| compression: "DEFLATE", | ||
| }); | ||
| 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(); | ||
| const data = await readFile(docxpath); | ||
| await zip.loadAsync(data); | ||
| const doc = open(zip); | ||
| if (!doc.list().includes(filepath)) { | ||
| console.error(`Missing fike: ${filepath}`); | ||
| process.exit(1); | ||
| } | ||
| else { | ||
| const content = await doc.readFile(filepath); | ||
| 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(); | ||
| const data = await readFile(docxpath); | ||
| await zip.loadAsync(data); | ||
| const doc = open(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); | ||
| 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 = Buffer.concat(buffers); | ||
| const zip = new JSZip(); | ||
| const data = await readFile(docxpath); | ||
| await zip.loadAsync(data); | ||
| const doc = open(zip); | ||
| await doc.writeFile(filepath, inputData); | ||
| const buffer = await zip.generateAsync({ | ||
| type: "nodebuffer", | ||
| mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
| compression: "DEFLATE", | ||
| }); | ||
| await writeFile(docxpath, buffer); | ||
| } | ||
| var write = /*#__PURE__*/Object.freeze({ | ||
| __proto__: null, | ||
| builder: builder, | ||
| cmd: cmd, | ||
| desc: desc, | ||
| handler: handler | ||
| }); | ||
| export { cmd$1 as a, builder$3 as b, cmd$3 as c, desc$3 as d, desc$1 as e, builder$1 as f, handler$1 as g, handler$3 as h, cmd$4 as i, desc$4 as j, builder$4 as k, list as l, handler$4 as m, cmd$2 as n, desc$2 as o, pack as p, builder$2 as q, read as r, handler$2 as s, cmd as t, unpack as u, desc as v, write as w, builder as x, handler as y }; |
| #!/usr/bin/env ./node_modules/.bin/tsx | ||
| import { relative } from 'path'; | ||
| 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, f as builder$1, g as handler$1, i as cmd$2, j as desc$2, k as builder$2, m as handler$2, n as cmd$3, o as desc$3, q as builder$3, s as handler$3, t as cmd$4, v as desc$4, x as builder$4, y as handler$4 } from '../write-CHAwJQCt.js'; | ||
| import { c as cmd, d as desc, b as builder, h as handler, a as cmd$1, e as desc$1, f as builder$1, g as handler$1, i as cmd$2, j as desc$2, k as builder$2, m as handler$2, n as cmd$3, o as desc$3, q as builder$3, s as handler$3, t as cmd$4, v as desc$4, x as builder$4, y as handler$4 } from '../write-DXx2bNoG.js'; | ||
| import 'fs/promises'; | ||
| import 'jszip'; | ||
| import '../index-I5ZQQkwV.js'; | ||
| import 'fs/promises'; | ||
| import '../index-7YYBw2Sl.js'; | ||
| import 'glob'; | ||
@@ -9,0 +10,0 @@ var _a; |
@@ -14,7 +14,7 @@ import { Argv, ArgumentsCamelCase } from 'yargs'; | ||
| declare const cmd$3 = "pack <docxpath> <filepath>"; | ||
| declare const cmd$3 = "pack <docxpath> <dirpath>"; | ||
| declare const desc$3 = "pack directory to docx file"; | ||
| declare const builder$3: (yargs: Argv) => void; | ||
| declare function handler$3({ filepath, dirpath }: ArgumentsCamelCase<{ | ||
| filepath: string; | ||
| declare function handler$3({ docxpath, dirpath }: ArgumentsCamelCase<{ | ||
| docxpath: string; | ||
| dirpath: string; | ||
@@ -21,0 +21,0 @@ }>): Promise<void>; |
@@ -1,5 +0,6 @@ | ||
| export { l as list, p as pack, r as read, u as unpack, w as write } from './write-CHAwJQCt.js'; | ||
| export { l as list, p as pack, r as read, u as unpack, w as write } from './write-DXx2bNoG.js'; | ||
| import 'fs/promises'; | ||
| import 'jszip'; | ||
| import './index-I5ZQQkwV.js'; | ||
| import 'fs/promises'; | ||
| import './index-7YYBw2Sl.js'; | ||
| import 'glob'; | ||
| import 'path'; |
@@ -1,2 +0,2 @@ | ||
| export { O as OpenOfficeXml, i as init, o as open } from './index-I5ZQQkwV.js'; | ||
| export { O as OpenOfficeXml, i as init, o as open } from './index-7YYBw2Sl.js'; | ||
| import 'jszip'; |
@@ -20,2 +20,3 @@ import JSZip from 'jszip'; | ||
| readdir(dirpath: string): JSZip.JSZipObject; | ||
| isDirectory(dirpath: string): boolean; | ||
| mkdir(dirpath: string): void; | ||
@@ -22,0 +23,0 @@ writeFile(filepath: string, data: string | Buffer): void; |
+3
-2
| { | ||
| "name": "@ooxml-tools/file", | ||
| "version": "0.1.2", | ||
| "version": "0.1.3", | ||
| "license": "MIT", | ||
@@ -38,3 +38,3 @@ "type": "module", | ||
| "tslib": "^2.6.3", | ||
| "tsx": "^4.16.2" | ||
| "tsx": "^4.17.0" | ||
| }, | ||
@@ -45,2 +45,3 @@ "engines": { | ||
| "dependencies": { | ||
| "glob": "^11.0.0", | ||
| "jszip": "^3.10.1", | ||
@@ -47,0 +48,0 @@ "typescript": "^5.5.4", |
| import JSZip from 'jszip'; | ||
| /****************************************************************************** | ||
| Copyright (c) Microsoft Corporation. | ||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted. | ||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
| REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
| INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
| LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
| OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
| PERFORMANCE OF THIS SOFTWARE. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise, SuppressedError, Symbol */ | ||
| function __values(o) { | ||
| var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
| if (m) return m.call(o); | ||
| if (o && typeof o.length === "number") return { | ||
| next: function () { | ||
| if (o && i >= o.length) o = void 0; | ||
| return { value: o && o[i++], done: !o }; | ||
| } | ||
| }; | ||
| throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
| } | ||
| function __await(v) { | ||
| return this instanceof __await ? (this.v = v, this) : new __await(v); | ||
| } | ||
| function __asyncGenerator(thisArg, _arguments, generator) { | ||
| if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
| var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
| return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
| function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; } | ||
| function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } } | ||
| function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
| function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
| function fulfill(value) { resume("next", value); } | ||
| function reject(value) { resume("throw", value); } | ||
| function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } | ||
| } | ||
| function __asyncValues(o) { | ||
| if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
| var m = o[Symbol.asyncIterator], i; | ||
| return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
| function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
| function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
| } | ||
| typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
| var e = new Error(message); | ||
| return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
| }; | ||
| class OpenOfficeXml { | ||
| constructor(zip) { | ||
| this.zip = zip; | ||
| } | ||
| pack() { | ||
| return this.zip.generateAsync({ type: "blob" }); | ||
| } | ||
| unpack() { | ||
| const obj = this; | ||
| return { | ||
| [Symbol.asyncIterator]() { | ||
| return __asyncGenerator(this, arguments, function* _a() { | ||
| const files = yield __await(obj.list()); | ||
| for (const filepath of files) { | ||
| if (obj.zip.files[filepath].dir) { | ||
| yield yield __await({ type: "directory", filepath }); | ||
| } | ||
| else { | ||
| const buffer = obj.zip.file(filepath); | ||
| yield yield __await({ type: "file", filepath, buffer }); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| list() { | ||
| return Object.keys(this.zip.files); | ||
| } | ||
| readdir(dirpath) { | ||
| const obj = this.zip.file(dirpath); | ||
| if (!obj) | ||
| throw new Error(); | ||
| if (!obj.dir) | ||
| throw new Error(); | ||
| return obj; | ||
| } | ||
| mkdir(dirpath) { | ||
| this.zip.folder(dirpath); | ||
| } | ||
| writeFile(filepath, data) { | ||
| this.zip.file(filepath, data); | ||
| } | ||
| async readFile(filepath) { | ||
| const obj = this.zip.file(filepath); | ||
| if (!obj) | ||
| throw new Error(); | ||
| if (obj.dir) | ||
| throw new Error(); | ||
| return await obj.async("uint8array"); | ||
| } | ||
| } | ||
| function open(zip) { | ||
| return new OpenOfficeXml(zip); | ||
| } | ||
| function init() { | ||
| const zip = new JSZip(); | ||
| return new OpenOfficeXml(zip); | ||
| } | ||
| export { OpenOfficeXml as O, __asyncValues as _, init as i, open as o }; |
| import JSZip from 'jszip'; | ||
| import { o as open, _ as __asyncValues } from './index-I5ZQQkwV.js'; | ||
| import { mkdir, writeFile } from 'fs/promises'; | ||
| import { join } from 'path'; | ||
| 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(docxpath); | ||
| const doc = open(zip); | ||
| console.log(doc.list()); | ||
| } | ||
| var list = /*#__PURE__*/Object.freeze({ | ||
| __proto__: null, | ||
| builder: builder$4, | ||
| cmd: cmd$4, | ||
| desc: desc$4, | ||
| handler: handler$4 | ||
| }); | ||
| const cmd$3 = "pack <docxpath> <filepath>"; | ||
| const desc$3 = "pack directory to docx file"; | ||
| const builder$3 = (yargs) => { | ||
| yargs | ||
| .positional("docxpath", { | ||
| type: "string", | ||
| describe: "", | ||
| }) | ||
| .positional("filepath", { | ||
| type: "string", | ||
| describe: "", | ||
| }); | ||
| }; | ||
| async function handler$3({ filepath, dirpath }) { | ||
| new JSZip(); | ||
| // TODO: | ||
| } | ||
| 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(docxpath); | ||
| const doc = open(zip); | ||
| if (doc.list().includes(filepath)) { | ||
| process.exit(1); | ||
| } | ||
| else { | ||
| console.log(doc.readFile(filepath)); | ||
| 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(docxpath); | ||
| const doc = open(zip); | ||
| for (const docxpath of doc.list()) { | ||
| const outpath = join(docxpath, docxpath); | ||
| await mkdir(outpath, { recursive: true }); | ||
| const data = await doc.readFile(docxpath); | ||
| 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 data = Buffer.concat(buffers); | ||
| const zip = new JSZip(); | ||
| await zip.loadAsync(docxpath); | ||
| const doc = open(zip); | ||
| await doc.writeFile(filepath, data); | ||
| } | ||
| var write = /*#__PURE__*/Object.freeze({ | ||
| __proto__: null, | ||
| builder: builder, | ||
| cmd: cmd, | ||
| desc: desc, | ||
| handler: handler | ||
| }); | ||
| export { cmd$1 as a, builder$3 as b, cmd$3 as c, desc$3 as d, desc$1 as e, builder$1 as f, handler$1 as g, handler$3 as h, cmd$4 as i, desc$4 as j, builder$4 as k, list as l, handler$4 as m, cmd$2 as n, desc$2 as o, pack as p, builder$2 as q, read as r, handler$2 as s, cmd as t, unpack as u, desc as v, write as w, builder as x, handler as y }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
18484
11.28%431
12.24%4
33.33%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added