aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2021-10-19 20:24:35 +0100
committerMichael Williamson <mike@zwobble.org>2021-10-19 20:25:52 +0100
commit97af358fa3e8b992741be913a9e69ef7e04e57e1 (patch)
treed0bdb373eacd1084fbc31814329c00838799b54c
parentc97335e3f1011a327bb99748e705b3e63d9e41ff (diff)
Add TypeScript declarations
-rw-r--r--NEWS4
-rw-r--r--lib/index.d.ts78
2 files changed, 82 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 9c37dcc..b48ffea 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+# 1.4.19
+
+* Add TypeScript declarations.
+
# 1.4.18
* When extracting raw text, convert tab elements to tab characters.
diff --git a/lib/index.d.ts b/lib/index.d.ts
new file mode 100644
index 0000000..0950b54
--- /dev/null
+++ b/lib/index.d.ts
@@ -0,0 +1,78 @@
+interface Mammoth {
+ convertToHtml: (input: Input, options?: Options) => Promise<Result>;
+ extractRawText: (input: Input) => Promise<Result>;
+ embedStyleMap: (input: Input, styleMap: string) => Promise<{toBuffer: () => Buffer}>;
+ images: Images;
+}
+
+type Input = NodeJsInput | BrowserInput;
+
+type NodeJsInput = PathInput | BufferInput;
+
+interface PathInput {
+ path: string;
+}
+
+interface BufferInput {
+ buffer: Buffer;
+}
+
+type BrowserInput = ArrayBufferInput;
+
+interface ArrayBufferInput {
+ arrayBuffer: ArrayBuffer;
+}
+
+interface Options {
+ styleMap?: string | Array<string>;
+ includeEmbeddedStyleMap?: boolean;
+ includeDefaultStyleMap?: boolean;
+ convertImage?: ImageConverter;
+ ignoreEmptyParagraphs?: boolean;
+ idPrefix?: string;
+}
+
+interface ImageConverter {
+ __mammothBrand: "ImageConverter";
+}
+
+interface Image {
+ contentType: string;
+ read: ImageRead;
+}
+
+interface ImageRead {
+ (): Promise<Buffer>;
+ (encoding: string): Promise<string>;
+}
+
+interface ImageAttributes {
+ src: string;
+}
+
+interface Images {
+ dataUri: ImageConverter;
+ imgElement: (f: (image: Image) => Promise<ImageAttributes>) => ImageConverter;
+}
+
+interface Result {
+ value: string;
+ messages: Array<Message>;
+}
+
+type Message = Warning | Error;
+
+interface Warning {
+ type: "warning";
+ message: string;
+}
+
+interface Error {
+ type: "error";
+ message: string;
+ error: unknown;
+}
+
+declare const mammoth: Mammoth;
+
+export = mammoth;