-
Notifications
You must be signed in to change notification settings - Fork 2
/
xlsx.js
65 lines (57 loc) · 1.29 KB
/
xlsx.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sinkToDuplex from '@rdfjs/sink-to-duplex'
import CsvwXlsxParser from '@zazuko/rdf-parser-csvw-xlsx'
import tracer from './lib/tracer.js'
import { toDataset } from './lib/stream.js'
/**
* @typedef {{
* metadata: import('@rdfjs/types').DatasetCore
* timezone?: string
* }} Options
*/
/**
* @overload
* @param {Options} args
* @return {import('duplexify').Duplexify}
*/
/**
* @overload
* @param {import('@rdfjs/types').DatasetCore} metadata
* @return {import('duplexify').Duplexify}
*/
/**
* @this {import('barnard59-core').Context}
* @param {Options | import('@rdfjs/types').DatasetCore} args
*/
function parse(args) {
/**
* @type {import('rdf-js').DatasetCore}
*/
let metadata
let timezone = 'local'
if ('metadata' in args) {
metadata = args.metadata
if (typeof args.timezone !== 'undefined') {
timezone = args.timezone
}
} else {
metadata = args
}
return tracer.startActiveSpan('xlsx:parse', async span => {
try {
const dataset = await toDataset(this.env, metadata)
span.addEvent('metadata')
return sinkToDuplex(new CsvwXlsxParser({
factory: this.env,
metadata: dataset,
timezone,
}), {
readableObjectMode: true,
})
} finally {
span.end()
}
})
}
export {
parse,
}