node-json-db
Advanced tools
Comparing version
@@ -72,2 +72,3 @@ (function () { | ||
create = create || false; | ||
dataPath = JsonUtils.removeTrailingSlash(dataPath); | ||
@@ -130,2 +131,3 @@ function recursiveProcessDataPath(data, index) { | ||
}; | ||
/** | ||
@@ -139,2 +141,4 @@ * Pushing data into the database | ||
override = override === undefined ? true : override; | ||
dataPath = JsonUtils.removeTrailingSlash(dataPath); | ||
var dbData = this._getParentData(dataPath, true); | ||
@@ -172,2 +176,3 @@ if (!dbData) { | ||
JsonDB.prototype.delete = function (dataPath) { | ||
dataPath = JsonUtils.removeTrailingSlash(dataPath); | ||
var dbData = this._getParentData(dataPath, true); | ||
@@ -174,0 +179,0 @@ if (!dbData) { |
@@ -50,7 +50,15 @@ (function () { | ||
}; | ||
function removeTrailingSlash(dataPath) { | ||
if(dataPath.length > 1 && endsWith(dataPath,"/")) { | ||
return dataPath.substring(0, dataPath.length - 1); | ||
} | ||
return dataPath; | ||
} | ||
exports = module.exports = { | ||
strEndWith: endsWith, | ||
mergeObject: merge, | ||
processArray: processArray | ||
processArray: processArray, | ||
removeTrailingSlash : removeTrailingSlash | ||
} | ||
})(); |
{ | ||
"name": "node-json-db", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Database using JSON file as storage for Node.JS", | ||
@@ -5,0 +5,0 @@ "main": "./JsonDB.js", |
@@ -50,3 +50,3 @@ [](http://travis-ci.org/Belphemur/node-json-db) [](https://coveralls.io/r/Belphemur/node-json-db?branch=master) | ||
//It also create automatically the hierarchy when pushing new data for a DataPath that doesn't exists | ||
db.push("/test2/my/test/",5); | ||
db.push("/test2/my/test",5); | ||
@@ -53,0 +53,0 @@ //You can also push directly objects |
@@ -107,2 +107,17 @@ var expect = require("expect.js"); | ||
}) | ||
it('should remove trailing Slash when pushing/getting data (/)', function () { | ||
var object = {test: {test: "test"}}; | ||
db.push("/testing/", object); | ||
expect(db.getData("/testing")).to.be(object); | ||
}) | ||
it('should remove trailing Slash when deleting data (/)', function () { | ||
db.delete("/testing/"); | ||
expect(function (args) { | ||
db.getData(args); | ||
}).withArgs("/testing/").to.throwException(function (e) { | ||
expect(e).to.be.a(DataError); | ||
}); | ||
}) | ||
it('should merge the data at datapath', function () { | ||
@@ -109,0 +124,0 @@ var object = ['test2']; |
38957
2.78%721
3.3%