@stll/docx-utils 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -4
- package/dist/index.js +15 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -51,9 +51,9 @@ type ArchiveOptions = {
|
|
|
51
51
|
};
|
|
52
52
|
type DocxArchive = {
|
|
53
53
|
/**
|
|
54
|
-
* The underlying JSZip instance.
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* The underlying JSZip instance. Write entries with `writeZipEntry`
|
|
55
|
+
* and repack with `zip.generateAsync(...)`; for reads, prefer the
|
|
56
|
+
* bounded helpers on this object.
|
|
57
57
|
*/
|
|
58
58
|
zip: JSZip;
|
|
59
59
|
/**
|
|
@@ -85,6 +85,18 @@ export declare const extractBinary: (zip: JSZip, path: string) => Promise<ArrayB
|
|
|
85
85
|
/** Repack a ZIP to ArrayBuffer with standard DOCX compression */
|
|
86
86
|
export declare const repackZip: (zip: JSZip) => Promise<ArrayBuffer>;
|
|
87
87
|
//#endregion
|
|
88
|
+
//#region src/zip-entry.d.ts
|
|
89
|
+
/** Text or bytes to store as one archive entry. */
|
|
90
|
+
type ZipEntryContent = string | Uint8Array | ArrayBuffer;
|
|
91
|
+
/**
|
|
92
|
+
* Write `content` to `path` in `zip`. Text is UTF-8 encoded here, in one
|
|
93
|
+
* pass over the whole string, before JSZip sees it: JSZip encodes string
|
|
94
|
+
* input in 16 KiB pieces, which splits a surrogate pair that straddles a
|
|
95
|
+
* piece boundary into two U+FFFD characters. Returns `zip`, like
|
|
96
|
+
* `JSZip#file`, so writes can be chained.
|
|
97
|
+
*/
|
|
98
|
+
export declare const writeZipEntry: (zip: JSZip, path: string, content: ZipEntryContent, options?: JSZip.JSZipFileOptions) => JSZip;
|
|
99
|
+
//#endregion
|
|
88
100
|
//#region src/relationships.d.ts
|
|
89
101
|
/** Find the next available rId in a relationships XML string */
|
|
90
102
|
export declare const findNextRId: (relsXml: string) => string;
|
|
@@ -132,4 +144,4 @@ export declare const sanitizeAttachedTemplateRelationships: (xml: string, relati
|
|
|
132
144
|
/** Remove WordprocessingML references to the relationships removed above. */
|
|
133
145
|
export declare const sanitizeAttachedTemplateSource: (xml: string, removedRelationshipIds: readonly string[]) => SanitizedAttachedTemplateSource;
|
|
134
146
|
//#endregion
|
|
135
|
-
export type { ArchiveOptions, AttachedTemplateRelationshipFinding, AttachedTemplateTargetKind, DocxArchive, OoxmlPrefix };
|
|
147
|
+
export type { ArchiveOptions, AttachedTemplateRelationshipFinding, AttachedTemplateTargetKind, DocxArchive, OoxmlPrefix, ZipEntryContent };
|
package/dist/index.js
CHANGED
|
@@ -395,6 +395,20 @@ const extractBinary = async (zip, path) => {
|
|
|
395
395
|
/** Repack a ZIP to ArrayBuffer with standard DOCX compression */
|
|
396
396
|
const repackZip = async (zip) => await zip.generateAsync(DOCX_COMPRESSION);
|
|
397
397
|
//#endregion
|
|
398
|
+
//#region src/zip-entry.ts
|
|
399
|
+
const utf8 = new TextEncoder();
|
|
400
|
+
/**
|
|
401
|
+
* Write `content` to `path` in `zip`. Text is UTF-8 encoded here, in one
|
|
402
|
+
* pass over the whole string, before JSZip sees it: JSZip encodes string
|
|
403
|
+
* input in 16 KiB pieces, which splits a surrogate pair that straddles a
|
|
404
|
+
* piece boundary into two U+FFFD characters. Returns `zip`, like
|
|
405
|
+
* `JSZip#file`, so writes can be chained.
|
|
406
|
+
*/
|
|
407
|
+
const writeZipEntry = (zip, path, content, options) => {
|
|
408
|
+
const data = typeof content === "string" ? utf8.encode(content) : content;
|
|
409
|
+
return zip.file(path, data, options);
|
|
410
|
+
};
|
|
411
|
+
//#endregion
|
|
398
412
|
//#region src/relationships.ts
|
|
399
413
|
/**
|
|
400
414
|
* Escape a string for safe use inside a double-quoted XML attribute value.
|
|
@@ -559,4 +573,4 @@ const sanitizeAttachedTemplateSource = (xml, removedRelationshipIds) => {
|
|
|
559
573
|
};
|
|
560
574
|
};
|
|
561
575
|
//#endregion
|
|
562
|
-
export { ATTACHED_TEMPLATE_SECURITY_RULE, ATTACHED_TEMPLATE_TARGET_KIND, DOCX_COMPRESSION, DOCX_MAX_ENTRIES, DOCX_MAX_ENTRY_BYTES, DOCX_MAX_TOTAL_BYTES, DocxArchiveError, OOXML_NS, classifyAttachedTemplateTarget, ensureContentType, ensureRelationship, extractBinary, extractText, findNextRId, isOpcRelationshipPartPath, loadDocx, loadDocxArchive, relationshipSourcePartPath, repackZip, sanitizeAttachedTemplateRelationships, sanitizeAttachedTemplateSource };
|
|
576
|
+
export { ATTACHED_TEMPLATE_SECURITY_RULE, ATTACHED_TEMPLATE_TARGET_KIND, DOCX_COMPRESSION, DOCX_MAX_ENTRIES, DOCX_MAX_ENTRY_BYTES, DOCX_MAX_TOTAL_BYTES, DocxArchiveError, OOXML_NS, classifyAttachedTemplateTarget, ensureContentType, ensureRelationship, extractBinary, extractText, findNextRId, isOpcRelationshipPartPath, loadDocx, loadDocxArchive, relationshipSourcePartPath, repackZip, sanitizeAttachedTemplateRelationships, sanitizeAttachedTemplateSource, writeZipEntry };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/docx-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Low-level helpers for reading and writing DOCX/OOXML zip packages: text and binary extraction, relationship and content-type management, and namespace constants.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docx",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"test": "bun test src",
|
|
51
51
|
"check:office-fixture-metadata": "bun scripts/check-office-fixture-metadata.ts",
|
|
52
52
|
"test:office-fixture-metadata": "bun test scripts/check-office-fixture-metadata.test.ts",
|
|
53
|
-
"typecheck": "bun
|
|
53
|
+
"typecheck": "bun check --no-pretty --all --project=tsconfig.json",
|
|
54
54
|
"lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --type-aware --type-check packages/docx-utils",
|
|
55
55
|
"lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/docx-utils",
|
|
56
56
|
"format": "bun ../../scripts/run-oxfmt.ts .",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@stll/property-testing": "0.0.0",
|
|
67
67
|
"@stll/typescript-config": "0.0.0",
|
|
68
|
-
"bun-types": "1.4.
|
|
69
|
-
"fast-check": "^4.10.
|
|
68
|
+
"bun-types": "1.4.3",
|
|
69
|
+
"fast-check": "^4.10.2",
|
|
70
70
|
"tsdown": "0.23.0"
|
|
71
71
|
},
|
|
72
72
|
"main": "./dist/index.js",
|