[Feature Request] Support URLs
Opened this issue · 1 comments
Rican7 commented
bholmesdev commented
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.