@caliatys/object-helper
v1.0.9
Published
Manage your objects easily
Downloads
4
Readme
Object Helper
JavaScript helper for object management.
Demo with RunKit
Installation
npm install @caliatys/object-helper --save
Import
JavaScript
let ObjectHelper = require('@caliatys/object-helper').ObjectHelper;
TypeScript
import { ObjectHelper } from '@caliatys/object-helper';
Usage
MergeObjects
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
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
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
npm run test