Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
decircularize
Advanced tools
Remove circular dependencies. It also functions as a deep-copy, to ensure that the input is never mutated and that the output can be trusted, even if there are no issues with circular structures.
The default behavior replaces the dependencies with a string suitable for debugging.
import decircularize from 'decircularize'
var obj = {
a: 1,
b: { something: 2 }
}
obj.b.bad = obj
obj.b.alsoBad = obj.b
JSON.stringify(obj) // explodes
JSON.stringify(decircularize(obj), null, 2)
/* returns
{
a: 1,
b: {
something: 2,
bad: '[Circular to: <root>]',
alsoBad: '[Circular to: <root>.b]'
}
}
*/
This can easily be overridden for any custom need. For example, imagine a REST
API where each entity have an id
prop that uniquely identifies it:
import decircularize from 'decircularize'
var obj = {
id: '123',
b: {
id: 'abc',
entities: [ 2 ]
}
}
obj.b.entities.push(obj.b)
decircularize(obj, {
onCircular: (object, otherPath, offendingPath) => {
assert(object === obj.b)
// In this instance, otherPath equals [ '<root>', 'b' ]
// and offendingPath equals [ '<root>', 'b', 'entities', 1 ]
return { id: object.id }
}
})
/* returns
{
a: 1,
b: {
id: 'abc',
entities: [
2,
{ id: 'abc' }
]
}
}
*/
FAQs
Remove circular dependencies
We found that decircularize 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.