TOML parser for Node.js (parses TOML spec v0.4.0)
If you haven't heard of TOML, well you're just missing out. Go check it out now. Back? Good.
toml-node supports version 0.4.0 the TOML spec as specified by firstname.lastname@example.org
toml-node is available via npm.
npm install toml
toml-node also works with browser module bundlers like Browserify and webpack.
Say you have some awesome TOML in a variable called
var toml = require'toml';var data = tomlparsesomeTomlString;consoledirdata;
toml.parse throws an exception in the case of a parsing error; such exceptions have a
column property on them to help identify the offending text.
trytomlparsesomeCrazyKnuckleHeadedTrblToml;catch econsole.error"Parsing error on line " + eline + ", column " + ecolumn +": " + emessage;
As of toml-node version 1.0, the streaming interface has been removed. Instead, use a module like concat-stream:
var toml = require'toml';var concat = require'concat-stream';var fs = require'fs';fscreateReadStream'tomlFile.toml' 'utf8'pipeconcatvar parsed = tomlparsedata;;
Thanks @ForbesLindesay for the suggestion.
You can use the toml-require package to
.toml files with Node.js
You can experiment with TOML online at http://binarymuse.github.io/toml-node/, which uses the latest version of this library.
toml-node uses the PEG.js parser generator.
npm install npm run build npm test
Any changes to
src/toml.peg requires a regeneration of the parser with
npm run build.
toml-node is tested on Travis CI and is tested against:
toml-node is licensed under the MIT license agreement. See the LICENSE file for more information.