Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update packages & add recursivity to delete #31

Merged
merged 3 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_js:
install:
- "npm install -g typescript"
- "npm install"
script: "npm run-script tests"
script: "npm run-script ci"
4 changes: 0 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

// consts

const ISTRAVIS = (0, process).env.TRAVIS || false;

const APP_FILES = [ path.join(__dirname, "lib", "**", "*.js") ];
const UNITTESTS_FILES = [ path.join(__dirname, "tests", "**", "*.js") ];

Expand Down Expand Up @@ -75,8 +73,6 @@

}));

gulp.task("tests", gulp.series(ISTRAVIS ? "coveralls" : "mocha"));

// watcher

gulp.task("watch", () => {
Expand Down
28 changes: 26 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,33 @@ module.exports = class NodeContainerPattern extends Map {
return this;
}

delete (key) {
super.delete(ensureKey(key));
delete (_key) {

const key = ensureKey(_key);

if (this.has(key)) {

if (-1 < key.indexOf(this._recursionSeparator)) {

const keys = key.split(this._recursionSeparator);
const lastKey = keys.pop();
const parentKey = keys.join(this._recursionSeparator);

const parent = this.get(parentKey);

delete parent[lastKey];

this.set(parentKey, parent);

}
else {
super.delete(key);
}

}

return this;

}

document (_key, documentation) {
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "node-containerpattern",
"version": "0.5.6",
"version": "0.5.7",
"description": "A 'Container pattern' object for a clean global use of data.",
"main": "lib/main.js",
"typings": "lib/index.d.ts",
"scripts": {
"tests": "gulp tests"
"ci": "gulp coveralls",
"precommit": "gulp eslint",
"prepush": "gulp mocha"
},
"pre-push": [
"tests"
Expand Down Expand Up @@ -34,14 +36,14 @@
},
"dependencies": {},
"devDependencies": {
"@types/node": "9.6.7",
"@types/node": "10.10.1",
"gulp": "4.0.0",
"gulp-coveralls": "0.1.4",
"gulp-eslint": "4.0.2",
"gulp-eslint": "5.0.0",
"gulp-istanbul": "1.1.3",
"gulp-mocha": "3.0.1",
"gulp-plumber": "1.2.0",
"pre-push": "0.1.1"
"husky": "0.14.3"
},
"homepage": "https://github.com/Psychopoulet/node-containerpattern#readme",
"engines": {
Expand Down
20 changes: 20 additions & 0 deletions tests/4_delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,31 @@

describe("delete", () => {

beforeEach(() => {
container.clear();
});

it("should check normal running", () => {

assert.strictEqual(container.set("test", "test").delete("test") instanceof Container, true, "normal running has invalid return");
assert.strictEqual(container.set("test", "test").delete("test").size, 0, "normal running has invalid return");

});

it("should check recursive running", () => {

container.set("test", {
"test": "test",
"test2": "test2"
});

assert.strictEqual(container.delete("test.test") instanceof Container, true, "recursive running has invalid return");
assert.strictEqual(container.delete("test.test").size, 1, "recursive running has invalid return");

assert.deepStrictEqual(container.get("test").size, {
"test2": "test2"
}, "recursive running has invalid return");

});

});