New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grille

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grille - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

3

lib/grille.js
'use strict';
var Spreadsheet = require('./spreadsheet.js');
var RedisGrilleStorage = require('./storage/redis.js');
var Grille = function(spreadsheet_id, storage, timeout) {
this.spreadsheet_id = spreadsheet_id;
this.storage = storage;
this.storage = storage || new RedisGrilleStorage();
this.timeout = timeout;

@@ -9,0 +10,0 @@ this.content = {};

@@ -122,18 +122,16 @@ 'use strict';

var destination = self.meta[collection].collection;
var path = self.meta[collection].collection;
if (type === 'hash') {
self.content[destination] = data;
Spreadsheet.dotSet(self.content, data, path);
} else if (type === 'keyvalue') {
var new_data = Spreadsheet.extractKeyValue(data);
if (!self.content[destination]) {
self.content[destination] = {};
if (!self.content[path]) {
self.content[path] = {};
}
// TODO: Break up object on .'s
_.extend(self.content[destination], new_data);
Spreadsheet.dotMerge(self.content, new_data, path);
} else if (type === 'array') {
// TODO: Break up object on .'s
self.content[destination] = Spreadsheet.extractArray(data);
Spreadsheet.dotSet(self.content, Spreadsheet.extractArray(data), path);
}

@@ -168,2 +166,51 @@

/**
* Sets data in a deep object using dot notation
*
* @param destination Object Tree where we want to put the source
* @param source Mixed What we want to stick in the destination object
* @param path String The location in the tree to put the source, such that x.y.z => destination.x.y.z = source
*/
Spreadsheet.dotSet = function(destination, source, path) {
var nodes = path.split("."); // e.g. x, y, z
var pointer = destination;
for (var i = 0; i < nodes.length - 1; i++) {
if (!pointer[nodes[i]]) {
pointer[nodes[i]] = {};
}
pointer = pointer[nodes[i]];
}
pointer[nodes[nodes.length-1]] = source;
return destination;
};
/**
* Merges data in a deep object using dot notation
*
* @param destination Object Tree where we want to merge the source
* @param source Mixed What we want to stick in the destination object
* @param path String The location in the tree to put the source, such that x.y.z => destination.x.y.z = source
*/
Spreadsheet.dotMerge = function(destination, source, path) {
var nodes = path.split("."); // e.g. x, y, z
var pointer = destination;
for (var i = 0; i < nodes.length; i++) {
if (!pointer[nodes[i]]) {
pointer[nodes[i]] = {};
}
pointer = pointer[nodes[i]];
}
_.extend(pointer, source);
return destination;
};
Spreadsheet.ValidationError = ValidationError;

@@ -170,0 +217,0 @@ Spreadsheet.TimeoutError = TimeoutError;

{
"name": "grille",
"version": "0.2.0",
"version": "0.3.0",
"description": "Simple CMS using Google Spreadsheets",

@@ -5,0 +5,0 @@ "main": "lib/grille.js",

@@ -73,2 +73,93 @@ 'use strict';

it("dotSet() simple", function() {
var destination = {};
var source = 'banana';
var path = 'x';
Spreadsheet.dotSet(destination, source, path);
assert.deepEqual(destination, {
x: 'banana'
});
});
it("dotSet()", function() {
var destination = {
x: {
b: 1
},
a: 2
};
var source = 'banana';
var path = 'x.y.z';
Spreadsheet.dotSet(destination, source, path);
assert.deepEqual(destination, {
x: {
b: 1,
y: {
z: 'banana'
}
},
a: 2
});
});
it("dotMerge() simple", function() {
var destination = {};
var source = {
a: 1,
b: 2
};
var path = 'x';
Spreadsheet.dotMerge(destination, source, path);
assert.deepEqual(destination, {
x: {
a: 1,
b: 2
}
});
});
it("dotMerge()", function() {
var destination = {
x: {
b: 1,
keyval: {
dog: 1,
cat: 2,
fish: 3
}
},
a: 2
};
var source = {
fish: 4,
frog: 5,
horse: 6
};
var path = 'x.keyval';
Spreadsheet.dotMerge(destination, source, path);
assert.deepEqual(destination, {
x: {
b: 1,
keyval: {
dog: 1,
cat: 2,
fish: 4,
frog: 5,
horse: 6
}
},
a: 2
});
});
describe("integration tests", function() {

@@ -91,6 +182,5 @@ this.timeout(10 * 1000);

// TODO: These should be split on .'s
assert.deepEqual(spreadsheet.get('levels.0'), data['levels.0']);
assert.deepEqual(spreadsheet.get('levels.1'), data['levels.1']);
assert.deepEqual(spreadsheet.get('levels.secret'), data['levels.secret']);
assert.deepEqual(spreadsheet.get('levels', 0), data.levels[0]);
assert.deepEqual(spreadsheet.get('levels', 1), data.levels[1]);
assert.deepEqual(spreadsheet.get('levels', 'secret'), data.levels.secret);

@@ -97,0 +187,0 @@ assert.deepEqual(spreadsheet.toJSON(), data);

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