js.documents 1.82.0 → 1.83.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/model/bytes.cjs +12 -9
- package/dist/model/bytes.js +12 -9
- package/package.json +1 -1
package/dist/model/bytes.cjs
CHANGED
|
@@ -63,20 +63,23 @@ function readAsciiSlice(bytes, offset, length) {
|
|
|
63
63
|
if (bytes.length < offset + length) return;
|
|
64
64
|
return new TextDecoder().decode(bytes.subarray(offset, offset + length));
|
|
65
65
|
}
|
|
66
|
-
function hasOdfMimetypeEntry(bytes,
|
|
66
|
+
function hasOdfMimetypeEntry(bytes, mediaTypes) {
|
|
67
67
|
if (!startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER)) return false;
|
|
68
68
|
if (readUint16LE(bytes, COMPRESSION_METHOD_OFFSET) !== 0) return false;
|
|
69
69
|
if (readAsciiSlice(bytes, MIMETYPE_FILENAME_OFFSET, 8) !== MIMETYPE_ENTRY_FILENAME) return false;
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
return mediaTypes.some((mediaType) => {
|
|
71
|
+
if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
|
|
72
|
+
return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
|
|
73
|
+
});
|
|
72
74
|
}
|
|
73
|
-
function odfBytesSchema(label,
|
|
74
|
-
|
|
75
|
+
function odfBytesSchema(label, mediaTypes) {
|
|
76
|
+
const accepted = mediaTypes.map((type) => `"${type}"`).join(" or ");
|
|
77
|
+
return zod.z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaTypes), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring ${accepted}` });
|
|
75
78
|
}
|
|
76
|
-
const OdtBytesSchema = odfBytesSchema("odt", odf_js.ODF_MEDIA_TYPES.odt);
|
|
77
|
-
const OdsBytesSchema = odfBytesSchema("ods", odf_js.ODF_MEDIA_TYPES.ods);
|
|
78
|
-
const OdpBytesSchema = odfBytesSchema("odp", odf_js.ODF_MEDIA_TYPES.odp);
|
|
79
|
-
const OdgBytesSchema = odfBytesSchema("odg", odf_js.ODF_MEDIA_TYPES.odg);
|
|
79
|
+
const OdtBytesSchema = odfBytesSchema("odt", [odf_js.ODF_MEDIA_TYPES.odt, odf_js.ODF_MEDIA_TYPES.ott]);
|
|
80
|
+
const OdsBytesSchema = odfBytesSchema("ods", [odf_js.ODF_MEDIA_TYPES.ods, odf_js.ODF_MEDIA_TYPES.ots]);
|
|
81
|
+
const OdpBytesSchema = odfBytesSchema("odp", [odf_js.ODF_MEDIA_TYPES.odp, odf_js.ODF_MEDIA_TYPES.otp]);
|
|
82
|
+
const OdgBytesSchema = odfBytesSchema("odg", [odf_js.ODF_MEDIA_TYPES.odg, odf_js.ODF_MEDIA_TYPES.otg]);
|
|
80
83
|
function isWellFormedUtf8Text(bytes) {
|
|
81
84
|
try {
|
|
82
85
|
new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
package/dist/model/bytes.js
CHANGED
|
@@ -62,20 +62,23 @@ function readAsciiSlice(bytes, offset, length) {
|
|
|
62
62
|
if (bytes.length < offset + length) return;
|
|
63
63
|
return new TextDecoder().decode(bytes.subarray(offset, offset + length));
|
|
64
64
|
}
|
|
65
|
-
function hasOdfMimetypeEntry(bytes,
|
|
65
|
+
function hasOdfMimetypeEntry(bytes, mediaTypes) {
|
|
66
66
|
if (!startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER)) return false;
|
|
67
67
|
if (readUint16LE(bytes, COMPRESSION_METHOD_OFFSET) !== 0) return false;
|
|
68
68
|
if (readAsciiSlice(bytes, MIMETYPE_FILENAME_OFFSET, 8) !== MIMETYPE_ENTRY_FILENAME) return false;
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
return mediaTypes.some((mediaType) => {
|
|
70
|
+
if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
|
|
71
|
+
return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
|
|
72
|
+
});
|
|
71
73
|
}
|
|
72
|
-
function odfBytesSchema(label,
|
|
73
|
-
|
|
74
|
+
function odfBytesSchema(label, mediaTypes) {
|
|
75
|
+
const accepted = mediaTypes.map((type) => `"${type}"`).join(" or ");
|
|
76
|
+
return z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaTypes), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring ${accepted}` });
|
|
74
77
|
}
|
|
75
|
-
const OdtBytesSchema = odfBytesSchema("odt", ODF_MEDIA_TYPES.odt);
|
|
76
|
-
const OdsBytesSchema = odfBytesSchema("ods", ODF_MEDIA_TYPES.ods);
|
|
77
|
-
const OdpBytesSchema = odfBytesSchema("odp", ODF_MEDIA_TYPES.odp);
|
|
78
|
-
const OdgBytesSchema = odfBytesSchema("odg", ODF_MEDIA_TYPES.odg);
|
|
78
|
+
const OdtBytesSchema = odfBytesSchema("odt", [ODF_MEDIA_TYPES.odt, ODF_MEDIA_TYPES.ott]);
|
|
79
|
+
const OdsBytesSchema = odfBytesSchema("ods", [ODF_MEDIA_TYPES.ods, ODF_MEDIA_TYPES.ots]);
|
|
80
|
+
const OdpBytesSchema = odfBytesSchema("odp", [ODF_MEDIA_TYPES.odp, ODF_MEDIA_TYPES.otp]);
|
|
81
|
+
const OdgBytesSchema = odfBytesSchema("odg", [ODF_MEDIA_TYPES.odg, ODF_MEDIA_TYPES.otg]);
|
|
79
82
|
function isWellFormedUtf8Text(bytes) {
|
|
80
83
|
try {
|
|
81
84
|
new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
package/package.json
CHANGED