KilledByAPixel / JSONCrush

Compress JSON into URL friendly strings
https://killedbyapixel.github.io/JSONCrush
MIT License
1.57k stars 45 forks source link

usage examples #14

Closed antialias closed 3 years ago

antialias commented 3 years ago

provide usage examples for how to use this library to convert a javascript object to a crushed string, back to a javascript object.

There are no instructions for how to use this library. JSONCrush and JSONUncrush both appear to take strings as input, so it's unclear to me how I'm supposed to pass over my object. Do I run it through JSON.stringify first? I tried that and got garbage back out when attempting to un-crush.

The demo site contains incomprehensible minified code, so it's of no help.

I like what this software does, and I really gave an honest effort to figure out how to use it, but failed. I am sad.

KilledByAPixel commented 3 years ago

The demo code is not minified at all. Can you show me the code you are talking about? This is the example and the code in textarea_JSON.oninput shows how to go from a string to crushed to uncrushed...

    let crushed = JSONCrush(originalString);
    let uncrushed = JSONUncrush(decodeURIComponent(crushed));

https://github.com/KilledByAPixel/JSONCrush/blob/master/index.html

Did you see the instructions in the readme file at the top?

For example the first instruction says "Pass a JSON string to JSONCrush", so why is it unclear that you would need to call JSON.stringify?

antialias commented 3 years ago

Ok, so JSONCrush and JSONUncrush are exported as a global variables as a side-effect of running its script. It would be good to state that explicitly.

Also, some API-type documentation would be helpful that describes the type of the arguments and return values of each function that is exported to the global object.

KilledByAPixel commented 3 years ago

Thanks! I am going to take another pass over this depo and improve the documentation and stuff soon.

KilledByAPixel commented 3 years ago

index.html has been improved to make it easier to understand how to use, let me know if that helps!

https://github.com/KilledByAPixel/JSONCrush/blob/b0f8f22a6a0f3b1d34f33b2634074ae8eabc3f03/index.html#L36

antialias commented 3 years ago

index.html has been improved to make it easier to understand how to use, let me know if that helps!

It would be helpful to indicate the name of the exports in the readme.md file since this is the file that gets the most exposure, for example, the readme is what shows up on the package's page on the npm registry.