Giter Club home page Giter Club logo

Comments (6)

pieroxy avatar pieroxy commented on June 26, 2024

The implementation I suggest for encoding something to URL encode is: LZString.compressToBase64().replace("=","$").replace("/","-") with of course the reverse replace before decoding. With this, you have nothing to URL encode.

I'll push two methods that wrap that. It never hurts. I'll update the documentation once this is in. (And I need to refactor a few things to make the current 'release' version more accessible by removing the version from the file name). I'll do that this weekend.

If you think of better chars than $ and -, I'm all ears.

from lz-string.

tomteman avatar tomteman commented on June 26, 2024

I also use $ and - myself as well as replace and reverse replace where needed :)
And like you said, I also think that wrapping it doesn't hurt and will make the code "prettier" 👍

from lz-string.

pieroxy avatar pieroxy commented on June 26, 2024

The version 1.3.5 should do the trick. Let me know.

I'll update the doc soon.

from lz-string.

pieroxy avatar pieroxy commented on June 26, 2024

Doc updated.

from lz-string.

tomteman avatar tomteman commented on June 26, 2024

I just looked at your implementation. I was actually hoping for a method which simply lets you set the last 2 chars of _keyStr to whatever you want, which will probably be part of some init step, setting various properties.
btw - since I use compressToUTF16 (I sometimes need to save url safe strings to the localStorage), and not compressToBase64, I can't use the new implementation (compressToEncodedURIComponent uses compressToBase64) and will continue using the replace method myself :/

from lz-string.

pieroxy avatar pieroxy commented on June 26, 2024

I don't understand your issue...

First, yes, I could have done something smarter for compressToEncodedURIComponent instead of basic replaces, but since this method is a preparation for a network operation, I guess wasting a couple of milliseconds here is no big deal and will be insignificant in regard to the network latency. That may not always be the case.

Second, I don't see the point in making the output of compressToUTF16 URL-encoded... Can you elaborate on your needs?

from lz-string.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.