-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: add isUndefined
function
#305
Conversation
* ``` | ||
*/ | ||
export function isUndefined(value: unknown): value is undefined { | ||
return typeof value === 'undefined' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Count me surprised that this is substantially faster than === undefined
(at least on Safari 16 and Chrome 132).
https://www.measurethat.net/benchmarks/Show/15532/0/undefined-vs-typeof-vs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷
tests/typed/isUndefined.test.ts
Outdated
expect(result).toBeFalsy() | ||
}) | ||
test('returns false for string class', () => { | ||
const result = _.isUndefined(String('abc')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not testing what you want.
String(x)
returns a string, while new String(x)
returns a boxed string.
But I don't think this is a necessary test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
These checks https://github.com/radashi-org/radashi/actions/runs/11803639848/job/32882043385?pr=305 fail with |
Benchmark Results
Performance regressions of 30% or more should be investigated, unless they were anticipated. Smaller regressions may be due to normal variability, as we don't use dedicated CI infrastructure. |
typed/isUndefined()
addedisUndefined
function
Thanks for the contribution! |
Thanks for radashi 🎉 ! |
A stable release To install: pnpm add [email protected] |
Tip
The owner of this PR can publish a preview release by commenting
/publish
in this PR. Afterwards, anyone can try it out by runningpnpm add radashi@pr<PR_NUMBER>
.Summary
The PR adds the
isUndefined()
function to easily check if the passed in value isundefined
.Related issue, if any:
https://github.com/orgs/radashi-org/discussions/303
For any code change,
Does this PR introduce a breaking change?
No
Bundle impact
src/typed/isUndefined.ts
Footnotes
Function size includes the
import
dependencies of the function. ↩