Streaming parser for TOML format. Requires Node v10.0.0 or above.
import { parseToml } from 'toml-stream-parser'
The parser takes AsyncIterable (or ReadableStream such as it also implements this interface) as input and returns, also AsyncIterable consisting of TOML chunks separated by inline tables or an array of inline tables:
[person]
name = 'John'
age = 32
[place]
city = 'Novosibirsk'
district = 'Academgorodok'
Each inline table will be emitted separately:
const tomlStream = fs.createReadableStream('data.toml')
for await (const chunk of parseToml(tomlStream)) {
// first chunk will be person
// second chunk will be place
}
If you have some big array of data represented as array of toml tables you can emit direct values of each inline table:
[[people]]
name = 'Andrew'
age = 32
[[people]]
name = 'Alisa'
age = 2
[[people]]
name = 'Ekaterina'
age = 8
Parsing code:
interface Person {
name: string,
age: number,
}
for await (const person of parseToml<Person>(toml, { extractArray: 'people' })) {
console.log(person.name)
}
// -> Andrew
// -> Alisa
// -> Ekaterina