Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicolasroehm/objecthelper
JavaScript helper for object management
https://github.com/nicolasroehm/objecthelper
javascript typescript
Last synced: about 4 hours ago
JSON representation
JavaScript helper for object management
- Host: GitHub
- URL: https://github.com/nicolasroehm/objecthelper
- Owner: NicolasRoehm
- License: mit
- Created: 2018-05-23T15:19:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-24T14:57:52.000Z (over 6 years ago)
- Last Synced: 2024-11-12T11:39:49.760Z (4 days ago)
- Topics: javascript, typescript
- Language: JavaScript
- Homepage: https://runkit.com/bakudan/object-helper-js/
- Size: 60.5 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/Caliatys/ObjectHelper.svg?branch=master)](https://travis-ci.org/Caliatys/ObjectHelper)
[![Coverage Status](https://coveralls.io/repos/github/Caliatys/ObjectHelper/badge.svg?branch=master)](https://coveralls.io/github/Caliatys/ObjectHelper?branch=master)# Object Helper
> JavaScript helper for object management.## Installation
```sh
npm install @caliatys/object-helper --save
```## Import
### JavaScript
```javascript
let ObjectHelper = require('@caliatys/object-helper').ObjectHelper;
```### TypeScript
```typescript
import { ObjectHelper } from '@caliatys/object-helper';
```## Usage
### MergeObjects
```javascript
var defaultConfig = {
flipped: false,
isFixedToCamera: false,
healthBar: {
x: 0,
y: 0
}
};var customConfig = {
isFixedToCamera: true,
healthBar: {
y: 10
}
};let config = ObjectHelper.mergeObjects(defaultConfig, customConfig);
// {
// flipped: false,
// healthBar: { x: 0, y: 10 },
// isFixedToCamera: true
// }
```### FilterObjectsByKey
```javascript
let data = {
CURSOR_1_UP : { id: 'up', key: '1' },
CURSOR_1_DOWN : { id: 'down', key: '2' },
CURSOR_1_LEFT : { id: 'left', key: '3' },
CURSOR_1_RIGHT : { id: 'right', key: '4' },
TECH_2_BLOCK : { id: 'block', key: 'b' },
};let objects = ObjectHelper.filterObjectsByKey(data, 'CURSOR', ['UP', 'LEFT']);
// [
// { id: "down", key: "2" },
// { id: "right", key: "4" }
// ]
```### SearchTree
```javascript
var tree = [{
title: 'topNode',
children: [{
title: 'node1',
children: [{
title: 'randomValue1'
}, {
title: 'node2',
children: [{
title: 'randomValue2',
children: [{
title: 'node3',
children: [{
title: 'randomValue3'
}]
}]
}]
}]
}]
}];let nodes = ObjectHelper.searchTree(tree, 'children', 'title', 'randomValue2');
// {
// title: "randomValue2",
// children: [{
// title: "node3",
// children: [{
// title: 'randomValue3'
// }]
// }]
// }
```## Test
```sh
npm run test
```