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

[Feature Request] Support URLs #79

Open
Rican7 opened this issue Jul 10, 2024 · 1 comment
Open

[Feature Request] Support URLs #79

Rican7 opened this issue Jul 10, 2024 · 1 comment

Comments

@Rican7
Copy link

Rican7 commented Jul 10, 2024

I was surprised to learn that this package didn't support URL types, especially as they have a toJSON method natively.

Date and RegExp types are supported, so I figured URLs were a pretty clear case.

Is this something that can be added?

@bholmesdev
Copy link

bholmesdev commented Aug 1, 2024

For those wondering how to add URL types today: you can pass a custom record to the stringify() and parse() functions to specify parsing behavior. The following will encode and decode URL objects as expected:

import { stringify, parse } from 'devalue';

const data = { url: new URL('https://example.com') }
const stringified = stringify(data, {
  URL: (value) => value instanceof URL && value.href,
});

const parsed = parse(stringified, {
  URL: (href) => new URL(href),
})

I would love to see URL support added natively though! I'd argue URL is as common in a payload as other natively supported classes.

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

No branches or pull requests

2 participants