Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binarymuse/toml-node
TOML parser for Node.js and the Browser. Parses TOML v0.4.0
https://github.com/binarymuse/toml-node
javascript nodejs toml toml-parser
Last synced: 29 days ago
JSON representation
TOML parser for Node.js and the Browser. Parses TOML v0.4.0
- Host: GitHub
- URL: https://github.com/binarymuse/toml-node
- Owner: BinaryMuse
- License: mit
- Created: 2013-02-24T04:18:21.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-01-14T19:44:41.000Z (almost 3 years ago)
- Last Synced: 2024-05-21T21:43:43.688Z (6 months ago)
- Topics: javascript, nodejs, toml, toml-parser
- Language: JavaScript
- Homepage: http://binarymuse.github.io/toml-node/
- Size: 354 KB
- Stars: 301
- Watchers: 6
- Forks: 30
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
TOML Parser for Node.js
=======================[![Build Status](https://travis-ci.org/BinaryMuse/toml-node.png?branch=master)](https://travis-ci.org/BinaryMuse/toml-node)
[![NPM](https://nodei.co/npm/toml.png?downloads=true)](https://nodei.co/npm/toml/)
If you haven't heard of TOML, well you're just missing out. [Go check it out now.](https://github.com/mojombo/toml) Back? Good.
TOML Spec Support
-----------------toml-node supports version 0.4.0 the TOML spec as specified by [mojombo/[email protected]](https://github.com/mojombo/toml/blob/master/versions/en/toml-v0.4.0.md)
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.
```javascript
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.
```javascript
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](https://npmjs.org/package/concat-stream):
```javascript
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](https://github.com/ForbesLindesay) for the suggestion.
### Requiring with Node.js
You can use the [toml-require package](https://github.com/BinaryMuse/toml-require) 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](http://pegjs.majda.cz/).
npm install
npm run build
npm testAny 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.jsLicense
-------toml-node is licensed under the MIT license agreement. See the LICENSE file for more information.