Skip to content

Instantly share code, notes, and snippets.

@johnoscott
Last active August 2, 2021 22:37
Show Gist options
  • Save johnoscott/0c923e119352489b76b7ae060f26693f to your computer and use it in GitHub Desktop.
Save johnoscott/0c923e119352489b76b7ae060f26693f to your computer and use it in GitHub Desktop.
babel url encoding for http get params
const compress = (string: string) =>
LZString.compressToBase64(string)
.replace(/\+/g, "-") // Convert '+' to '-'
.replace(/\//g, "_") // Convert '/' to '_'
.replace(/=+$/, ""); // Remove ending '='
const decompress = (string: string) =>
LZString.decompressFromBase64(
string
.replace(/-/g, "+") // Convert '-' to '+'
.replace(/_/g, "/") // Convert '_' to '/'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment