Skip to content
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

Jsonify correctness #410

Merged
merged 8 commits into from
Jun 30, 2022
Merged

Conversation

frontsideair
Copy link
Contributor

@frontsideair frontsideair commented Jun 28, 2022

This is my first attempt at fixing Jsonify problems I mentioned in #407.

I started with tests first, then proceeded to fix those tests. Tests are based on MDN docs and my own tests.

I had to delete a faulty test case, where an object had a function value. The spec tells that those entries are omitted from the output.

I checked the validity of the types with the provided test script. It also output a lot of lint warnings that were there before I picked it up, so I left them alone. I can fix those errors if you want me to, but it will end up destroying the git blame.

I'm not sure if I documented everything I did as best as I could, since this was a first attempt. I can fix anything where you thing it needs more explanation.

I also commented out the Infinity and NaN checks. Infinity is detectable with this library, but it seemed like a minor edge case. NaN is not detectable as far as I can understand, see #406.

Also missing is TypedArrays. I'm not sure how to approach them, any guidance is welcome, or we can get this merged and leave it as future work.

I can also add a warning about NaNs in the readme, or leave it as future work as well.

Sorry for a lot of text, I just wanted to cover everything.


Fixes #407

- it now handles transformation of Number, String and Boolean to
  primitive counterparts
- it correctly turns function and symbol to null as array members
- it omits entries in objects where values are function, symbol or
  undefined; and where keys are symbols
- it fails on BigInt with never
test-d/jsonify.ts Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

You need to fix the lint errors.

@sindresorhus
Copy link
Owner

Also missing is TypedArrays. I'm not sure how to approach them, any guidance is welcome

What's the difficulty with supporting TypedArrays?

@sindresorhus
Copy link
Owner

I can also add a warning about NaNs in the readme, or leave it as future work as well.

Both

@frontsideair
Copy link
Contributor Author

Sorry for the lint errors point, I thought they were there before but I was mistaken. I fixed them all. I'll investigate the typed arrays and update the readme about limitations.

@frontsideair
Copy link
Contributor Author

@sindresorhus I think it should be ready for review. I fixed newly introduced lint errors as well.

@sindresorhus sindresorhus merged commit 8ca2959 into sindresorhus:main Jun 30, 2022
@sindresorhus
Copy link
Owner

Thanks for contributing 🙏

skarab42 pushed a commit to skarab42/type-fest that referenced this pull request Jul 3, 2022
skarab42 pushed a commit to skarab42/type-fest that referenced this pull request Aug 16, 2022
skarab42 pushed a commit to skarab42/type-fest that referenced this pull request Aug 24, 2022
skarab42 pushed a commit to skarab42/type-fest that referenced this pull request Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jsonify problems
2 participants