From 4a0288560fb6c4d697c726405fc0642066e32094 Mon Sep 17 00:00:00 2001 From: Alexander Sorokin Date: Tue, 5 May 2015 14:16:33 -0700 Subject: [PATCH 1/3] Only call getParts on string paths --- lib/getobject.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/getobject.js b/lib/getobject.js index e4006fe..89f42df 100644 --- a/lib/getobject.js +++ b/lib/getobject.js @@ -40,7 +40,9 @@ getobject.get = function(obj, parts, create) { // Set a deeply-nested property in an object, creating intermediary objects // as we go. getobject.set = function(obj, parts, value) { - parts = getParts(parts); + if (typeof parts === 'string') { + parts = getParts(parts); + } var prop = parts.pop(); obj = getobject.get(obj, parts, true); @@ -51,7 +53,9 @@ getobject.set = function(obj, parts, value) { // Does a deeply-nested property exist in an object? getobject.exists = function(obj, parts) { - parts = getParts(parts); + if (typeof parts === 'string') { + parts = getParts(parts); + } var prop = parts.pop(); obj = getobject.get(obj, parts); From e42ce42db80f44a438f80d8ba95a41a80377e47f Mon Sep 17 00:00:00 2001 From: Alexander Sorokin Date: Tue, 5 May 2015 14:17:34 -0700 Subject: [PATCH 2/3] Bump up version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 364155f..687a491 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "getobject", "description": "get.and.set.deep.objects.easily = true", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/cowboy/node-getobject", "author": { "name": "\"Cowboy\" Ben Alman", From 4fc62d275c3dba4b40ea3ee47b6a61813aacf862 Mon Sep 17 00:00:00 2001 From: Alexander Sorokin Date: Tue, 5 May 2015 14:44:00 -0700 Subject: [PATCH 3/3] Don't alter the arguments --- lib/getobject.js | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/getobject.js b/lib/getobject.js index 89f42df..881f695 100644 --- a/lib/getobject.js +++ b/lib/getobject.js @@ -23,6 +23,8 @@ function getParts(str) { getobject.get = function(obj, parts, create) { if (typeof parts === 'string') { parts = getParts(parts); + } else { + parts = parts.slice(0); } var part; @@ -42,6 +44,8 @@ getobject.get = function(obj, parts, create) { getobject.set = function(obj, parts, value) { if (typeof parts === 'string') { parts = getParts(parts); + } else { + parts = parts.slice(0); } var prop = parts.pop(); @@ -55,6 +59,8 @@ getobject.set = function(obj, parts, value) { getobject.exists = function(obj, parts) { if (typeof parts === 'string') { parts = getParts(parts); + } else { + parts = parts.slice(0); } var prop = parts.pop(); diff --git a/package.json b/package.json index 687a491..58835c9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "getobject", "description": "get.and.set.deep.objects.easily = true", - "version": "0.1.1", + "version": "0.1.2", "homepage": "https://github.com/cowboy/node-getobject", "author": { "name": "\"Cowboy\" Ben Alman",