Giter VIP home page Giter VIP logo

toml-node's Introduction

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.3.1 the TOML spec as specified by mojombo/[email protected]

Installation

toml-node is available via npm.

npm install toml

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
./generate.sh
npm test

Any changes to src/toml.peg requires a regeneration of the parser with ./generate.sh.

toml-node is tested on Travis CI and is tested against:

  • Node 0.10
  • Node 0.11

License

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

toml-node's People

Contributors

sebmck avatar forbeslindesay avatar

Stargazers

Angus H. avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.