epublib 0.0.0 → 0.1.1
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/epub.d.ts +274 -0
- package/dist/epub.d.ts.map +1 -0
- package/dist/epub.js +367 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/schemas/epub/containerXml.d.ts +18 -0
- package/dist/schemas/epub/containerXml.d.ts.map +1 -0
- package/dist/schemas/epub/containerXml.js +14 -0
- package/dist/schemas/epub/dublinCore.d.ts +393 -0
- package/dist/schemas/epub/dublinCore.d.ts.map +1 -0
- package/dist/schemas/epub/dublinCore.js +39 -0
- package/dist/schemas/epub/global.d.ts +2146 -0
- package/dist/schemas/epub/global.d.ts.map +1 -0
- package/dist/schemas/epub/global.js +52 -0
- package/dist/schemas/epub/packageOpf.d.ts +18 -0
- package/dist/schemas/epub/packageOpf.d.ts.map +1 -0
- package/dist/schemas/epub/packageOpf.js +20 -0
- package/dist/schemas/epub2/packageOpf.d.ts +2273 -0
- package/dist/schemas/epub2/packageOpf.d.ts.map +1 -0
- package/dist/schemas/epub2/packageOpf.js +57 -0
- package/dist/schemas/epub3/global.d.ts +8 -0
- package/dist/schemas/epub3/global.d.ts.map +1 -0
- package/dist/schemas/epub3/global.js +2 -0
- package/dist/schemas/epub3/packageOpf.d.ts +2426 -0
- package/dist/schemas/epub3/packageOpf.d.ts.map +1 -0
- package/dist/schemas/epub3/packageOpf.js +75 -0
- package/dist/schemas/global.d.ts +33 -0
- package/dist/schemas/global.d.ts.map +1 -0
- package/dist/schemas/global.js +94 -0
- package/dist/schemas/loc.d.ts +316 -0
- package/dist/schemas/loc.d.ts.map +1 -0
- package/dist/schemas/loc.js +314 -0
- package/dist/utils/html.d.ts +2 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +4 -0
- package/dist/utils/mime.d.ts +3 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +6 -0
- package/dist/utils/xml.d.ts +4 -0
- package/dist/utils/xml.d.ts.map +1 -0
- package/dist/utils/xml.js +11 -0
- package/package.json +49 -5
- package/index.js +0 -1
package/dist/epub.js
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import AdmZip from "adm-zip";
|
|
2
|
+
import { accessSync, constants } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, normalize, resolve } from "node:path/posix";
|
|
4
|
+
import { satisfies, valid } from "semver";
|
|
5
|
+
import { Temporal } from "temporal-polyfill";
|
|
6
|
+
import z, {} from "zod";
|
|
7
|
+
import { EpubContainerXML } from "./schemas/epub/containerXml.js";
|
|
8
|
+
import { EpubBasicPackageOPF } from "./schemas/epub/packageOpf.js";
|
|
9
|
+
import { Epub2PackageOPF, Epub2PackageOpfMetadataMeta, } from "./schemas/epub2/packageOpf.js";
|
|
10
|
+
import { Epub3PackageOPF, Epub3PackageOpfMetadataMeta, } from "./schemas/epub3/packageOpf.js";
|
|
11
|
+
import { BCP47LanguageTag, ISBN13 } from "./schemas/global.js";
|
|
12
|
+
import { LOCRelator } from "./schemas/loc.js";
|
|
13
|
+
import { sanitizeHTMLString } from "./utils/html.js";
|
|
14
|
+
import { xmlParser } from "./utils/xml.js";
|
|
15
|
+
export class EpubFile {
|
|
16
|
+
#filePath;
|
|
17
|
+
#zip;
|
|
18
|
+
#dev;
|
|
19
|
+
#containerXml;
|
|
20
|
+
#version;
|
|
21
|
+
#packageOpfPath;
|
|
22
|
+
#packageOpf;
|
|
23
|
+
get filePath() {
|
|
24
|
+
return this.#filePath;
|
|
25
|
+
}
|
|
26
|
+
get zip() {
|
|
27
|
+
return this.#zip;
|
|
28
|
+
}
|
|
29
|
+
get containerXml() {
|
|
30
|
+
return this.#containerXml;
|
|
31
|
+
}
|
|
32
|
+
get version() {
|
|
33
|
+
return this.#version;
|
|
34
|
+
}
|
|
35
|
+
get packageOpf() {
|
|
36
|
+
return this.#packageOpf;
|
|
37
|
+
}
|
|
38
|
+
#getContainerXml() {
|
|
39
|
+
const entry = this.#zip.getEntry("META-INF/container.xml");
|
|
40
|
+
if (entry === null) {
|
|
41
|
+
throw new Error(`Could not find "META-INF/container.xml" in epub "${this.#filePath}"`);
|
|
42
|
+
}
|
|
43
|
+
const rawData = xmlParser.parse(entry.getData());
|
|
44
|
+
const parsedData = EpubContainerXML.safeParse(rawData);
|
|
45
|
+
if (parsedData.success === false) {
|
|
46
|
+
if (this.#dev) {
|
|
47
|
+
console.error(z.prettifyError(parsedData.error));
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`"META-INF/container.xml" in epub "${this.#filePath}" is malformed`);
|
|
50
|
+
}
|
|
51
|
+
return parsedData.data;
|
|
52
|
+
}
|
|
53
|
+
#getVersion() {
|
|
54
|
+
const entry = this.#zip.getEntry(this.#packageOpfPath);
|
|
55
|
+
if (entry === null) {
|
|
56
|
+
throw new Error(`Could not find "${this.#packageOpfPath}" in epub "${this.#filePath}"`);
|
|
57
|
+
}
|
|
58
|
+
const rawTextData = entry.getData().toString();
|
|
59
|
+
const rawData = xmlParser.parse(rawTextData.startsWith("<package ")
|
|
60
|
+
? "<?xml version='1.0' encoding='utf-8'?> \n" + rawTextData
|
|
61
|
+
: rawTextData);
|
|
62
|
+
const parsedData = EpubBasicPackageOPF.safeParse(rawData);
|
|
63
|
+
if (parsedData.success === false) {
|
|
64
|
+
if (this.#dev) {
|
|
65
|
+
console.error(z.prettifyError(parsedData.error));
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`"${this.#packageOpfPath}" in epub "${this.#filePath}" is malformed`);
|
|
68
|
+
}
|
|
69
|
+
return satisfies(valid(parsedData.data.package["@_version"] + ".0") ?? "0.0.0", "^3")
|
|
70
|
+
? "3"
|
|
71
|
+
: "2";
|
|
72
|
+
}
|
|
73
|
+
#getPackageOpf() {
|
|
74
|
+
const entry = this.#zip.getEntry(this.#packageOpfPath);
|
|
75
|
+
if (entry === null) {
|
|
76
|
+
throw new Error(`Could not find "${this.#packageOpfPath}" in epub "${this.#filePath}"`);
|
|
77
|
+
}
|
|
78
|
+
const rawTextData = entry.getData().toString();
|
|
79
|
+
const rawData = xmlParser.parse(rawTextData.startsWith("<package ")
|
|
80
|
+
? "<?xml version='1.0' encoding='utf-8'?> \n" + rawTextData
|
|
81
|
+
: rawTextData);
|
|
82
|
+
let parsedData;
|
|
83
|
+
if (this.#version === "3") {
|
|
84
|
+
parsedData = Epub3PackageOPF.safeParse(rawData);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
parsedData = Epub2PackageOPF.safeParse(rawData);
|
|
88
|
+
}
|
|
89
|
+
if (parsedData.success === false) {
|
|
90
|
+
if (this.#dev) {
|
|
91
|
+
console.error(z.prettifyError(parsedData.error));
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`"${this.#packageOpfPath}" (EPUB v${this.#version}) in epub "${this.#filePath}" is malformed`);
|
|
94
|
+
}
|
|
95
|
+
return parsedData.data;
|
|
96
|
+
}
|
|
97
|
+
constructor(filePath, dev = false) {
|
|
98
|
+
this.#dev = dev;
|
|
99
|
+
const fp = normalize(resolve(filePath));
|
|
100
|
+
accessSync(fp, constants.R_OK | constants.W_OK);
|
|
101
|
+
this.#filePath = fp;
|
|
102
|
+
this.#zip = new AdmZip(fp);
|
|
103
|
+
this.#containerXml = this.#getContainerXml();
|
|
104
|
+
this.#packageOpfPath =
|
|
105
|
+
this.#containerXml.container.rootfiles.rootfile["@_full-path"];
|
|
106
|
+
this.#version = this.#getVersion();
|
|
107
|
+
this.#packageOpf = this.#getPackageOpf();
|
|
108
|
+
}
|
|
109
|
+
getCoverImage() {
|
|
110
|
+
function epub2get(t) {
|
|
111
|
+
const p = t.#packageOpf;
|
|
112
|
+
const metaCover = [
|
|
113
|
+
...(p.package.metadata?.meta ?? []),
|
|
114
|
+
...(p.package.metadata?.["opf:meta"] ?? []),
|
|
115
|
+
].find((e) => e["@_name"] === "cover");
|
|
116
|
+
if (!metaCover || !metaCover?.["@_content"]) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const manifestItem = p.package.manifest.item.find((e) => e["@_id"] === metaCover["@_content"]);
|
|
120
|
+
if (!manifestItem) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
const coverImagePath = join(dirname(t.#packageOpfPath), manifestItem["@_href"]);
|
|
124
|
+
const entry = t.#zip.getEntry(coverImagePath);
|
|
125
|
+
if (entry === null) {
|
|
126
|
+
throw new Error(`Could not find "${coverImagePath}" in epub "${t.#filePath}"`);
|
|
127
|
+
}
|
|
128
|
+
return new File([Buffer.from(entry.getData())], basename(coverImagePath), {
|
|
129
|
+
type: manifestItem["@_media-type"],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (this.#version === "3") {
|
|
133
|
+
const coverImageItem = this.#packageOpf.package.manifest.item.find((e) => (e["@_properties"] ?? []).includes("cover-image"));
|
|
134
|
+
if (typeof coverImageItem === "undefined") {
|
|
135
|
+
return epub2get(this);
|
|
136
|
+
}
|
|
137
|
+
const coverImagePath = join(dirname(this.#packageOpfPath), coverImageItem["@_href"]);
|
|
138
|
+
const entry = this.#zip.getEntry(coverImagePath);
|
|
139
|
+
if (entry === null) {
|
|
140
|
+
throw new Error(`Could not find "${coverImagePath}" in epub "${this.#filePath}"`);
|
|
141
|
+
}
|
|
142
|
+
return new File([Buffer.from(entry.getData())], basename(coverImagePath), {
|
|
143
|
+
type: coverImageItem["@_media-type"],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return epub2get(this);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
getTitle() {
|
|
151
|
+
const t = this.#packageOpf.package.metadata["dc:title"]?.[0];
|
|
152
|
+
if (!t) {
|
|
153
|
+
throw new Error(`"${this.#packageOpfPath}" in epub (v${this.#version}) "${this.#filePath}" is missing at least one "dc:title" element`);
|
|
154
|
+
}
|
|
155
|
+
const out = {
|
|
156
|
+
title: t["#text"].trim(),
|
|
157
|
+
fileAs: undefined,
|
|
158
|
+
};
|
|
159
|
+
if (this.#version === "3") {
|
|
160
|
+
if (typeof t["@_id"] === "string") {
|
|
161
|
+
const metaFileAs = [
|
|
162
|
+
...(this.#packageOpf.package
|
|
163
|
+
.metadata?.meta ?? []),
|
|
164
|
+
...(this.#packageOpf.package
|
|
165
|
+
.metadata?.["opf:meta"] ?? []),
|
|
166
|
+
].filter((e) => Epub3PackageOpfMetadataMeta.safeParse(e)?.success).find((e) => typeof e["@_refines"] === "string" &&
|
|
167
|
+
e["@_refines"] === `#${t["@_id"]}` &&
|
|
168
|
+
e["@_property"] === "file-as");
|
|
169
|
+
if (metaFileAs) {
|
|
170
|
+
out.fileAs = metaFileAs["#text"].trim();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const metaCalibreTitleSort = [
|
|
176
|
+
...(this.#packageOpf.package.metadata
|
|
177
|
+
?.meta ?? []),
|
|
178
|
+
...(this.#packageOpf.package
|
|
179
|
+
.metadata?.["opf:meta"] ?? []),
|
|
180
|
+
].filter((e) => Epub2PackageOpfMetadataMeta.safeParse(e)?.success).find((e) => e["@_name"] === "calibre:title_sort" &&
|
|
181
|
+
typeof e["@_content"] === "string");
|
|
182
|
+
if (metaCalibreTitleSort &&
|
|
183
|
+
typeof metaCalibreTitleSort["@_content"] === "string") {
|
|
184
|
+
out.fileAs = metaCalibreTitleSort["@_content"].trim();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (typeof out.fileAs === "string" && out.fileAs === out.title) {
|
|
188
|
+
out.fileAs = undefined;
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
getISBN13() {
|
|
193
|
+
const isbnUrn = this.#packageOpf.package.metadata["dc:identifier"].find((e) => /^urn:isbn:\d{10,13}$/.test(e["#text"]))?.["#text"];
|
|
194
|
+
if (isbnUrn) {
|
|
195
|
+
return ISBN13.safeParse(isbnUrn.replace("urn:isbn:", ""))?.data;
|
|
196
|
+
}
|
|
197
|
+
const isbnOpfScheme = this.#packageOpf.package.metadata["dc:identifier"].find((e) => (e?.["@_opf:scheme"] ?? "").toLocaleUpperCase() === "ISBN")?.["#text"];
|
|
198
|
+
if (isbnOpfScheme) {
|
|
199
|
+
return ISBN13.safeParse(isbnOpfScheme)?.data;
|
|
200
|
+
}
|
|
201
|
+
const meta3 = [
|
|
202
|
+
...(this.#packageOpf.package.metadata?.["meta"] ?? []),
|
|
203
|
+
...(this.#packageOpf.package.metadata?.["opf:meta"] ?? []),
|
|
204
|
+
].filter((e) => Epub3PackageOpfMetadataMeta.safeParse(e).success);
|
|
205
|
+
function identifier3isIsbn(id) {
|
|
206
|
+
const onixType = meta3.find((e) => e["@_property"] === "identifier-type" &&
|
|
207
|
+
e?.["@_refines"] === `#${id}` &&
|
|
208
|
+
e?.["@_scheme"] === "onix:codelist5");
|
|
209
|
+
if (onixType) {
|
|
210
|
+
const onixTypeValue = Number(onixType["#text"]);
|
|
211
|
+
return (!isNaN(onixTypeValue) &&
|
|
212
|
+
(onixTypeValue === 2 || onixTypeValue === 15));
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
const isbnOnly = this.#packageOpf.package.metadata["dc:identifier"].filter((e) => /^\d{10,13}$/.test(e["#text"]));
|
|
217
|
+
for (const i of isbnOnly) {
|
|
218
|
+
if (typeof i["@_id"] === "string" && identifier3isIsbn(i["@_id"])) {
|
|
219
|
+
return ISBN13.parse(i["#text"].replace(/^urn:isbn:/, "").trim());
|
|
220
|
+
}
|
|
221
|
+
const a = ISBN13.safeParse(i["#text"].replace(/^urn:isbn:/, "").trim());
|
|
222
|
+
if (a.success) {
|
|
223
|
+
return a.data;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
getLanguage() {
|
|
229
|
+
const dublinCoreLanguage = this.#packageOpf.package.metadata["dc:language"]?.[0];
|
|
230
|
+
if (!dublinCoreLanguage) {
|
|
231
|
+
throw new Error(`"${this.#packageOpfPath}" in epub (v${this.#version}) "${this.#filePath}" is missing at least one "dc:language" element`);
|
|
232
|
+
}
|
|
233
|
+
return BCP47LanguageTag.parse(dublinCoreLanguage["#text"]);
|
|
234
|
+
}
|
|
235
|
+
getCollection() {
|
|
236
|
+
function calibreGet(t) {
|
|
237
|
+
const m = [
|
|
238
|
+
...(t.#packageOpf.package.metadata?.meta ?? []),
|
|
239
|
+
...(t.#packageOpf.package.metadata?.["opf:meta"] ?? []),
|
|
240
|
+
].filter((e) => Epub2PackageOpfMetadataMeta.safeParse(e)?.success);
|
|
241
|
+
const metaCalibreSeries = m.find((e) => e["@_name"] === "calibre:series" &&
|
|
242
|
+
typeof e["@_content"] === "string");
|
|
243
|
+
const metaCalibreSeriesIndex = m.find((e) => e["@_name"] === "calibre:series_index" &&
|
|
244
|
+
typeof e["@_content"] === "string");
|
|
245
|
+
if (metaCalibreSeries &&
|
|
246
|
+
typeof metaCalibreSeries["@_content"] === "string" &&
|
|
247
|
+
metaCalibreSeriesIndex &&
|
|
248
|
+
!isNaN(Number(metaCalibreSeriesIndex?.["@_content"] ?? "NaN"))) {
|
|
249
|
+
return {
|
|
250
|
+
name: metaCalibreSeries["@_content"].trim(),
|
|
251
|
+
position: Number(metaCalibreSeriesIndex["@_content"]),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
if (this.#version === "3") {
|
|
257
|
+
const m = [
|
|
258
|
+
...(this.#packageOpf.package.metadata?.meta ?? []),
|
|
259
|
+
...(this.#packageOpf.package.metadata?.["opf:meta"] ?? []),
|
|
260
|
+
].filter((e) => Epub3PackageOpfMetadataMeta.safeParse(e)?.success);
|
|
261
|
+
const collectionName = m.find((e) => e["@_property"] === "belongs-to-collection" &&
|
|
262
|
+
typeof e["@_id"] === "string");
|
|
263
|
+
if (collectionName) {
|
|
264
|
+
const collectionType = m.find((e) => e["@_refines"] === `#${collectionName["@_id"]}` &&
|
|
265
|
+
e["@_property"] === "collection-type");
|
|
266
|
+
if ((collectionType && collectionType["#text"] === "series") ||
|
|
267
|
+
typeof collectionType === "undefined") {
|
|
268
|
+
const collectionPosition = m.find((e) => e["@_refines"] === `#${collectionName["@_id"]}` &&
|
|
269
|
+
e["@_property"] === "group-position");
|
|
270
|
+
if (collectionPosition &&
|
|
271
|
+
!isNaN(Number(collectionPosition["#text"]))) {
|
|
272
|
+
return {
|
|
273
|
+
name: collectionName["#text"].trim(),
|
|
274
|
+
position: Number(collectionPosition["#text"]),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return calibreGet(this);
|
|
281
|
+
}
|
|
282
|
+
getDate(config = { stripTime: true }) {
|
|
283
|
+
const dublinCodeDate = this.#packageOpf.package.metadata?.["dc:date"];
|
|
284
|
+
if (!dublinCodeDate) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
if (dublinCodeDate["#text"].length > 10) {
|
|
288
|
+
const i = Temporal.Instant.from(dublinCodeDate["#text"]);
|
|
289
|
+
if (config?.stripTime === false) {
|
|
290
|
+
const ts = i.toZonedDateTimeISO("utc").toString({
|
|
291
|
+
offset: "never",
|
|
292
|
+
fractionalSecondDigits: 0,
|
|
293
|
+
timeZoneName: "never",
|
|
294
|
+
}) + "Z";
|
|
295
|
+
return ts.endsWith("T00:00:00Z")
|
|
296
|
+
? ts.replace("T00:00:00Z", "")
|
|
297
|
+
: ts;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return i
|
|
301
|
+
.toZonedDateTimeISO("utc")
|
|
302
|
+
.toString({
|
|
303
|
+
offset: "never",
|
|
304
|
+
fractionalSecondDigits: 0,
|
|
305
|
+
timeZoneName: "never",
|
|
306
|
+
})
|
|
307
|
+
.substring(0, 10);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return z.iso.date().safeParse(dublinCodeDate["#text"])?.data;
|
|
311
|
+
}
|
|
312
|
+
getPublisher() {
|
|
313
|
+
const m = this.#packageOpf.package.metadata?.["dc:publisher"]?.["#text"];
|
|
314
|
+
return m ? m.trim() : undefined;
|
|
315
|
+
}
|
|
316
|
+
getDescription(sanitizeHTML = true) {
|
|
317
|
+
const d = this.#packageOpf.package.metadata?.["dc:description"]?.["#text"];
|
|
318
|
+
if (d && sanitizeHTML === true) {
|
|
319
|
+
return sanitizeHTMLString(d);
|
|
320
|
+
}
|
|
321
|
+
return d;
|
|
322
|
+
}
|
|
323
|
+
getContributors(excludedRoles = ["bkp"]) {
|
|
324
|
+
const contributorElements = [
|
|
325
|
+
...(this.#packageOpf.package.metadata?.["dc:creator"] ?? []),
|
|
326
|
+
...(this.#packageOpf.package.metadata?.["dc:contributor"] ?? []),
|
|
327
|
+
];
|
|
328
|
+
let out = [];
|
|
329
|
+
const meta3 = [
|
|
330
|
+
...(this.#packageOpf.package.metadata?.["meta"] ?? []),
|
|
331
|
+
...(this.#packageOpf.package.metadata?.["opf:meta"] ?? []),
|
|
332
|
+
].filter((e) => Epub3PackageOpfMetadataMeta.safeParse(e).success);
|
|
333
|
+
for (const c of contributorElements) {
|
|
334
|
+
const m = {
|
|
335
|
+
name: c["#text"].trim(),
|
|
336
|
+
fileAs: undefined,
|
|
337
|
+
role: undefined,
|
|
338
|
+
};
|
|
339
|
+
if (typeof c["@_opf:file-as"] === "string") {
|
|
340
|
+
m.fileAs = c["@_opf:file-as"].trim();
|
|
341
|
+
}
|
|
342
|
+
if (typeof c["@_opf:role"] === "string") {
|
|
343
|
+
m.role = c["@_opf:role"];
|
|
344
|
+
}
|
|
345
|
+
if (typeof m.fileAs === "undefined" &&
|
|
346
|
+
typeof c["@_id"] === "string") {
|
|
347
|
+
const fileAsMeta = meta3.find((e) => e?.["@_refines"] === `#${c["@_id"]}` &&
|
|
348
|
+
e["@_property"] === "file-as");
|
|
349
|
+
if (fileAsMeta) {
|
|
350
|
+
m.fileAs = fileAsMeta["#text"].trim();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (typeof m.role === "undefined" &&
|
|
354
|
+
typeof c["@_id"] === "string") {
|
|
355
|
+
const roleMeta = meta3.find((e) => e?.["@_refines"] === `#${c["@_id"]}` &&
|
|
356
|
+
e["@_property"] === "role" &&
|
|
357
|
+
e?.["@_scheme"] === "marc:relators");
|
|
358
|
+
if (roleMeta) {
|
|
359
|
+
m.role = LOCRelator.safeParse(roleMeta["#text"].trim()).data;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
out.push(m);
|
|
363
|
+
}
|
|
364
|
+
out = out.filter((e) => typeof e.role === "undefined" || !excludedRoles.includes(e.role));
|
|
365
|
+
return out.length > 0 ? out : undefined;
|
|
366
|
+
}
|
|
367
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export declare const EpubContainerXML: z.ZodObject<{
|
|
3
|
+
"?xml": z.ZodObject<{
|
|
4
|
+
"@_version": z.ZodLiteral<"1.0">;
|
|
5
|
+
}, z.z.core.$strip>;
|
|
6
|
+
container: z.ZodObject<{
|
|
7
|
+
rootfiles: z.ZodObject<{
|
|
8
|
+
rootfile: z.ZodObject<{
|
|
9
|
+
"@_full-path": z.ZodString;
|
|
10
|
+
"@_media-type": z.ZodLiteral<"application/oebps-package+xml">;
|
|
11
|
+
}, z.z.core.$strip>;
|
|
12
|
+
}, z.z.core.$strip>;
|
|
13
|
+
"@_version": z.ZodLiteral<"1.0">;
|
|
14
|
+
"@_xmlns": z.ZodLiteral<"urn:oasis:names:tc:opendocument:xmlns:container">;
|
|
15
|
+
}, z.z.core.$strip>;
|
|
16
|
+
}, z.z.core.$strip>;
|
|
17
|
+
export type EpubContainerXML = z.infer<typeof EpubContainerXML>;
|
|
18
|
+
//# sourceMappingURL=containerXml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerXml.d.ts","sourceRoot":"","sources":["../../../src/schemas/epub/containerXml.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;mBAY3B,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export const EpubContainerXML = z.object({
|
|
3
|
+
"?xml": z.object({ "@_version": z.literal("1.0") }),
|
|
4
|
+
container: z.object({
|
|
5
|
+
rootfiles: z.object({
|
|
6
|
+
rootfile: z.object({
|
|
7
|
+
"@_full-path": z.string(),
|
|
8
|
+
"@_media-type": z.literal("application/oebps-package+xml"),
|
|
9
|
+
}),
|
|
10
|
+
}),
|
|
11
|
+
"@_version": z.literal("1.0"),
|
|
12
|
+
"@_xmlns": z.literal("urn:oasis:names:tc:opendocument:xmlns:container"),
|
|
13
|
+
}),
|
|
14
|
+
});
|