Skip to content
This repository was archived by the owner on Dec 18, 2020. It is now read-only.

Add safe versions of various functions from Global.Unsafe. #18

Merged
merged 1 commit into from
Aug 11, 2019
Merged

Conversation

nsaunders
Copy link
Contributor

Some concerns about the use of unsafeEncodeURIComponent in purescript-form-urlencoded (and potentially unsafeDecodeURIComponent) were raised in purescript-form-urlencoded#12. Thomas Honeyman suggested that safe alternatives should be added to this library; and, considering #16, it seems like this is something people need.

As I understand, this has been avoided up to now in order to keep purescript-globals a zero-dependency library. I suppose we need to consider whether the benefit of reducing dependency bloat outweighs the cost; which in some cases (as linked above) is error-prone code, and in other cases is opting out of purescript-globals altogether.

If we simply aren't willing to accept dependencies here, I have created a separate purescript-globals-safe library introducing the Global.Safe module that perhaps should be promoted to the purescript or purescript-contrib organizations and published to Pursuit (which I have avoided for now to prevent redundant Global.Safe modules potentially appearing there).

Other than that, I would welcome any feedback you might have, even if this won't be merged, so that I can improve purescript-globals-safe. Thanks in advance!

-- | Uses the global JSON object to turn anything into a string.
-- | Returns `Nothing` when input is a function.
stringify :: forall a. a -> Maybe String
stringify v = runFn3 _stringify (const Nothing) Just v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really rather not provide this function. The JSON libraries already have it, and they ensure the accepted type actually is JSON too. A "print a representation of anything" function is ok in purescript-debug, since you can't get a value out of it and all those functions raise a warning, but it's highly dodgy otherwise.

@garyb
Copy link
Member

garyb commented Aug 8, 2019

I'd just put these functions in the existing Global module too I think 🙂.

@nsaunders nsaunders changed the title Add Global.Safe with error handling. Add safe versions of various functions from Global.Unsafe. Aug 9, 2019
@nsaunders
Copy link
Contributor Author

Thanks very much for the feedback @garyb. I have updated the pull request accordingly. Please let me know if anything else comes to mind!

@garyb
Copy link
Member

garyb commented Aug 11, 2019

Looks great, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants