@likecoin/epubcheck-ts 0.2.0 → 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/README.md +44 -0
- package/bin/epubcheck.js +170 -0
- package/bin/epubcheck.ts +227 -0
- package/dist/index.cjs +21 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -1378,6 +1378,7 @@ var OCFValidator = class {
|
|
|
1378
1378
|
"metadata.xml"
|
|
1379
1379
|
]);
|
|
1380
1380
|
for (const file of metaInfFiles) {
|
|
1381
|
+
if (file === "META-INF/") continue;
|
|
1381
1382
|
const filename = file.replace("META-INF/", "");
|
|
1382
1383
|
if (!allowedFiles.has(filename)) {
|
|
1383
1384
|
messages.push({
|
|
@@ -1395,6 +1396,7 @@ var OCFValidator = class {
|
|
|
1395
1396
|
validateFilenames(zip, messages) {
|
|
1396
1397
|
for (const path of zip.paths) {
|
|
1397
1398
|
if (path === "mimetype") continue;
|
|
1399
|
+
if (path.endsWith("/")) continue;
|
|
1398
1400
|
const filename = path.includes("/") ? path.split("/").pop() ?? path : path;
|
|
1399
1401
|
if (filename === "" || filename === "." || filename === "..") {
|
|
1400
1402
|
messages.push({
|
|
@@ -2218,12 +2220,13 @@ var OPFValidator = class {
|
|
|
2218
2220
|
}
|
|
2219
2221
|
declaredPaths.add(opfPath);
|
|
2220
2222
|
for (const filePath of context.files.keys()) {
|
|
2223
|
+
if (filePath.endsWith("/")) continue;
|
|
2221
2224
|
if (filePath.startsWith("META-INF/")) continue;
|
|
2222
2225
|
if (filePath === "mimetype") continue;
|
|
2223
2226
|
if (declaredPaths.has(filePath)) continue;
|
|
2224
2227
|
context.messages.push({
|
|
2225
2228
|
id: "RSC-008",
|
|
2226
|
-
severity: "
|
|
2229
|
+
severity: "error",
|
|
2227
2230
|
message: `File in container is not declared in manifest: ${filePath}`,
|
|
2228
2231
|
location: { path: filePath }
|
|
2229
2232
|
});
|
|
@@ -3307,7 +3310,16 @@ var EpubCheck = class _EpubCheck {
|
|
|
3307
3310
|
});
|
|
3308
3311
|
}
|
|
3309
3312
|
const elapsedMs = performance.now() - startTime;
|
|
3310
|
-
|
|
3313
|
+
const filteredMessages = context.messages.filter((msg) => {
|
|
3314
|
+
if (!this.options.includeUsage && msg.severity === "usage") {
|
|
3315
|
+
return false;
|
|
3316
|
+
}
|
|
3317
|
+
if (!this.options.includeInfo && msg.severity === "info") {
|
|
3318
|
+
return false;
|
|
3319
|
+
}
|
|
3320
|
+
return true;
|
|
3321
|
+
});
|
|
3322
|
+
return buildReport(filteredMessages, context.version, elapsedMs);
|
|
3311
3323
|
}
|
|
3312
3324
|
/**
|
|
3313
3325
|
* Static method to validate an EPUB file with default options
|
|
@@ -3351,20 +3363,20 @@ var EpubCheck = class _EpubCheck {
|
|
|
3351
3363
|
const ncxContent = new TextDecoder().decode(ncxData);
|
|
3352
3364
|
const ncxValidator = new NCXValidator();
|
|
3353
3365
|
ncxValidator.validate(context, ncxContent, ncxPath);
|
|
3354
|
-
if (context.ncxUid) {
|
|
3355
|
-
const
|
|
3356
|
-
|
|
3366
|
+
if (context.ncxUid && context.packageDocument.uniqueIdentifier) {
|
|
3367
|
+
const uniqueIdRef = context.packageDocument.uniqueIdentifier;
|
|
3368
|
+
const matchingIdentifier = context.packageDocument.dcElements.find(
|
|
3369
|
+
(dc) => dc.name === "identifier" && dc.id === uniqueIdRef
|
|
3357
3370
|
);
|
|
3358
|
-
|
|
3359
|
-
const opfUid =
|
|
3371
|
+
if (matchingIdentifier) {
|
|
3372
|
+
const opfUid = matchingIdentifier.value.trim();
|
|
3360
3373
|
if (context.ncxUid !== opfUid) {
|
|
3361
3374
|
context.messages.push({
|
|
3362
3375
|
id: "NCX-001",
|
|
3363
|
-
severity: "
|
|
3376
|
+
severity: "error",
|
|
3364
3377
|
message: `NCX uid "${context.ncxUid}" does not match OPF unique identifier "${opfUid}"`,
|
|
3365
3378
|
location: { path: ncxPath }
|
|
3366
3379
|
});
|
|
3367
|
-
break;
|
|
3368
3380
|
}
|
|
3369
3381
|
}
|
|
3370
3382
|
}
|