-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow sharing of the REPL #25
base: master
Are you sure you want to change the base?
Conversation
const base64UrlDecodeChars = {'-': '+', '_': '/', '.': '='}; | ||
const base64UrlDecode = input => { | ||
try { | ||
return atob(input.replace(/[-_.]/g, c => base64UrlDecodeChars[c])); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
const base64UrlEncodeChars = {'+': '-', '/': '_', '=': '.'}; | ||
const base64UrlEncode = input => { | ||
try { | ||
return btoa(input).replace(/[+/=]/g, c => base64UrlEncodeChars[c]); | ||
} catch { | ||
return null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smart!
// Quote property names | ||
opts = opts.replace(/^\s*(\w+):/gm, '"$1":'); | ||
return JSON.parse(opts); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why this is something we need to do (avoiding a self xss and whatnot), however there are some Terser options that are regexps. For instance you can use /^_/
to select properties started with _ to mangle :/
There are a few options that take functions too (which would be a nightmare) so I'm not mentioning that part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible to avoid this by disabling sharing for options that include RegExps and functions. Then you can do eval freely, and only do JSON.parse in loadState
This saves and loads the current REPL state into the hash fragment, allow simple sharing. I've wanted this a few times when trying to demo different compression options.