toml-stream-parser
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

toml-stream-parser

Build Status npm version

Streaming parser for TOML format. Requires Node v10.0.0 or above.

Usage

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
}

Parsing array of tables

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

/toml-stream-parser/

    Package Sidebar

    Install

    npm i toml-stream-parser

    Weekly Downloads

    8

    Version

    1.1.1

    License

    Apache-2.0

    Unpacked Size

    16.4 kB

    Total Files

    5

    Last publish

    Collaborators

    • anru