-
Notifications
You must be signed in to change notification settings - Fork 2
/
wrapper.js
50 lines (45 loc) · 1.12 KB
/
wrapper.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
43
44
45
46
47
48
49
50
async function taxsim(input, opts) {
let out = ''
let em = await loadTAXSIM({
noInitialRun: true,
noFSInit: true,
...opts,
})
let data
if (typeof input === 'string') {
data = input
} else if (typeof input === 'object') {
let keys = [],
vals = []
for (const k in input) {
keys.push(k)
vals.push(input[k])
}
data = keys.join(',') + '\n' + vals.join(',') + '\n'
}
if (data !== undefined) {
let i = 0
function stdin() {
if (i < data.length) {
return data.charCodeAt(i++)
}
return null
}
function stdouterr(c) {
out += String.fromCharCode(c)
}
em.FS.init(stdin, stdouterr, stdouterr)
} else {
em.FS.init()
}
let exitCode = em.callMain()
//console.log('taxsim results', {exitCode, out})
if (exitCode !== undefined && exitCode != 0) throw out
return out
}
if (typeof exports === 'object' && typeof module === 'object') module.exports = taxsim
else if (typeof define === 'function' && define['amd'])
define([], function () {
return taxsim
})
else if (typeof exports === 'object') exports['taxsim'] = taxsim