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

    1.0.0 • Public • Published


    Copyright Sergio Garcia

    A chevrotain based TOML v0.4.0 parser, written in typescript.


    var bombadil = require('@sgarciac/bombadil')
    var input = 'whatever = 1'
    var reader = new bombadil.TomlReader
    reader.result // -> {whatever: 1}


    If the input is not a valid TOML string, the reader will store null in its result property and it will keep the errors in its errors property. Errors can be either:

    Type mapping

    By default, the toml reader will map TOML values to javascript values as follows:

    • Integers -> Number
    • Float -> Number
    • String -> String
    • Boolean -> Boolean
    • Offset Date Time -> Date
    • Local Date Time -> Date (using UTC±00:00)
    • Local Date -> Date (using UTC±00:00 and time 00:00:00)
    • Local Time -> Date (using UTC±00:00 and date 0000-00-00)
    • Array -> Array
    • Table -> Object

    As you can see, there is some information loss. If you need the original typing information, you can pass a second parameter to readToml set to true:

    var bombadil = require('@sgarciac/bombadil')
    var input = 'names = ["sergio","arturo"]'
    var reader = new bombadil.TomlReader
    reader.readToml(input, true)
    reader.result // -> { names:[ TomlAtomicValue { type: 4, image: 'sergio', value: 'sergio' },TomlAtomicValue { type: 4, image: 'arturo', value: 'arturo' } ] }
    bombadil.TomlAtomicValueType[reader.result.names[0].type] // ->  'String'

    Notice that we also keep the original string representation of the value. This can be helpful for example to deal with big integers, which can not be handled by the javascript Number type.

    Known problems

    Chevrotain is known to rely on function names, which means that minification (such as performed by, for example, Uglify) can break bombadil. There are some solutions to this problem here

    Unless you are running the code inside the browser, and using minification, you probably don't need to worry about this.



    npm i @sgarciac/[email protected]





    Unpacked Size

    124 kB

    Total Files


    Last publish


    • sgarciac