![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
object-manage
Advanced tools
A library for managing javascript objects and offering common getter, setter, merge support.
A library for managing javascript objects and offering common getter, setter, merge support.
Works great for managing config objects and libraries that have options.
$ npm install object-manage
This helper is generally meant to be implemented into higher level API's. As such usage is simple.
ObjectManage is also an event emitter that allows the internal data object to be watched and augmented manually.
var ObjectManage = require('object-manage')
//construct
var obj = new ObjectManage({box: 'square'})
//watch data
var mydata = {}
obj.on('load',function(data){
mydata = data
})
//load in data
obj.load({foo: 'bar'})
//set a path
obj.set('bas.boo','foo1')
//get a path
obj.get('bas') //{boo: 'foo1'}
obj.get('bas.boo') //'foo1'
//access data directly
console.log(obj.data.bas.boo) //'foo1'
//check if a path exists
obj.exists('bas') //true
obj.exists('badkey') //false
//remove a path
obj.remove('bas')
obj.exists('bas') //false
It is also useful to use ObjectManage as a superconstructor for libraries with options.
Here is a quick example
var ObjectManage = require('object-manage')
, util = require('util')
var myObj = function(data){
ObjectManage.call(this,data)
}
util.inherits(myObj,ObjectManage)
myObj.prototype.foo = function(){
console.log(this.data) //this.data managed by ObjectManage
}
In order to make object-manage more performance friendly in smaller environments the merger can easily be switched between object-merge for merge-recursive. merge-recursive will only merge pointers and thus when the object-manage instance is modified the original objects will be as well. We choose object-merge as the default because it will decouple from the objects being merged in. This comes with a performance and memory cost.
To use merge-recursive
var ObjectManage = require('object-manage')
ObjectManage.prototype.merge = ObjectManage.prototype.mergeRecursive
It is also possible to implement one's own merging function.
var ObjectManage = require('object-manage')
ObjectManage.prototype.merge = function(obj1,obj2){
var mergedObject = obj2
return mergedObject
}
In order for object-manage to be useful in more hostile environments. It allows for validation functions to be defined per instance.
Quick example of a validation function for setting values
var obj = new ObjectManage()
obj.validateSet = function(path,value){
//your validation code here that calls one of the below functions
//erroneous method that still processes the action
this.warn('should have passed a boolean',value)
//erroneous methods that will halt processing of the action
this.drop('value must be boolean')
this.reject('value must be boolean')
//will throw an exception that must be caught in user space
this.error('something bad happened')
//non erroneous return methods
this.ok(value)
//or
return value
}
The following callbacks are available.
ObjectManage.validateGet
-- Validate get directivesObjectManage.validateSet
-- Validate set directivesObjectManage.validateExists
-- Validate exists directivesObjectManage.validateRemove
-- Validate remove directivesObjectManage.validateLoad
-- Validate load directivesThere are 5 verbs used to handle exceptions
The constructor sets up the object to be managed and accepts
the a single argument that gets passed to ObjectManage.load(data)
var data = {foo: 'foo'}
var inst = new ObjectManage(data)
NOTE If watching data via the load
event is desired data
should not be passed to the construct as it will be impossible to
listen for the load
event.
Load is used to merge an argument object into the main object.
var inst = new ObjectManage()
inst.load({mykey: 'mydata'})
inst.load({mykey2: 'mydata2'})
Load will also accept an array of objects that will be merged on top of each other in order.
var data1 = {test1: 'val1', test2: 'val2'}
, data2 = {test3: 'val3', test4: 'val4'}
, data3 = {test5: {test6: 'val6'}}
var inst = new ObjectManage()
inst.load([data1,data2,data3])
It can even be a recursive array
inst.load([data1,[data2,data3]])
Set will recursively set a path given by a string using dot notation.
var isnt = new ObjectManage()
inst.set('mykey','mydata') //{mykey: 'mydata'}
inst.set('mykey2.data','mydata') //{mykey: 'mydata', mykey2: {data: 'mydata'}}
Get will recursively set a path given by a string using dot notation.
var isnt = new ObjectManage({mykey: 'mydata', mykey2: {data: 'mydata'}})
inst.get('mykey') //'mydata'
inst.get('mykey2.data') //'mydata
Check if a path exists
NOTE This uses hasOwnProperty()
method of the object so is safe
to return an accurate value even when a path is set to undefined
var inst = new ObjectManage({mykey: 'myvalue'})
inst.exists('mykey') //true
inst.exists('mykey2') //false
Remove a path and all its children
This uses delete object[property]
and does not just set the property
to undefined
var inst = new ObjectManage({mykey: {mykey2: 'myvalue'}})
inst.exists('mykey.mykey2') //true
inst.remove('mykey') //true
inst.exists('mykey.mykey') //false
This will take a userspace object and count the depth of the object.
var inst = new ObjectManage()
var obj = {foo: {foo: {foo: 'baz'}}}
obj.countDepth(obj) //3
Fired when a set is processed on the managed object
var obj = new require('object-manage')()
obj.on('set',function(path,value,valid){
valid = valid ? 'valid' : 'invalid'
console.log('a ' + valid + ' value of (' + value + ') set to (' + path + ')')
})
obj.set('foo','bar')
Fired when a get is processed on the managed object
var obj = new require('object-manage')()
obj.on('get',function(path,value){
console.log(value + ' was retrieved from ' + path)
})
obj.get('foo')
Fired when an exists operation is performed
var obj = new require('object-manage')()
obj.on('exists',function(path,exists){
var does = exists ? 'does' : 'does not'
console.log('checked if ' + path + ' exists and it ' + does)
})
obj.exists('foo')
Fired when an remove operation is performed
var obj = new require('object-manage')()
obj.on('exists',function(path,removed){
var successfully = removed ? 'successfully' : 'unsuccessfully'
console.log(successfully + ' removed path (' + path + ')')
})
obj.remove('foo')
Fired when a load and merge is performed on the managed object
var obj = new require('object-manage')()
obj.on('load',function(data){
console.log('a merge was performed and the resulting data: ' + data)
})
obj.load({foo: 'bar'})
Fired when there is a validation drop
var obj = new require('object-manage')()
obj.on('drop',function(verb,message,path,value){
console.log('object-manage drop [' + verb + ':' + path + ']: ' + message)
})
obj.validateSet = function(path,value){
this.drop('not accepting anything')
}
obj.set('foo','will drop') //returns true
Fired when there is a validation reject
var obj = new require('object-manage')()
obj.on('reject',function(verb,message,path,value){
console.log('object-manage reject [' + verb + ':' + path + ']: ' + message)
})
obj.validateSet = function(path,value){
this.reject('not accepting anything')
}
obj.set('foo','will drop') //returns false
Fired when there is a set/get/merge warning.
var obj = new require('object-manage')()
obj.on('warn',function(verb,message,path,value){
console.log('object-manage warning [' + verb + ']: ' + message)
})
obj.load(overlyDeepObject)
Fired when there is a set/get/merge error.
var obj = new require('object-manage')()
obj.on('error',function(verb,message,path,value){
console.log('object-manage error [' + verb + ']: ' + message)
})
obj.load(overlyDeepObject)
Maximum call stack exceeded
Maximum call stack exceeded
errorObjectManage.maxDepth
propertyObjectManage.countDepth(object)
to check object depthvar obj = new ObjectManage(); var watched = obj.data
get()
now returns the entire objectObjectManage.data
is always an objectObjectManage.exists()
ObjectManage.remove()
MIT licensed see LICENSE.md
FAQs
A library for managing javascript objects and offering common getter, setter, merge support.
The npm package object-manage receives a total of 73 weekly downloads. As such, object-manage popularity was classified as not popular.
We found that object-manage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.