From 0faafd40f549ed1c31dacbc332f57fbcc6c9270f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Vidal?= Date: Fri, 21 Sep 2018 15:29:49 +0200 Subject: [PATCH 1/2] update packages --- .travis.yml | 2 +- gulpfile.js | 4 ---- package.json | 12 +++++++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 65b8b0a..6e68c85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ node_js: install: - "npm install -g typescript" - "npm install" -script: "npm run-script tests" +script: "npm run-script ci" diff --git a/gulpfile.js b/gulpfile.js index e2981c7..6fa32a7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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") ]; @@ -75,8 +73,6 @@ })); - gulp.task("tests", gulp.series(ISTRAVIS ? "coveralls" : "mocha")); - // watcher gulp.task("watch", () => { diff --git a/package.json b/package.json index 475f534..0b8cfa7 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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": { From cdee2bfa93bd712c3d6bc21396c5b1e417a42f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Vidal?= Date: Fri, 21 Sep 2018 15:34:03 +0200 Subject: [PATCH 2/2] add recursivity to delete --- lib/main.js | 28 ++++++++++++++++++++++++++-- tests/4_delete.js | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 64b8668..d5372b5 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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) { diff --git a/tests/4_delete.js b/tests/4_delete.js index d4ef372..7809afb 100644 --- a/tests/4_delete.js +++ b/tests/4_delete.js @@ -13,6 +13,10 @@ 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"); @@ -20,4 +24,20 @@ describe("delete", () => { }); + 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"); + + }); + });