
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
circular.js
Advanced tools
A small AMD, CommonJS, Global (window) compatible helper utility (usually called a replacer in JSON.stringify
) to remove circular references for stringifying an object.
Using circular.js is pretty simple & straightforward, it provides you with several options to keep or discard keys from the object you're stringifying too.
stringified = JSON.stringify(obj, circular()); //the most basic usage option without any options or refs
With basic parameters you can pass into circular, the helper looks something like..
circular([ref [, options]]);
ref
is the reference name you want to assign your circular references.
stringified = JSON.stringify(obj, circular("[circular]")) //overrides [circular Circular] to [circular]
ref
can also be a callback function
which takes a single value
parameter and processes the passed value even more..
stringified = JSON.stringify(obj, circular(function(v) {
return "some_string_" + v;
}))
Circular provides you with various options
to enable or disable few features, some of the most usable ones being able to keep or discard object's various keys
Options supported by circular include -
boolean
flag to specify whether you need to stringify values of type functions or discard them default: true
json
outputjson
outputYou have the flexibility to just pass in the options without overriding the default ref
stringified = JSON.stringify(obj, circular({ //without overriding ref
stringifyFunctions: false,
keep: ["Modernizr"]
}))
Or you can also override ref
and pass in the options as the 2nd parameter
stringified = JSON.stringify(obj, circular("[circular]", { //with an alternative reference name
stringifyFunctions: false,
keep: ["Modernizr"]
}))
Feel free to report any bugs, or pull requests which can extend it with even more features
FAQs
A tiny utility to stringify [Circular] objects on Client & on Server
The npm package circular.js receives a total of 6 weekly downloads. As such, circular.js popularity was classified as not popular.
We found that circular.js 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.