Created
February 20, 2021 10:52
-
-
Save morellodev/dbbd7573602ff14367424131e5416bf8 to your computer and use it in GitHub Desktop.
Functions to encode and decode URL safe Base64 strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const objectToUrlSafeBase64 = (obj) => { | |
| const stringifiedObject = JSON.stringify(obj); | |
| const base64String = btoa(stringifiedObject); | |
| return encodeURIComponent(base64String); | |
| }; | |
| const urlSafeBase64ToObject = (urlSafeBase64String) => { | |
| const base64String = decodeURIComponent(urlSafeBase64String); | |
| const stringifiedObject = atob(base64String); | |
| return JSON.parse(stringifiedObject); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment