epublib 0.2.0 → 0.3.2
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 +4 -0
- package/dist/epub.d.ts.map +1 -1
- package/dist/epub.js +40 -1
- 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
|
@@ -264,6 +264,10 @@ export declare class EpubFile {
|
|
|
264
264
|
getISBN13(): ISBN13 | undefined;
|
|
265
265
|
getLanguage(): BCP47LanguageTag;
|
|
266
266
|
getCollection(): EpubFileGetCollection | undefined;
|
|
267
|
+
/**
|
|
268
|
+
*
|
|
269
|
+
* @returns {string} ISO partial date (possible formats: `2010-01-12`, `2010-01`, `2010`)
|
|
270
|
+
*/
|
|
267
271
|
getDate(config?: Partial<{
|
|
268
272
|
stripTime: boolean;
|
|
269
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,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,UAAU,qBAAqB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,mBAAmB;IAC5B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;;;;;;;;;MAEf;IAED,IAAI,OAAO,cAEV;IAED,IAAI,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEb;gBAqGW,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAQ;IAiBzC,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
|
@@ -98,7 +98,8 @@ export class EpubFile {
|
|
|
98
98
|
constructor(filePath, dev = false) {
|
|
99
99
|
this.#dev = dev;
|
|
100
100
|
const fp = normalize(resolve(filePath));
|
|
101
|
-
accessSync(fp, constants.R_OK | constants.W_OK);
|
|
101
|
+
// accessSync(fp, constants.R_OK | constants.W_OK);
|
|
102
|
+
accessSync(fp, constants.R_OK);
|
|
102
103
|
this.#filePath = fp;
|
|
103
104
|
this.#zip = new AdmZip(fp);
|
|
104
105
|
this.#containerXml = this.#getContainerXml();
|
|
@@ -298,6 +299,10 @@ export class EpubFile {
|
|
|
298
299
|
}
|
|
299
300
|
return calibreGet(this);
|
|
300
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
*
|
|
304
|
+
* @returns {string} ISO partial date (possible formats: `2010-01-12`, `2010-01`, `2010`)
|
|
305
|
+
*/
|
|
301
306
|
getDate(config = { stripTime: true }) {
|
|
302
307
|
const dublinCodeDate = this.#packageOpf.package.metadata?.["dc:date"];
|
|
303
308
|
if (!dublinCodeDate) {
|
|
@@ -326,6 +331,40 @@ export class EpubFile {
|
|
|
326
331
|
.substring(0, 10);
|
|
327
332
|
}
|
|
328
333
|
}
|
|
334
|
+
else if (dublinCodeDate["#text"].length > 4 &&
|
|
335
|
+
dublinCodeDate["#text"].length < 10) {
|
|
336
|
+
const splitDcDate = dublinCodeDate["#text"].split("-");
|
|
337
|
+
let temporalPlainDate = undefined;
|
|
338
|
+
try {
|
|
339
|
+
temporalPlainDate = new Temporal.PlainDate(Number(splitDcDate[0]), Number(splitDcDate[1] ?? 1), 1);
|
|
340
|
+
}
|
|
341
|
+
catch (e) {
|
|
342
|
+
if (this.#dev) {
|
|
343
|
+
console.error(splitDcDate, e);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (temporalPlainDate) {
|
|
347
|
+
return temporalPlainDate
|
|
348
|
+
.toString({ calendarName: "never" })
|
|
349
|
+
.substring(0, 7);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else if (dublinCodeDate["#text"].length <= 4) {
|
|
353
|
+
let temporalPlainDate = undefined;
|
|
354
|
+
try {
|
|
355
|
+
temporalPlainDate = new Temporal.PlainDate(Number(dublinCodeDate["#text"]), 1, 1);
|
|
356
|
+
}
|
|
357
|
+
catch (e) {
|
|
358
|
+
if (this.#dev) {
|
|
359
|
+
console.error({ year: dublinCodeDate["#text"] }, e);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (temporalPlainDate) {
|
|
363
|
+
return temporalPlainDate
|
|
364
|
+
.toString({ calendarName: "never" })
|
|
365
|
+
.substring(0, 4);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
329
368
|
return z.iso.date().safeParse(dublinCodeDate["#text"])?.data;
|
|
330
369
|
}
|
|
331
370
|
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,CAA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;AAEhE,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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>>>;
|