🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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

to
2.2.0

.jshintrc

@@ -0,1 +1,11 @@

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

@@ -2,0 +12,0 @@ ===================

74

lib/compiler.js
function compile(nodes) {
"use strict";
var assignedPaths = [];
var currentPath = '';
var currentPath = "";
var data = {};

@@ -15,9 +16,9 @@ var context = data;

switch (node.type) {
case 'Assign':
case "Assign":
assign(node);
break;
case 'ObjectPath':
case "ObjectPath":
setPath(node);
break;
case 'ArrayPath':
case "ArrayPath":
addTableArray(node);

@@ -44,15 +45,38 @@ break;

var fullPath = currentPath + '.' + key;
if (typeof context[key] !== 'undefined') {
var fullPath = currentPath + "." + key;
if (typeof context[key] !== "undefined") {
genError("Cannot redefine existing key '" + fullPath + "'.", line, column);
}
if (value.type == 'Array')
context[key] = reduceArrayWithTypeChecking(value.value);
else
context[key] = value.value;
context[key] = reduceValueNode(value);
if (assignedPaths.indexOf(fullPath) === -1) assignedPaths.push(fullPath);
if (assignedPaths.indexOf(fullPath) === -1) {
assignedPaths.push(fullPath);
}
}
function reduceValueNode(node) {
if (node.type === "Array") {
return reduceArrayWithTypeChecking(node.value);
} else if (node.type === "InlineTable") {
return reduceInlineTableNode(node.value);
} else {
return node.value;
}
}
function reduceInlineTableNode(values) {
var obj = {};
for (var i = 0; i < values.length; i++) {
var val = values[i];
if (val.value.type === "InlineTable") {
obj[val.key] = reduceInlineTableNode(val.value.value);
} else if (val.type === "InlineTableValue") {
obj[val.key] = reduceValueNode(val.value);
}
}
return obj;
}
function setPath(node) {

@@ -80,3 +104,5 @@ var path = node.value;

if (assignedPaths.indexOf(path) === -1) assignedPaths.push(path);
if (assignedPaths.indexOf(path) === -1) {
assignedPaths.push(path);
}
assignedPaths = assignedPaths.filter(function(p) {

@@ -104,3 +130,3 @@ return p.indexOf(path) !== 0;

var key;
var keys = path.split('.');
var keys = path.split(".");
var ctx = start;

@@ -110,4 +136,4 @@

key = keys[i];
if (typeof ctx[key] === 'undefined') {
if (i == keys.length - 1) {
if (typeof ctx[key] === "undefined") {
if (i === String(keys.length - 1)) {
ctx[key] = value;

@@ -120,4 +146,5 @@ } else {

ctx = ctx[key];
if (ctx instanceof Array && ctx.length && i < keys.length - 1)
if (ctx instanceof Array && ctx.length && i < keys.length - 1) {
ctx = ctx[ctx.length - 1];
}
}

@@ -136,3 +163,3 @@

} else {
if (node.type != firstType) {
if (node.type !== firstType) {
genError("Cannot add value of type " + node.type + " to array of type " +

@@ -145,16 +172,11 @@ firstType + ".", node.line, node.column);

// Recursively reduce array of nodes into array of the nodes' values
return array.map(function(elem) {
if (elem.type == 'Array') {
return reduceArrayWithTypeChecking(elem.value);
} else {
return elem.value;
}
});
return array.map(reduceValueNode);
}
function checkPath(path, line, column) {
if (path[0] === '.')
if (path[0] === ".") {
genError("Cannot start a table key with '.'.", line, column);
else if (path[path.length - 1] === '.')
} else if (path[path.length - 1] === ".") {
genError("Cannot end a table key with '.'.", line, column);
}
}

@@ -161,0 +183,0 @@ }

{
"name": "toml",
"version": "2.1.1",
"description": "TOML parser for Node.js (parses TOML spec v0.3.1)",
"version": "2.2.0",
"description": "TOML parser for Node.js (parses TOML spec v0.4.0)",
"main": "index.js",
"scripts": {
"build": "pegjs --cache src/toml.peg lib/parser.js",
"test": "jshint lib/compiler.js && nodeunit test/test_*.js"

@@ -18,5 +19,5 @@ },

"jshint": "*",
"nodeunit": "~0.8.6",
"nodeunit": "~0.9.0",
"pegjs": "~0.8.0"
}
}

@@ -13,3 +13,3 @@ TOML Parser for Node.js

toml-node supports version 0.3.1 the TOML spec as specified by [mojombo/toml@v0.3.1](https://github.com/mojombo/toml/blob/master/versions/toml-v0.3.1.md)
toml-node supports version 0.4.0 the TOML spec as specified by [mojombo/toml@v0.4.0](https://github.com/mojombo/toml/blob/master/versions/en/toml-v0.4.0.md)

@@ -86,3 +86,4 @@ Installation

* Node 0.10
* Node 0.11
* Node 0.12
* Latest stable io.js

@@ -89,0 +90,0 @@ License

@@ -241,3 +241,3 @@ var toml = require('../');

exports.testIntegerFormats = function(test) {
var str = "a = +99\nb = 42\nc = 0\nd = -17";
var str = "a = +99\nb = 42\nc = 0\nd = -17\ne = 1_000_001\nf = 1_2_3_4_5 # why u do dis";
test.deepEqual(toml.parse(str), {

@@ -247,3 +247,5 @@ a: 99,

c: 0,
d: -17
d: -17,
e: 1000001,
f: 12345
});

@@ -256,3 +258,5 @@ test.done();

"d = 5e+22\ne = 1e6\nf = -2E-2\n" +
"g = 6.626e-34";
"g = 6.626e-34\n" +
"h = 9_224_617.445_991_228_313\n" +
"i = 1e1_000";
test.deepEqual(toml.parse(str), {

@@ -265,3 +269,5 @@ a: 1.0,

f: -2e-2,
g: 6.626e-34
g: 6.626e-34,
h: 9224617.445991228313,
i: 1e1000
});

@@ -297,2 +303,42 @@ test.done();

exports.testInlineTables = function(test) {
var str = fs.readFileSync(__dirname + "/inline_tables.toml", 'utf8'),
parsed = toml.parse(str);
test.deepEqual(parsed, {
name: {
first: "Tom",
last: "Preston-Werner"
},
point: {
x: 1,
y: 2
},
nested: {
x: {
a: {
b: 3
}
}
},
points: [
{ x: 1, y: 2, z: 3 },
{ x: 7, y: 8, z: 9 },
{ x: 2, y: 4, z: 8 }
],
arrays: [
{ x: [1, 2, 3], y: [4, 5, 6] },
{ x: [7, 8, 9], y: [0, 1, 2] }
]
});
test.done();
};
exports.testErrorOnBadUnicode = function(test) {
var str = "str = \"My name is Jos\\uD800\"";
test.throws(function() {
toml.parse(str);
});
test.done();
};
exports.testErrorOnDotAtStartOfKey = function(test) {

@@ -299,0 +345,0 @@ test.throws(function() {

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet