@firecrawl/anydoc-wasm 0.1.5 → 0.1.6

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 CHANGED
@@ -34,6 +34,33 @@ The package is built with `wasm-pack --target web`: it loads with a plain `<scri
34
34
 
35
35
  Calls are synchronous: wasm runs single-threaded on the calling thread, so convert on a worker if the main thread must stay responsive.
36
36
 
37
+ ## Errors
38
+
39
+ A conversion throws only when no meaningful Markdown could come out of the bytes. The thrown value is an `Error` whose `code` names what went wrong:
40
+
41
+ ```js
42
+ try {
43
+ return toMarkdownBytes(bytes);
44
+ } catch (error) {
45
+ // No document comes out of these, so record the file and take the next one.
46
+ if (error.code === 'encrypted' || error.code === 'unsupported') {
47
+ unconverted.push({ name, reason: error.code });
48
+ return null;
49
+ }
50
+ throw error;
51
+ }
52
+ ```
53
+
54
+ | `code` | Meaning |
55
+ | --------------- | ------------------------------------------------------------------- |
56
+ | `unsupported` | Unknown format, or one that cannot be converted (an image-only PDF) |
57
+ | `malformed` | Structurally unusable: no meaningful content could be extracted |
58
+ | `encrypted` | Encrypted or password-protected |
59
+ | `resourceLimit` | Crossed a fixed safety limit (decompression, nesting, node count) |
60
+ | `missingPart` | A part required for any meaningful output is absent |
61
+
62
+ `error.message` carries the detail, naming the package part at fault where the format identifies one. TypeScript gets the union as `ConvertErrorCode`. The crate's `io` code has no counterpart here: there is no filesystem to read from.
63
+
37
64
  ## Building
38
65
 
39
66
  ```bash
package/anydoc_wasm.d.ts CHANGED
@@ -8,6 +8,24 @@
8
8
 
9
9
  export type Format = "doc" | "docx" | "odt" | "pdf" | "ppt" | "pptx" | "rtf" | "epub" | "xlsx" | "ods" | "odp" | "csv";
10
10
 
11
+ /**
12
+ * `code` on the `Error` a failed conversion throws. Conversion fails only
13
+ * when no meaningful Markdown could be produced; producer quirks are
14
+ * recovered or skipped instead. The crate's `io` code has no wasm
15
+ * counterpart: there is no filesystem to read from.
16
+ */
17
+ export type ConvertErrorCode =
18
+ /** Unknown format, or one that cannot be converted (an image-only PDF). */
19
+ | 'unsupported'
20
+ /** Structurally unusable: no meaningful content could be extracted. */
21
+ | 'malformed'
22
+ /** Encrypted or password-protected. */
23
+ | 'encrypted'
24
+ /** Crossed a fixed safety limit (decompression, nesting, node count). */
25
+ | 'resourceLimit'
26
+ /** A part required for any meaningful output is absent. */
27
+ | 'missingPart'
28
+
11
29
  export interface Document {
12
30
  blocks: Array<Block>
13
31
  /**
@@ -227,6 +245,8 @@ export function formatFromPath(path: string): Format | undefined;
227
245
  *
228
246
  * Unsupported for `pdf`: PDF conversion produces Markdown directly and has
229
247
  * no document-model form; use `toMarkdownBytes`.
248
+ *
249
+ * Throws an `Error` carrying a `ConvertErrorCode` on `code`.
230
250
  */
231
251
  export function toDocument(bytes: Uint8Array, format?: Format | null): Document;
232
252
 
@@ -234,6 +254,8 @@ export function toDocument(bytes: Uint8Array, format?: Format | null): Document;
234
254
  * Convert an in-memory document to Markdown. Without a format, it is
235
255
  * detected from the content, which signature-less formats (CSV) have to name
236
256
  * explicitly.
257
+ *
258
+ * Throws an `Error` carrying a `ConvertErrorCode` on `code`.
237
259
  */
238
260
  export function toMarkdownBytes(bytes: Uint8Array, format?: Format | null): string;
239
261
 
package/anydoc_wasm.js CHANGED
@@ -45,6 +45,8 @@ export function formatFromPath(path) {
45
45
  *
46
46
  * Unsupported for `pdf`: PDF conversion produces Markdown directly and has
47
47
  * no document-model form; use `toMarkdownBytes`.
48
+ *
49
+ * Throws an `Error` carrying a `ConvertErrorCode` on `code`.
48
50
  * @param {Uint8Array} bytes
49
51
  * @param {Format | null} [format]
50
52
  * @returns {Document}
@@ -71,6 +73,8 @@ export function toDocument(bytes, format) {
71
73
  * Convert an in-memory document to Markdown. Without a format, it is
72
74
  * detected from the content, which signature-less formats (CSV) have to name
73
75
  * explicitly.
76
+ *
77
+ * Throws an `Error` carrying a `ConvertErrorCode` on `code`.
74
78
  * @param {Uint8Array} bytes
75
79
  * @param {Format | null} [format]
76
80
  * @returns {string}
@@ -104,10 +108,6 @@ export function toMarkdownBytes(bytes, format) {
104
108
  function __wbg_get_imports() {
105
109
  const import0 = {
106
110
  __proto__: null,
107
- __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
108
- const ret = Error(getStringFromWasm0(arg0, arg1));
109
- return addHeapObject(ret);
110
- },
111
111
  __wbg_String_8564e559799eccda: function(arg0, arg1) {
112
112
  const ret = String(getObject(arg1));
113
113
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -129,6 +129,10 @@ function __wbg_get_imports() {
129
129
  const ret = new Array();
130
130
  return addHeapObject(ret);
131
131
  },
132
+ __wbg_new_b667d279fd5aa943: function(arg0, arg1) {
133
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
134
+ return addHeapObject(ret);
135
+ },
132
136
  __wbg_new_cd45aabdf6073e84: function(arg0) {
133
137
  const ret = new Uint8Array(getObject(arg0));
134
138
  return addHeapObject(ret);
@@ -140,6 +144,10 @@ function __wbg_get_imports() {
140
144
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
141
145
  getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
142
146
  },
147
+ __wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
148
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
149
+ return ret;
150
+ }, arguments); },
143
151
  __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
144
152
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
145
153
  },
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@firecrawl/anydoc-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly bindings for anydoc: convert documents (doc, docx, odt, rtf, epub, pdf, presentations, spreadsheets, csv) to GitHub-Flavored Markdown in the browser",
5
- "version": "0.1.5",
5
+ "version": "0.1.6",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",