-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
browser.js
36 lines (31 loc) · 811 Bytes
/
browser.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
// todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
import {Readable} from 'node:stream'
const stationsData = require('./data.json')
const fullData = require('./full.json')
const arrayAsReadable = (arr) => {
const l = arr.length
let i = 0
return new Readable({
objectMode: true,
read: function (size) {
const maxI = Math.min(i + size, l - 1)
for (; i <= maxI; i++) {
this.push(arr[i])
}
if (i === (l - 1)) this.push(null) // end
},
})
}
const readStations = () => {
return arrayAsReadable(stationsData)
}
const readFullStations = () => {
return arrayAsReadable(fullData)
}
export {
readStations,
readFullStations,
}