Detalhes do pacote

toml

BinaryMuse8.3mMIT3.0.0

TOML parser for Node.js (parses TOML spec v0.4.0)

toml, parser

readme (leia-me)

TOML Parser for Node.js

Build Status

NPM

If you haven't heard of TOML, well you're just missing out. Go check it out now. Back? Good.

TOML Spec Support

toml-node supports version 0.4.0 the TOML spec as specified by mojombo/toml@v0.4.0

Installation

toml-node is available via npm.

npm install toml

toml-node also works with browser module bundlers like Browserify and webpack.

Usage

Standalone

Say you have some awesome TOML in a variable called someTomlString. Maybe it came from the web; maybe it came from a file; wherever it came from, it came asynchronously! Let's turn that sucker into a JavaScript object.

var toml = require('toml');
var data = toml.parse(someTomlString);
console.dir(data);

toml.parse throws an exception in the case of a parsing error; such exceptions have a line and column property on them to help identify the offending text.

try {
  toml.parse(someCrazyKnuckleHeadedTrblToml);
} catch (e) {
  console.error("Parsing error on line " + e.line + ", column " + e.column +
    ": " + e.message);
}

Streaming

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');

fs.createReadStream('tomlFile.toml', 'utf8').pipe(concat(function(data) {
  var parsed = toml.parse(data);
}));

Thanks @ForbesLindesay for the suggestion.

Requiring with Node.js

You can use the toml-require package to require() your .toml files with Node.js

Live Demo

You can experiment with TOML online at http://binarymuse.github.io/toml-node/, which uses the latest version of this library.

Building & Testing

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:

  • Node 0.10
  • Node 0.12
  • Latest stable io.js

License

toml-node is licensed under the MIT license agreement. See the LICENSE file for more information.

changelog (log de mudanças)

2.3.0 - July 13 2015

  • Correctly handle quoted keys (#21)

2.2.3 - June 8 2015

  • Support empty inline tables (#24)
  • Do not allow implicit table definitions to replace value (#23)
  • Don't allow tables to replace inline tables (#25)

2.2.2 - April 3 2015

  • Correctly handle newlines at beginning of string (#22)

2.2.1 - March 17 2015

  • Parse dates generated by Date#toISOString() (#20)

2.2.0 - Feb 26 2015

  • Support TOML spec v0.4.0

2.1.0 - Jan 7 2015

  • Support TOML spec v0.3.1

2.0.6 - May 23 2014

Bug Fixes

  • Fix support for empty arrays with newlines (#13)

2.0.5 - May 5 2014

Bug Fixes

Development

  • Tests now run JSHint on lib/compiler.js

2.0.4 - Mar 9 2014

Bug Fixes

  • Fix failure on duplicate table name inside table array (#11)

2.0.2 - Feb 23 2014

Bug Fixes

  • Fix absence of errors when table path starts or ends with period

2.0.1 - Feb 23 2014

Bug Fixes

  • Fix incorrect messaging in array type errors
  • Fix missing error when overwriting key with table array

2.0.0 - Feb 23 2014

Features

Internals

  • Upgrade to PEG.js v0.8 and rewrite compiler; parser is now considerably faster (from ~7000ms to ~1000ms to parse example.toml 1000 times on Node.js v0.10)

1.0.4 - Aug 17 2013

Bug Fixes

  • Fix support for empty arrays

1.0.3 - Aug 17 2013

Bug Fixes

  • Fix typo in array type error message
  • Fix single-element arrays with no trailing commas

1.0.2 - Aug 17 2013

Bug Fixes

  • Fix errors on lines that contain only whitespace (#7)

1.0.1 - Aug 17 2013

Internals

  • Remove old code remaining from the remove streaming API

1.0.0 - Aug 17 2013

Initial stable release