# object-collection

> Break objects into pieces and control them from those pieces.

Latest version **3.0.1** (published 2022-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install object-collection
pnpm add object-collection
yarn add object-collection
bun add object-collection
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2022-03-19 |
| First published | 2019-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 41.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | trapcodeio |
| Maintainers | trapcode |
| Keywords | object-collection, object, collection, lodash-collection |

## Links

- npm: https://www.npmjs.com/package/object-collection
- Repository: https://github.com/trapcodeio/object-collection
- Homepage: https://github.com/trapcodeio/object-collection#readme
- Issues: https://github.com/trapcodeio/object-collection/issues
- npm.io page: https://npm.io/package/object-collection

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.178

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2022-03-19
- 4.1.5 (next) — 2022-12-16
- 2.2.0 (old) — 2022-01-08
- 4.1.4 — 2022-12-16
- 4.1.3 — 2022-06-25
- 4.1.2 — 2022-06-25
- 4.1.1 — 2022-06-25
- 4.1.0 — 2022-06-25
- 4.0.12 — 2022-06-11
- 4.0.11 — 2022-06-11
- 4.0.10 — 2022-06-11
- 4.0.9 — 2022-06-11
- 4.0.8 — 2022-06-11
- 4.0.7 — 2022-06-11
- 4.0.5 — 2022-06-11
- … 46 more at https://npm.io/package/object-collection/versions

## README

# Javascript object collection.

[**NPM**](https://www.npmjs.com/package/object-collection) |
[**YARN**](https://yarnpkg.com/en/package/object-collection)

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

```javascript
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

```javascript
// 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

---
_Source: https://npm.io/package/object-collection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
