Closed iuioiua closed 2 days ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 94.15%. Comparing base (
26914ff
) to head (d379578
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I think it would be better the other way around. canParse()
is borrowed from web APIs like URL.prototype.canParse while tryParse()
was rejected as a web API (ref https://github.com/denoland/deno_std/pull/4049)
The motivation for this PR (see initial comment), I think, is a good counterargument for doing that. This is what Yoshiya previously explained. I didn't agree with it then, but I do now.
now URL has URL.parse
which returns URL | null
https://github.com/whatwg/url/pull/825 that is mostly aligned to semver.tryParse
.
Some deno projects (deployctl, publish-on-tag) seem using canParse
.
https://github.com/search?q=semver+canParse+language%3ATypeScript&type=code&l=TypeScript
Do we need to remove this?
How about keeping all three APIs (parse
, tryParse
, canParse
)?
My opinion on this isn't strong. Existing use is a sufficient reason to abandon the idea. Fine with me. Closing.
What's changed
canParse()
has been removed from@std/semver
in favor oftryParse()
.Motivation
This change was made because
tryParse()
provides extended functionality overcanParse()
, as it allows the user to determine whether a string is able to be parsed into a SemVer version, but returns that SemVer object too.Migration
To migrate, use
tryParse()
instead ofcanParse()
, and compare the return value tonull
.CC @timreichen