3.0.1 • Published 2 years ago

object-collection v3.0.1

Weekly downloads
9
License
MIT
Repository
github
Last release
2 years ago

Javascript object collection.

NPM | YARN

Built from Lodash's object functions api.

so instead of _.extend(obj, data) you do data.extend({}).

All lodash helpers that mutates object returns this

When to use ObjectCollection.

ObjectCollection is best used when accessing large objects e.g Api data, Your config object e.t.c

Usage

const Obj = require("object-collection");

// Creates empty object
let data = new Obj();
// => {}

const User = {name: "John", age: 32, gender: "male"};

// Use already existing object.
const user = new Obj(User);
// => {name: "John", age: 32, gender: 'male'}

// OR Use is a static helper to create new collection instance
const user = Obj.use(User);
// => {name: "John", age: 32, gender: "male"}


user.has("name")
// => true

user.pick(['name', 'age']);
// => {name: "John", age: 32}


user.set({hobbies: ['code', 'eat', 'sleep']});
// => {name: "John", age: 32, gender: "male", hobbies: ['code', 'eat', 'sleep']}

You get the idea right? All object helpers in lodash are available on this

We also added a few more helpers. e.g

If a path in your object holds an object we can access it as a collection using .path helper

// Add contact_details to User
user.set('contact_details', {
    address: 'No 1 Astro World', 
    phone: '+123456789',
    country: 'US',
});

user.path("contact_details");
// Returns message value as a collection

user.get("contact_details.address");
//OR
user.path("contact_details").get('address');
// => No 1 Astro World

user.path("contact_details").pick(['phone', 'US'])
// => {phone: '+123456789', country: 'US'}

Full Docs coming soon

4.1.4

2 years ago

4.1.5

2 years ago

4.0.5

3 years ago

4.0.4

3 years ago

4.0.10

3 years ago

4.0.7

3 years ago

4.0.0

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.12

3 years ago

4.0.11

3 years ago

4.0.9

3 years ago

4.0.8

3 years ago

4.1.3

3 years ago

4.1.0

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

3.0.1

3 years ago

2.1.2

3 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.5

3 years ago

2.1.0

3 years ago

3.0.0

3 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.32

4 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.0.1

6 years ago