Gathering detailed insights and metrics for json-url
Gathering detailed insights and metrics for json-url
Gathering detailed insights and metrics for json-url
Gathering detailed insights and metrics for json-url
npm install json-url
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
241 Stars
99 Commits
18 Forks
4 Watching
8 Branches
7 Contributors
Updated on 24 May 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
23.5%
8,436
Compared to previous day
Last week
14.3%
45,821
Compared to previous week
Last month
2.1%
182,908
Compared to previous month
Last year
44.5%
2,123,240
Compared to previous year
44
Generate URL-safe representations of some arbtirary JSON data in as small a space as possible that can be shared in a bookmark / link.
Although designed to work in Node, a standalone client-side library is provided that can be used directly on the browser.
var codec = require('json-url')('lzw');
var obj = { one: 1, two: 2, three: [1,2,3], four: 'red pineapples' };
codec.compress(obj).then(result => console.log(result));
/* Result: woTCo29uZQHCo3R3bwLCpXRocmVlwpMBAgPCpGZvdXLCrsSOZCBwacSDYXBwbGVz */
var codec = require('json-url')('lzma');
codec.decompress(someCompressedString).then(json => { /* operate on json */ })
var codec = require('json-url')('lzstring');
codec.stats(obj).then(
({ rawencoded, compressedencoded, compression }) => {
console.log(`Raw URI-encoded JSON string length: ${rawencoded}`);
console.log(`Compressed URI-encoded JSON string length: ${compressedencoded}`);
console.log(`Compression ratio (raw / compressed): ${compression}`);
}
);
<script type="text/javascript" src="/dist/browser/json-url.js"></script>
<script>
const lib = JsonUrl('lzma'); // JsonUrl is added to the window object
lib.compress(parsed).then(output => { result.value = output; });
</script>
To see it in action, download the source code and run npm run example
, or simply visit this link.
dist/browser/json-url.js
. Chunks must be located in the same folder as the main module itself.Typically when you want to shorten a long URL with large amounts of data parameters, the approach is to generate a "short URL" where compression is achieved by using a third-party service which stores the true URL and redirects the user (e.g. bit.ly or goo.gl).
However, if you want to:
you would encode the data structure (typically JSON) in your URL, but this often results in very large URLs.
This approach differs by removing that third-party dependency and encodes it using common compression algorithms such as LZW or LZMA.
Note: It is arguable that a custom dictionary / domain specific encoding would ultimately provide better compression, but here we want to
I explored several options, the most popular one being MessagePack. However, I noticed that it did not give the best possible compression as compared to LZMA and LZW.
At first I tried to apply the binary compression directly on a stringified JSON, then I realised that packing it first resulted in better compression.
For small JS objects, LZW largely outperformed LZMA, but for the most part you'd probably be looking to compress large JSON data rather than small amounts (otherwise a simple stringify + base64 is sufficient). You can choose to use whatever codec suits you best.
In addition, there is now support for LZSTRING, although the URI encoding still uses urlsafe-base64 because LZSTRING still uses unsafe characters via their compressToURIEncodedString
method - notably the +
character
Finally, I went with urlsafe-base64 to encode it in a URL-friendly format.
Find a way to improve bundle sizes for browser usage.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/8 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More