Skip to content
Open
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
14 changes: 12 additions & 2 deletions lib/getobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +42,11 @@ 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);
} else {
parts = parts.slice(0);
}

var prop = parts.pop();
obj = getobject.get(obj, parts, true);
Expand All @@ -51,7 +57,11 @@ 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);
} else {
parts = parts.slice(0);
}

var prop = parts.pop();
obj = getobject.get(obj, parts);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "getobject",
"description": "get.and.set.deep.objects.easily = true",
"version": "0.1.0",
"version": "0.1.2",
"homepage": "https://github.com/cowboy/node-getobject",
"author": {
"name": "\"Cowboy\" Ben Alman",
Expand Down