@korzun/epubcheck-ts 0.1.0-beta.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/ATTRIBUTION.md ADDED
@@ -0,0 +1,26 @@
1
+ # Attribution
2
+
3
+ epubcheck-ts is a fresh, TypeScript-native EPUB validator inspired by
4
+ [w3c/epubcheck](https://github.com/w3c/epubcheck). It is not a port of
5
+ epubcheck's code.
6
+
7
+ ## Message catalog
8
+
9
+ The validation message identifiers (e.g. `OPF-014`, `RSC-005`, `NAV-010`) and
10
+ their English message templates are reused from epubcheck's
11
+ `MessageBundle.properties` so that results are compatible with existing
12
+ epubcheck-aware tooling. epubcheck is distributed under the BSD 3-Clause
13
+ License:
14
+
15
+ ```
16
+ Copyright (c) 2007, Adobe Systems Incorporated
17
+ Copyright (c) 2008, IDPF
18
+ Copyright (c) 2017, W3C
19
+ ```
20
+
21
+ ## Test fixtures
22
+
23
+ The fixtures under `test/fixtures/` are original works authored for this
24
+ project. They are *modeled on* the scenarios described in epubcheck's
25
+ Cucumber `.feature` test files (which document the expected message for each
26
+ case), but no epubcheck source or binary test files are redistributed here.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, epubcheck-ts contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its contributors
16
+ may be used to endorse or promote products derived from this software
17
+ without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # epubcheck-ts
2
+
3
+ A runtime-agnostic, TypeScript-native EPUB validator, distributed as a library.
4
+
5
+ epubcheck-ts validates EPUB 2 and EPUB 3 publications and reports problems
6
+ using the same message-id vocabulary as [w3c/epubcheck](https://github.com/w3c/epubcheck),
7
+ so results are compatible with existing epubcheck-aware tooling. It is a fresh,
8
+ functional implementation — not a port of epubcheck's code — with no Java
9
+ dependency and no Node-specific APIs, so it runs anywhere the Web Platform's
10
+ `Uint8Array` and `ReadableStream` are available (Node, Deno, Bun, browsers,
11
+ edge runtimes).
12
+
13
+ > **Not to be confused with [`@likecoin/epubcheck-ts`](https://www.npmjs.com/package/@likecoin/epubcheck-ts).**
14
+ > Despite the similar name, that is a separate, more mature project. See
15
+ > [How this compares](#how-this-compares-to-likecoinepubcheck-ts) below.
16
+
17
+ ## How this compares to `@likecoin/epubcheck-ts`
18
+
19
+ [`@likecoin/epubcheck-ts`](https://github.com/likecoin/epubcheck-ts) is an
20
+ established, near-complete TypeScript port of the official EPUBCheck. If you
21
+ need maximum conformance today, use it (or the official Java EPUBCheck). The two
22
+ projects make deliberately different trade-offs:
23
+
24
+ | | epubcheck-ts (this project) | `@likecoin/epubcheck-ts` |
25
+ | --- | --- | --- |
26
+ | Goal | A small, embeddable, dependency-light validator | Near-complete parity (~99%) with Java EPUBCheck |
27
+ | Maturity | Early-stage; a curated subset of checks | Mature; ~1300 tests, EPUB 2.0 & 3.0–3.3 |
28
+ | Validation approach | Hand-written checks against parsed structures | Ports EPUBCheck's RELAX NG / Schematron / XSD schemas |
29
+ | Schema engine | None | `libxml2-wasm` + `fontoxpath` + `slimdom` (XPath 3.1) |
30
+ | Runtime deps | 3 (`fflate`, `saxes`, `css-tree`) — no WASM | 6, including a WASM libxml2 build |
31
+ | Interface | Library only | Library **and** CLI (`npx`, profiles, JSON output) |
32
+ | API style | Functional & layered — compose the parse/check steps | Higher-level validator API |
33
+ | Footprint | Minimal | Larger (WASM payload) |
34
+
35
+ In short: reach for `@likecoin/epubcheck-ts` when you want the most complete,
36
+ schema-accurate validation or a ready-made CLI. Reach for this project when you
37
+ want a tiny, WASM-free, functionally composable library and are comfortable with
38
+ a smaller (but growing) set of checks. Both reuse epubcheck's message-id
39
+ vocabulary, so their output is broadly compatible.
40
+
41
+ ## Features
42
+
43
+ - **EPUB 2 and EPUB 3** — version is auto-detected from the package document.
44
+ - **Runtime-agnostic** — pure functions over byte buffers; no filesystem access.
45
+ - **Layered, functional API** — call the all-in-one `validateEpub`, or compose
46
+ the underlying parse/check functions yourself.
47
+ - **Dual ESM + CJS** — ships both `import` and `require` builds, each with its
48
+ own type declarations.
49
+ - **epubcheck-compatible messages** — message ids (`OPF-014`, `RSC-005`,
50
+ `NAV-010`, …) and English templates match epubcheck's catalog.
51
+ - **Few, lightweight runtime deps** — only `fflate` (zip), `saxes` (XML), and
52
+ `css-tree` (CSS).
53
+
54
+ ### Validation coverage
55
+
56
+ The current checks span the container, package document, navigation document,
57
+ content documents, and stylesheets:
58
+
59
+ | Area | Message ids |
60
+ | --- | --- |
61
+ | Package / container structure (OCF) | `PKG-*`, `RSC-001`–`RSC-003` |
62
+ | OPF manifest & spine semantics | `OPF-*`, `RSC-005`–`RSC-012` |
63
+ | Navigation document (EPUB 3) | `NAV-*` |
64
+ | CSS / style sheets | `CSS-*` |
65
+
66
+ ## Installation
67
+
68
+ ```sh
69
+ npm install @korzun/epubcheck-ts
70
+ ```
71
+
72
+ ## Usage
73
+
74
+ `validateEpub` accepts the raw bytes of an `.epub` file (a `Uint8Array`,
75
+ `ArrayBuffer`, or `ReadableStream<Uint8Array>`) and resolves to a `Report`.
76
+
77
+ ```ts
78
+ import { readFile } from 'node:fs/promises'
79
+ import { validateEpub } from '@korzun/epubcheck-ts'
80
+
81
+ const bytes = await readFile('book.epub')
82
+ const report = await validateEpub(bytes)
83
+
84
+ if (report.valid) {
85
+ console.log(`Valid EPUB ${report.epubVersion}`)
86
+ } else {
87
+ for (const m of report.messages) {
88
+ const where = m.location
89
+ ? `${m.location.path}${m.location.line ? `:${m.location.line}` : ''}`
90
+ : ''
91
+ console.log(`${m.severity} ${m.id} ${where} — ${m.message}`)
92
+ }
93
+ }
94
+ ```
95
+
96
+ The package is published as both ESM and CommonJS, so `require` works too:
97
+
98
+ ```js
99
+ const { validateEpub } = require('@korzun/epubcheck-ts')
100
+ ```
101
+
102
+ ### Options
103
+
104
+ ```ts
105
+ // Force validation against a specific version. If the detected version differs,
106
+ // a PKG-001 warning is reported.
107
+ await validateEpub(bytes, { version: '3.0' })
108
+ ```
109
+
110
+ ### The report
111
+
112
+ ```ts
113
+ interface Report {
114
+ messages: Message[]
115
+ epubVersion?: '2.0' | '3.0'
116
+ counts: Record<Severity, number> // FATAL | ERROR | WARNING | INFO | USAGE
117
+ fatal: boolean // any FATAL message present
118
+ valid: boolean // no FATAL and no ERROR messages
119
+ }
120
+
121
+ interface Message {
122
+ id: string // e.g. "OPF-014"
123
+ severity: Severity
124
+ message: string // formatted, human-readable
125
+ location?: { path: string; line?: number; column?: number }
126
+ suggestion?: string
127
+ }
128
+ ```
129
+
130
+ ### Composing the lower-level API
131
+
132
+ `validateEpub` is a thin orchestration over independently usable parse and
133
+ check functions. You can drive the pipeline yourself — open the container, then
134
+ parse and check each part:
135
+
136
+ ```ts
137
+ import {
138
+ openEpub,
139
+ validateOcf,
140
+ parseOpf,
141
+ validateOpf,
142
+ } from '@korzun/epubcheck-ts'
143
+
144
+ const container = await openEpub(bytes)
145
+ const ocfMessages = validateOcf(container)
146
+ const { pkg, messages } = parseOpf(container)
147
+ if (pkg) messages.push(...validateOpf(pkg, container))
148
+ ```
149
+
150
+ Every check function returns a plain `Message[]` and never throws, so they're
151
+ easy to combine, filter, or test in isolation.
152
+
153
+ ## Development
154
+
155
+ ```sh
156
+ npm install
157
+ npm test # run the vitest suite
158
+ npm run typecheck # tsc --noEmit
159
+ npm run lint # eslint
160
+ npm run build # bundle to dist/ via tsdown
161
+ ```
162
+
163
+ Unit tests are colocated with their source (`src/**/*.test.ts`); integration
164
+ tests and fixtures live under `test/`.
165
+
166
+ ## Releasing
167
+
168
+ Publishing is automated by
169
+ [`.github/workflows/release.yml`](./.github/workflows/release.yml) and triggered
170
+ by **publishing a GitHub Release**:
171
+
172
+ 1. Bump `version` in `package.json` and commit it to `main`.
173
+ 2. Create a GitHub Release whose tag matches that version, prefixed with `v`
174
+ (e.g. version `1.2.0` → tag `v1.2.0`). The workflow fails the publish if the
175
+ tag and `package.json` version disagree.
176
+ 3. Tick **"Set as a pre-release"** for beta/rc builds. Pre-releases publish
177
+ under the `next` dist-tag (`npm install @korzun/epubcheck-ts@next`); stable
178
+ releases publish under `latest`.
179
+
180
+ Authentication uses npm [Trusted Publishing](https://docs.npmjs.com/trusted-publishers)
181
+ (OIDC) — there is no `NPM_TOKEN` secret, and build provenance is attached
182
+ automatically. This requires a one-time setup on npmjs.com: configure this
183
+ repository and the `Release` workflow as a trusted publisher for the
184
+ `@korzun/epubcheck-ts` package.
185
+
186
+ ## License & attribution
187
+
188
+ epubcheck-ts is licensed under the [BSD 3-Clause License](./LICENSE).
189
+
190
+ It reuses epubcheck's message-id vocabulary and message templates — see
191
+ [ATTRIBUTION.md](./ATTRIBUTION.md) for details.