![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
async-json is a library that provides an asynchronous version of the standard JSON.stringify.
This can be used in both the browser and in node.js. The only dependency is that JSON
must exist either by the
implementation providing it (all modern browsers and implementations) or by providing it yourself
json2.js.
Assuming you are using node.js:
The easiest way to install is through npm.
$ npm install escort
Alternatively, you can pull from github and place where necessary.
There is only one, very simple function: stringify.
It takes a javascript object as its first argument and a callback as its second.
The callback has two parameters and follows the node.js style.
null
if there is no error.var asyncJSON = require('async-json');
asyncJSON.stringify({ some: "data" }, function (err, jsonValue) {
if (err) {
throw err;
}
jsonValue === '{"some":"data"}';
});
In the previous case, the callback is invoked immediately, as no asynchronous functions were found.
In the first argument, if a function is found, rather than skipping it as JSON
does, it is invoked.
Two types of functions can be provided:
Synchronous functions are useful for handling a value on-the-fly that you do not wish to precompute.
var asyncJSON = require('async-json');
asyncJSON.stringify({ some: function() { return "hard to compute data"; } }, function (err, jsonValue) {
if (err) {
throw err;
}
jsonValue === '{"some":"hard to compute data"}';
});
Like the previous example, this is invoked immediately, and the function will be invoked along the pipeline. Since JavaScript lacks the concept of background threads, this may cause the program to freeze while the value is being computed.
Note: it is perfectly acceptable to return an object that contains another function, it will be calculated through the same process.
Asynchronous functions are useful for handling I/O driven data or if you have a gradual calculation mechanism.
var asyncJSON = require('async-json');
asyncJSON.stringify({ data: function(callback) {
SomeDatabase.find({}, function (err, value) {
if (err) {
callback(err);
} else {
callback(null, {
key: value.someNumber
});
}
});
} }, function (err, jsonValue) {
if (err) {
throw err;
}
jsonValue === '{"data":{"key":12345}}';
});
This fetches data from some database or cache or other external source, and once it has a resultant value or error, will call the async callback function.
var asyncJSON = require('async-json');
asyncJSON.stringify({ data: function(callback) {
setTimeout(function () {
callback(null, "Hello there!");
}, 1000);
} }, function (err, jsonValue) {
if (err) {
throw err;
}
jsonValue === '"Hello there!"';
});
This will invoke the async callback one second after calling stringify
with the obvious result.
first:
$ git submodule update --init
then:
$ make test
If you find any issues with async-json or have any suggestions or feedback, please feel free to visit the github issues page.
MIT licensed. See LICENSE for more details.
FAQs
An asynchronous version of JSON.stringify
The npm package async-json receives a total of 38 weekly downloads. As such, async-json popularity was classified as not popular.
We found that async-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.