forked from iarna/rtf-to-html
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
42 lines (37 loc) · 865 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict'
const parse = require('rtf-parser')
const rtfToHTML = require('./rtf-to-html.js')
module.exports = asStream
module.exports.fromStream = fromStream
module.exports.fromString = fromString
function asStream (opts, cb) {
if (arguments.length === 1) {
cb = opts
opts = null
}
return parse(htmlifyresult(opts, cb))
}
function fromStream (stream, opts, cb) {
if (arguments.length === 2) {
cb = opts
opts = null
}
return parse.stream(stream, htmlifyresult(opts, cb))
}
function fromString (string, opts, cb) {
if (arguments.length === 2) {
cb = opts
opts = null
}
return parse.string(string, htmlifyresult(opts, cb))
}
function htmlifyresult (opts, cb) {
return (err, doc) => {
if (err) return cb(err)
try {
return cb(null, rtfToHTML(doc, opts))
} catch (ex) {
return cb(ex)
}
}
}