Comparing version 1.1.1 to 1.2.0
@@ -24,3 +24,3 @@ 'use strict'; | ||
if (keys.length > 1) { | ||
// Get the key without the fist word separated by a period | ||
// Get the key deselect the fist word separated by a period | ||
var newKey = key.replace(/^(\w|\di|_|$)*./g, ''); | ||
@@ -134,3 +134,3 @@ newOb[keys[0]] = getNestedObject(ob[keys[0]], newKey); | ||
}, | ||
with: function _with() { | ||
select: function select() { | ||
var keys = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
@@ -151,3 +151,3 @@ | ||
resp = resp.concat(ob(i).with(keys)); | ||
resp = resp.concat(ob(i).select(keys)); | ||
} | ||
@@ -205,3 +205,3 @@ } catch (err) { | ||
}, | ||
without: function without() { | ||
deselect: function deselect() { | ||
var keys = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
@@ -268,3 +268,3 @@ | ||
return this.with(keysToKeep); | ||
return this.select(keysToKeep); | ||
} | ||
@@ -271,0 +271,0 @@ }; |
{ | ||
"name": "objob", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A tool for controlling and manipulating javascript object fields and output.", | ||
@@ -5,0 +5,0 @@ "main": "lib/objob.js", |
@@ -18,3 +18,3 @@ 'use strict'; | ||
if(keys.length > 1) { | ||
// Get the key without the fist word separated by a period | ||
// Get the key deselect the fist word separated by a period | ||
let newKey = key.replace(/^(\w|\di|_|$)*./g, ''); | ||
@@ -85,3 +85,3 @@ newOb[keys[0]] = getNestedObject(ob[keys[0]], newKey); | ||
}, | ||
with: (keys = []) => { | ||
select: (keys = []) => { | ||
let resp; | ||
@@ -93,3 +93,3 @@ | ||
for(let i of subject){ | ||
resp = resp.concat(ob(i).with(keys)); | ||
resp = resp.concat(ob(i).select(keys)); | ||
} | ||
@@ -112,3 +112,3 @@ } else { | ||
}, | ||
without: function(keys = []){ | ||
deselect: function(keys = []){ | ||
let allKeys = this.keys(subject); | ||
@@ -131,3 +131,3 @@ let keysToKeep = []; | ||
return this.with(keysToKeep); | ||
return this.select(keysToKeep); | ||
}, | ||
@@ -134,0 +134,0 @@ }; |
36
tests.js
@@ -76,16 +76,16 @@ /* eslint max-nested-callbacks: 0*/ | ||
describe('with', () => { | ||
it('should return the object only with the given keys', (done) => { | ||
expect(ob(ob1).with(['name'])).to.deep.equal({name: ob1.name}); | ||
expect(ob(ob2).with(['name', 'age'])).to.deep.equal({name: ob2.name, age: ob2.age}); | ||
describe('select', () => { | ||
it('should return the object only select the given keys', (done) => { | ||
expect(ob(ob1).select(['name'])).to.deep.equal({name: ob1.name}); | ||
expect(ob(ob2).select(['name', 'age'])).to.deep.equal({name: ob2.name, age: ob2.age}); | ||
done(); | ||
}); | ||
it('should return the object only with the given keys using nested object', (done) => { | ||
expect(ob(ob3).with(['body.feet'])).to.deep.equal({body: {feet: ob3.body.feet}}); | ||
it('should return the object only select the given keys using nested object', (done) => { | ||
expect(ob(ob3).select(['body.feet'])).to.deep.equal({body: {feet: ob3.body.feet}}); | ||
done(); | ||
}); | ||
it('should return the array only with the given keys using nested object', (done) => { | ||
expect(ob([ob3, ob3]).with(['body.feet'])) | ||
it('should return the array only select the given keys using nested object', (done) => { | ||
expect(ob([ob3, ob3]).select(['body.feet'])) | ||
.to.deep.equal([{body: {feet: ob3.body.feet}}, {body: {feet: ob3.body.feet}}]); | ||
@@ -95,4 +95,4 @@ done(); | ||
it('should return an array of objects only with the given keys', (done) => { | ||
expect(ob(obArr1).with(['name'])).to.deep.equal([{name: ob1.name},{name: ob2.name}]); | ||
it('should return an array of objects only select the given keys', (done) => { | ||
expect(ob(obArr1).select(['name'])).to.deep.equal([{name: ob1.name},{name: ob2.name}]); | ||
done(); | ||
@@ -102,11 +102,11 @@ }); | ||
describe('without', () => { | ||
it('should return the object only without the given keys', (done) => { | ||
expect(ob(ob1).without(['name'])).to.deep.equal({age: ob1.age, weight: ob1.weight}); | ||
expect(ob(ob2).without(['name', 'age'])).to.deep.equal({weight: ob2.weight, feet: ob2.feet}); | ||
describe('deselect', () => { | ||
it('should return the object only deselect the given keys', (done) => { | ||
expect(ob(ob1).deselect(['name'])).to.deep.equal({age: ob1.age, weight: ob1.weight}); | ||
expect(ob(ob2).deselect(['name', 'age'])).to.deep.equal({weight: ob2.weight, feet: ob2.feet}); | ||
done(); | ||
}); | ||
it('should return an array of objects only without the given keys', (done) => { | ||
expect(ob(obArr1).without(['name', 'weight', 'feet'])) | ||
it('should return an array of objects only deselect the given keys', (done) => { | ||
expect(ob(obArr1).deselect(['name', 'weight', 'feet'])) | ||
.to.deep.equal([{age: ob1.age},{age: ob2.age}]); | ||
@@ -119,4 +119,4 @@ | ||
describe('Chaining', () => { | ||
it('should return many of an object after filtering with with', (done) => { | ||
expect(ob(ob(ob1).with(['name', 'age'])).many(3)) | ||
it('should return many of an object after filtering select select', (done) => { | ||
expect(ob(ob(ob1).select(['name', 'age'])).many(3)) | ||
.to.deep.equal([ | ||
@@ -123,0 +123,0 @@ {age: ob1.age, name: ob1.name}, |
14993