Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

toml

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toml - npm Package Compare versions

Comparing version 0.4.1 to 1.0.0

generate.sh

50

index.js

@@ -7,53 +7,3 @@ var Stream = require('stream');

return toml.parse(input.toString());
},
createStream: function() {
var stream = new Stream();
var buffers = [];
var bufLen = 0;
stream.readable = true;
stream.writable = true;
var parse = function() {
try {
var str = "";
if (Buffer.concat) {
str = Buffer.concat(buffers, bufLen);
} else { // Node 0.6
for(var i = 0; i < buffers.length; i++) {
console.log(buffers[i].toString())
str += buffers[i].toString();
}
}
var results = toml.parse(str.toString());
stream.emit('data', results);
} catch(e) {
stream.emit('error', e);
stream.destroy();
}
};
stream.write = function(buffer) {
buffers.push(buffer);
bufLen += buffer.length;
};
stream.end = function(buffer) {
if (buffer) stream.write(buffer);
this.writable = false;
parse();
stream.emit('end');
stream.emit('close');
stream.readable = false;
stream.writable = false;
};
stream.destroy = stream.destroySoon = function() {
stream.emit('end');
stream.emit('close');
stream.readable = false;
stream.writable = false;
};
return stream;
}
};
{
"name": "toml",
"version": "0.4.1",
"version": "1.0.0",
"description": "TOML parser for Node.js",

@@ -17,4 +17,5 @@ "main": "index.js",

"devDependencies": {
"nodeunit": "~0.7.4"
"nodeunit": "~0.7.4",
"pegjs": "~0.7.0"
}
}

@@ -22,37 +22,46 @@ TOML Parser for Node.js

var toml = require('toml');
var data = toml.parse(someTomlString);
console.dir(data);
```javascript
var toml = require('toml');
var data = toml.parse(someTomlString);
console.dir(data);
```
### Streaming
You can pipe a stream of TOML text into toml-node and it will emit a single `data` event with the parsed results once the stream is complete.
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):
var toml = require('toml');
var fs = require('fs');
fs.createReadStream('tomlFile.toml').pipe(toml.createStream()).on('data', function(results) {
// `results` is your parsed TOML
});
```javascript
var toml = require('toml');
var concat = require('concat-stream');
var fs = require('fs');
The stream will emit an `error` event in the case of an error while parsing the TOML document.
fs.createReadStream('tomlFile.toml', 'utf8').pipe(concat(function(data) {
var parsed = toml.parse(data);
}));
```
Thanks [@ForbesLindesay](https://github.com/ForbesLindesay) for the suggestion.
TOML Spec Support
-----------------
toml-node supports the TOML spec as specified by [mojombo/toml@4a6ed394](https://github.com/mojombo/toml/tree/4a6ed3944183e2a0307ad6022b7daf53fb9e7eb0)
toml-node supports the TOML spec as specified by [mojombo/toml@v0.1.0](https://github.com/mojombo/toml/tree/v0.1.0)
Building & Tests
----------------
Building & Testing
------------------
toml-node uses the Jison parser generator.
toml-node uses [the PEG.js parser generator](http://pegjs.majda.cz/).
npm install -g jison
jison src/toml.jison -o lib/toml.js
npm install
./generate.sh
npm test
toml-node runs on Travis CI and is tested against:
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.6
* Node 0.8
* Node 0.9
* Node 0.10
* Node 0.11

@@ -59,0 +68,0 @@ License

30

test/smoke.js

@@ -1,14 +0,22 @@

var toml = require('../');
var fs = require('fs');
var parser = require('../lib/toml');
var str = fs.readFileSync(__dirname + '/example.toml', 'utf-8');
var result = toml.parse(str);
var codes = [
"# test\n my.key=\"value\"\nother = 101\nthird = -37",
"first = 1.2\nsecond = -56.02\nth = true\nfth = false",
"time = 1979-05-27T07:32:00Z",
"test = [\"one\", ]",
"test = [[1, 2,], [true, false,],]",
"[my.sub.path]\nkey = true\nother = -15.3\n[my.sub]\nkey=false",
"arry = [\"one\", \"two\",\"thr\nee\", \"\\u03EA\"]",
fs.readFileSync(__dirname + '/example.toml', 'utf8'),
fs.readFileSync(__dirname + '/hard_example.toml', 'utf8')
]
console.log("Object result of toml.parse:");
console.dir(result);
console.log("\nOutput of result.owner.bio:");
console.log(result.owner.bio);
console.log("\nInspecting clients.data:");
console.dir(result.clients.data);
console.log("=============================================");
for(i in codes) {
var code = codes[i];
console.log(code + "\n");
console.log(JSON.stringify(parser.parse(code)));
console.log("=============================================");
}

@@ -36,10 +36,37 @@ var toml = require('../');

var hardExampleExpected = {
the: {
hard: {
another_test_string: ' Same thing, but with a string #',
'bit#': {
multi_line_array: [']'],
'what?': "You don't think some user won't do that?"
},
harder_test_string: " And when \"'s are in the string, along with # \"",
test_array: ['] ', ' # '],
test_array2: ['Test #11 ]proved that', 'Experiment #9 was a success']
},
test_string: "You'll hate me after this - #"
}
};
var badInputs = [
'[error] if you didn\'t catch this, your parser is broken',
'string = "Anything other than tabs, spaces and newline after a keygroup or key value pair has ended should produce an error unless it is a comment" like this',
'array = [\n \"This might most likely happen in multiline arrays\",\n Like here,\n \"or here,\n and here\"\n ] End of array comment, forgot the #',
'number = 3.14 pi <--again forgot the #'
];
exports.testParsesExample = function(test) {
fs.readFile(__dirname + "/example.toml", 'utf-8', function(err, str) {
test.ifError(err);
test.deepEqual(toml.parse(str), exampleExpected);
test.done();
});
var str = fs.readFileSync(__dirname + "/example.toml", 'utf-8')
test.deepEqual(toml.parse(str), exampleExpected);
test.done();
};
exports.testParsesHardExample = function(test) {
var str = fs.readFileSync(__dirname + "/hard_example.toml", 'utf-8')
test.deepEqual(toml.parse(str), hardExampleExpected);
test.done();
};
exports.testSupportsTrailingCommasInArrays = function(test) {

@@ -53,29 +80,22 @@ var str = 'arr = [1, 2, 3,]';

exports.testStreamingInterface = function(test) {
var inStream = fs.createReadStream(__dirname + '/example.toml');
var outStream = inStream.pipe(toml.createStream());
var results = null;
var dataCount = 0;
outStream.on('data', function(parsed) {
results = parsed;
dataCount++;
});
outStream.on('end', function() {
test.deepEqual(exampleExpected, results);
test.equal(dataCount, 1);
test.done();
});
exports.textDefineOnSuperkey = function(test) {
var str = "[a.b]\nc = 1\n\n[a]\nd = 2";
var expected = {
a: {
b: {
c: 1
},
d: 2
}
};
test.deepEqual(toml.parse(str), expected);
test.done();
};
exports.testErrorsInStreamingInterface = function(test) {
var inStream = fs.createReadStream(__dirname + '/bad.toml');
var outStream = inStream.pipe(toml.createStream());
var results = null;
var dataCount = 0;
outStream.on('data', function() {
throw new Error("Unexpected error event");
exports.testErrorOnKeygroupOverride = function(test) {
test.throws(function() {
var str = "[a]\nb = 1\n\n[a]\nc = 2";
toml.parse(str);
});
outStream.on('error', function() {
test.done();
});
test.done()
};

@@ -85,3 +105,3 @@

test.throws(function() {
var str = '[server]\nnum = 1\n[server.num]\ndata = 2'
var str = "[a]\nb = 1\n[a.b]\nc = 2";
toml.parse(str);

@@ -92,2 +112,10 @@ });

exports.testErrorOnKeyReplace = function(test) {
test.throws(function() {
var str = "[a]\nb = 1\nb = 2";
toml.parse(str);
});
test.done()
};
exports.testErrorOnArrayMismatch = function(test) {

@@ -100,1 +128,13 @@ test.throws(function() {

};
exports.textErrorOnBadInputs = function(test) {
var count = 0;
for (i in badInputs) {
(function(num) {
test.throws(function() {
toml.parse(badInputs[num]);
});
})(i);
}
test.done();
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc