epublib 0.1.4 → 0.2.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 +5 -0
- package/dist/epub.d.ts.map +1 -1
- package/dist/epub.js +58 -4
- package/dist/schemas/epub/dublinCore.d.ts +1 -1
- package/dist/schemas/epub/dublinCore.d.ts.map +1 -1
- package/dist/schemas/epub/dublinCore.js +3 -0
- package/dist/schemas/epub/global.d.ts +1 -1
- package/dist/schemas/epub2/packageOpf.d.ts +1 -1
- package/dist/schemas/epub3/packageOpf.d.ts +1 -1
- package/package.json +1 -1
package/dist/epub.d.ts
CHANGED
|
@@ -259,10 +259,15 @@ export declare class EpubFile {
|
|
|
259
259
|
};
|
|
260
260
|
constructor(filePath: string, dev?: boolean);
|
|
261
261
|
getCoverImage(): File | undefined;
|
|
262
|
+
hasCoverImage(): boolean;
|
|
262
263
|
getTitle(): EpubFileGetTitle;
|
|
263
264
|
getISBN13(): ISBN13 | undefined;
|
|
264
265
|
getLanguage(): BCP47LanguageTag;
|
|
265
266
|
getCollection(): EpubFileGetCollection | undefined;
|
|
267
|
+
/**
|
|
268
|
+
*
|
|
269
|
+
* @returns {string} ISO partial date (possible formats: `2010-01-12`, `2010-01`, `2010`)
|
|
270
|
+
*/
|
|
266
271
|
getDate(config?: Partial<{
|
|
267
272
|
stripTime: boolean;
|
|
268
273
|
}>): string | undefined;
|
package/dist/epub.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epub.d.ts","sourceRoot":"","sources":["../src/epub.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAiB7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C,UAAU,gBAAgB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,M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ACb,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;CAC7B;AAED,qBAAa,QAAQ;;IASpB,IAAI,QAAQ,WAEX;IAED,IAAI,GAAG,WAEN;IAED,IAAI,YAAY;;;;;;;;;;;;;;MAEf;IAED,IAAI,OAAO,cAEV;IAED,IAAI,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEb;gBAqGW,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAQ;IAgBzC,aAAa,IAAI,IAAI,GAAG,SAAS;IAqGjC,aAAa,IAAI,OAAO;IAIxB,QAAQ,IAAI,gBAAgB;IAmE5B,SAAS,IAAI,MAAM,GAAG,SAAS;IAgE/B,WAAW,IAAI,gBAAgB;IAa/B,aAAa,IAAI,qBAAqB,GAAG,SAAS;IAmFlD;;;OAGG;IACH,OAAO,CACN,MAAM,GAAE,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAuB,GAC3D,MAAM,GAAG,SAAS;IAgFrB,YAAY,IAAI,MAAM,GAAG,SAAS;IAMlC,cAAc,CAAC,YAAY,GAAE,OAAc,GAAG,MAAM,GAAG,SAAS;IAWhE,eAAe,CACd,aAAa,GAAE,UAAU,EAAY,GACnC,mBAAmB,EAAE,GAAG,SAAS;CAwEpC"}
|
package/dist/epub.js
CHANGED
|
@@ -108,6 +108,15 @@ export class EpubFile {
|
|
|
108
108
|
this.#packageOpf = this.#getPackageOpf();
|
|
109
109
|
}
|
|
110
110
|
getCoverImage() {
|
|
111
|
+
const coverImage = this.#getCoverImageEntry();
|
|
112
|
+
if (typeof coverImage === "undefined") {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
return new File([Buffer.from(coverImage.entry.getData())], coverImage.filename, {
|
|
116
|
+
type: coverImage.type,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
#getCoverImageEntry() {
|
|
111
120
|
function epub2get(t) {
|
|
112
121
|
const p = t.#packageOpf;
|
|
113
122
|
const metaCover = [
|
|
@@ -127,9 +136,11 @@ export class EpubFile {
|
|
|
127
136
|
if (entry === null) {
|
|
128
137
|
throw new Error(`Could not find "${coverImagePath}" in epub "${t.#filePath}"`);
|
|
129
138
|
}
|
|
130
|
-
return
|
|
139
|
+
return {
|
|
140
|
+
entry,
|
|
131
141
|
type: manifestItem["@_media-type"],
|
|
132
|
-
|
|
142
|
+
filename: basename(coverImagePath),
|
|
143
|
+
};
|
|
133
144
|
}
|
|
134
145
|
if (this.#version === "3") {
|
|
135
146
|
const coverImageItem = this.#packageOpf.package.manifest.item.find((e) => (e["@_properties"] ?? []).includes("cover-image"));
|
|
@@ -142,14 +153,19 @@ export class EpubFile {
|
|
|
142
153
|
if (entry === null) {
|
|
143
154
|
throw new Error(`Could not find "${coverImagePath}" in epub "${this.#filePath}"`);
|
|
144
155
|
}
|
|
145
|
-
return
|
|
156
|
+
return {
|
|
157
|
+
entry,
|
|
146
158
|
type: coverImageItem["@_media-type"],
|
|
147
|
-
|
|
159
|
+
filename: basename(coverImagePath),
|
|
160
|
+
};
|
|
148
161
|
}
|
|
149
162
|
else {
|
|
150
163
|
return epub2get(this);
|
|
151
164
|
}
|
|
152
165
|
}
|
|
166
|
+
hasCoverImage() {
|
|
167
|
+
return typeof this.#getCoverImageEntry() !== "undefined";
|
|
168
|
+
}
|
|
153
169
|
getTitle() {
|
|
154
170
|
const t = this.#packageOpf.package.metadata["dc:title"]?.[0];
|
|
155
171
|
if (!t) {
|
|
@@ -282,6 +298,10 @@ export class EpubFile {
|
|
|
282
298
|
}
|
|
283
299
|
return calibreGet(this);
|
|
284
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
*
|
|
303
|
+
* @returns {string} ISO partial date (possible formats: `2010-01-12`, `2010-01`, `2010`)
|
|
304
|
+
*/
|
|
285
305
|
getDate(config = { stripTime: true }) {
|
|
286
306
|
const dublinCodeDate = this.#packageOpf.package.metadata?.["dc:date"];
|
|
287
307
|
if (!dublinCodeDate) {
|
|
@@ -310,6 +330,40 @@ export class EpubFile {
|
|
|
310
330
|
.substring(0, 10);
|
|
311
331
|
}
|
|
312
332
|
}
|
|
333
|
+
else if (dublinCodeDate["#text"].length > 4 &&
|
|
334
|
+
dublinCodeDate["#text"].length < 10) {
|
|
335
|
+
const splitDcDate = dublinCodeDate["#text"].split("-");
|
|
336
|
+
let temporalPlainDate = undefined;
|
|
337
|
+
try {
|
|
338
|
+
temporalPlainDate = new Temporal.PlainDate(Number(splitDcDate[0]), Number(splitDcDate[1] ?? 1), 1);
|
|
339
|
+
}
|
|
340
|
+
catch (e) {
|
|
341
|
+
if (this.#dev) {
|
|
342
|
+
console.error(splitDcDate, e);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (temporalPlainDate) {
|
|
346
|
+
return temporalPlainDate
|
|
347
|
+
.toString({ calendarName: "never" })
|
|
348
|
+
.substring(0, 7);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else if (dublinCodeDate["#text"].length <= 4) {
|
|
352
|
+
let temporalPlainDate = undefined;
|
|
353
|
+
try {
|
|
354
|
+
temporalPlainDate = new Temporal.PlainDate(Number(dublinCodeDate["#text"]), 1, 1);
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
if (this.#dev) {
|
|
358
|
+
console.error({ year: dublinCodeDate["#text"] }, e);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (temporalPlainDate) {
|
|
362
|
+
return temporalPlainDate
|
|
363
|
+
.toString({ calendarName: "never" })
|
|
364
|
+
.substring(0, 4);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
313
367
|
return z.iso.date().safeParse(dublinCodeDate["#text"])?.data;
|
|
314
368
|
}
|
|
315
369
|
getPublisher() {
|
|
@@ -33,7 +33,7 @@ export declare const DublinCoreIdentifier: z.ZodObject<{
|
|
|
33
33
|
}, z.z.core.$strip>;
|
|
34
34
|
export type DublinCoreIdentifier = z.infer<typeof DublinCoreIdentifier>;
|
|
35
35
|
export declare const DublinCoreDate: z.ZodObject<{
|
|
36
|
-
"#text": z.ZodUnion<readonly [z.z.ZodISODate, z.z.ZodISODateTime]>;
|
|
36
|
+
"#text": z.ZodUnion<readonly [z.z.ZodISODate, z.z.ZodISODateTime, z.ZodString]>;
|
|
37
37
|
}, z.z.core.$strip>;
|
|
38
38
|
export type DublinCoreDate = z.infer<typeof DublinCoreDate>;
|
|
39
39
|
export declare const DublinCoreDescription: z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dublinCore.d.ts","sourceRoot":"","sources":["../../../src/schemas/epub/dublinCore.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAKpB,eAAO,MAAM,oBAAoB;;;;;;;;;mBAQhC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,eAAO,MAAM,kBAAkB;;;mBAM9B,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe;;;;;;;;;mBAG3B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,eAAO,MAAM,oBAAoB;;;;mBAOhC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,eAAO,MAAM,c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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAOjC,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -27,6 +27,9 @@ export const DublinCoreDate = z.object({
|
|
|
27
27
|
offset: true,
|
|
28
28
|
error: (e) => `Not a valid iso datetime ("${String(e?.input)}")`,
|
|
29
29
|
}),
|
|
30
|
+
z.string().regex(/^\d{4}(-\d{2})?$/, {
|
|
31
|
+
error: (e) => `Not a valid partial iso date ("${String(e?.input)}")`,
|
|
32
|
+
}),
|
|
30
33
|
]),
|
|
31
34
|
}, "Not a valid dc:date");
|
|
32
35
|
export const DublinCoreDescription = z.object({ ...DublinCoreCommonText.shape }, "Not a valid dc:description");
|
|
@@ -171,7 +171,7 @@ export declare const PackageMetadataCommonDublinCoreTerms: z.ZodObject<{
|
|
|
171
171
|
"@_id"?: string | undefined;
|
|
172
172
|
"@_opf:scheme"?: string | undefined;
|
|
173
173
|
}[]>>, z.ZodObject<{
|
|
174
|
-
"#text": z.ZodUnion<readonly [z.ZodISODate, z.ZodISODateTime]>;
|
|
174
|
+
"#text": z.ZodUnion<readonly [z.ZodISODate, z.ZodISODateTime, z.ZodString]>;
|
|
175
175
|
}, z.core.$strip>>>;
|
|
176
176
|
"dc:publisher": z.ZodOptional<z.ZodObject<{
|
|
177
177
|
"@_id": z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
@@ -248,7 +248,7 @@ export declare const Epub2PackageOPF: z.ZodObject<{
|
|
|
248
248
|
"@_id"?: string | undefined;
|
|
249
249
|
"@_opf:scheme"?: string | undefined;
|
|
250
250
|
}[]>>, z.ZodObject<{
|
|
251
|
-
"#text": z.ZodUnion<readonly [z.z.ZodISODate, z.z.ZodISODateTime]>;
|
|
251
|
+
"#text": z.ZodUnion<readonly [z.z.ZodISODate, z.z.ZodISODateTime, z.ZodString]>;
|
|
252
252
|
}, z.z.core.$strip>>>;
|
|
253
253
|
"dc:publisher": z.ZodOptional<z.ZodObject<{
|
|
254
254
|
"@_id": z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
@@ -380,7 +380,7 @@ export declare const Epub3PackageOPF: z.ZodObject<{
|
|
|
380
380
|
"@_id"?: string | undefined;
|
|
381
381
|
"@_opf:scheme"?: string | undefined;
|
|
382
382
|
}[]>>, z.ZodObject<{
|
|
383
|
-
"#text": z.ZodUnion<readonly [z.z.ZodISODate, z.z.ZodISODateTime]>;
|
|
383
|
+
"#text": z.ZodUnion<readonly [z.z.ZodISODate, z.z.ZodISODateTime, z.ZodString]>;
|
|
384
384
|
}, z.z.core.$strip>>>;
|
|
385
385
|
"dc:publisher": z.ZodOptional<z.ZodObject<{
|
|
386
386
|
"@_id": z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|