@ooxml-tools/file
Advanced tools
| #!/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-pLaZQmpB.js'; | ||
| import 'jszip'; | ||
| import '../index-I5ZQQkwV.js'; | ||
| import 'fs/promises'; | ||
| var _a; | ||
| const scriptName = relative(process.cwd(), (_a = process.argv[1]) !== null && _a !== void 0 ? _a : ""); | ||
| yargs(process.argv.slice(2)) | ||
| .usage(`${scriptName} <command> [args]`) | ||
| // HACK to remove script-name from commands | ||
| .scriptName("") | ||
| .example([ | ||
| [`${scriptName} unpack ./test.docx test.docx.unpacked`], | ||
| [`${scriptName} pack ./test.docx test.docx.unpacked`], | ||
| [`${scriptName} list ./test.docx`], | ||
| [`${scriptName} read ./test.docx word/document.xml`], | ||
| [`${scriptName} write ./test.docx word/document.xml < input.xml`], | ||
| ]) | ||
| .command(cmd, desc, builder, handler) | ||
| .command(cmd$1, desc$1, builder$1, handler$1) | ||
| .command(cmd$2, desc$2, builder$2, handler$2) | ||
| .command(cmd$3, desc$3, builder$3, handler$3) | ||
| .command(cmd$4, desc$4, builder$4, handler$4) | ||
| .help() | ||
| .argv; |
| import { Argv, ArgumentsCamelCase } from 'yargs'; | ||
| declare const cmd$4 = "list <docxpath> <filepath>"; | ||
| declare const desc$4 = "list files in docx"; | ||
| declare const builder$4: (yargs: Argv) => void; | ||
| declare function handler$4({ docxpath }: ArgumentsCamelCase<{ | ||
| docxpath: string; | ||
| }>): Promise<void>; | ||
| declare namespace list { | ||
| export { builder$4 as builder, cmd$4 as cmd, desc$4 as desc, handler$4 as handler }; | ||
| } | ||
| declare const cmd$3 = "pack <docxpath> <filepath>"; | ||
| 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; | ||
| dirpath: string; | ||
| }>): Promise<void>; | ||
| declare namespace pack { | ||
| export { builder$3 as builder, cmd$3 as cmd, desc$3 as desc, handler$3 as handler }; | ||
| } | ||
| declare const cmd$2 = "read <docxpath> <filepath>"; | ||
| declare const desc$2 = "read file inside docx to sdtout"; | ||
| declare const builder$2: (yargs: Argv) => void; | ||
| declare function handler$2({ docxpath, filepath }: ArgumentsCamelCase<{ | ||
| docxpath: string; | ||
| filepath: string; | ||
| }>): Promise<void>; | ||
| declare namespace read { | ||
| export { builder$2 as builder, cmd$2 as cmd, desc$2 as desc, handler$2 as handler }; | ||
| } | ||
| declare const cmd$1 = "unpack <docxpath> <dirpath>"; | ||
| declare const desc$1 = "unpack docx to a directory"; | ||
| declare const builder$1: (yargs: Argv) => void; | ||
| declare function handler$1({ docxpath, dirpath }: ArgumentsCamelCase<{ | ||
| docxpath: string; | ||
| dirpath: string; | ||
| }>): Promise<void>; | ||
| declare namespace unpack { | ||
| export { builder$1 as builder, cmd$1 as cmd, desc$1 as desc, handler$1 as handler }; | ||
| } | ||
| declare const cmd = "write <docxpath> <filepath>"; | ||
| declare const desc = "create/override file in docx"; | ||
| declare const builder: (yargs: Argv) => void; | ||
| declare function handler({ docxpath, filepath }: ArgumentsCamelCase<{ | ||
| docxpath: string; | ||
| filepath: string; | ||
| }>): Promise<void>; | ||
| declare const write_builder: typeof builder; | ||
| declare const write_cmd: typeof cmd; | ||
| declare const write_desc: typeof desc; | ||
| declare const write_handler: typeof handler; | ||
| declare namespace write { | ||
| export { write_builder as builder, write_cmd as cmd, write_desc as desc, write_handler as handler }; | ||
| } | ||
| export { list, pack, read, unpack, write }; |
| export { l as list, p as pack, r as read, u as unpack, w as write } from './write-pLaZQmpB.js'; | ||
| import 'jszip'; | ||
| import './index-I5ZQQkwV.js'; | ||
| import 'fs/promises'; | ||
| import 'path'; |
| 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 }; |
| export { O as OpenOfficeXml, i as init, o as open } from './index-I5ZQQkwV.js'; | ||
| import 'jszip'; |
| import JSZip from 'jszip'; | ||
| declare class OpenOfficeXml { | ||
| zip: JSZip; | ||
| constructor(zip: JSZip); | ||
| pack(): Promise<Blob>; | ||
| unpack(): { | ||
| [Symbol.asyncIterator](): AsyncGenerator<{ | ||
| type: string; | ||
| filepath: string; | ||
| buffer?: undefined; | ||
| } | { | ||
| type: string; | ||
| filepath: string; | ||
| buffer: JSZip.JSZipObject | null; | ||
| }, void, unknown>; | ||
| }; | ||
| list(): string[]; | ||
| readdir(dirpath: string): JSZip.JSZipObject; | ||
| mkdir(dirpath: string): void; | ||
| writeFile(filepath: string, data: string | Buffer): void; | ||
| readFile(filepath: string): Promise<Uint8Array>; | ||
| } | ||
| declare function open(zip: JSZip): OpenOfficeXml; | ||
| declare function init(): OpenOfficeXml; | ||
| export { OpenOfficeXml, init, open }; |
| 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> <filepath>"; | ||
| 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 }; |
+1
-1
| { | ||
| "name": "@ooxml-tools/file", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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.
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
16633
567.72%9
350%384
Infinity%4
300%