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

feat: add isUndefined function #305

Merged
merged 5 commits into from
Dec 1, 2024
Merged

Conversation

RobinBobin
Copy link
Contributor

@RobinBobin RobinBobin commented Nov 12, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

The PR adds the isUndefined() function to easily check if the passed in value is undefined.

Related issue, if any:

https://github.com/orgs/radashi-org/discussions/303

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed
  • Release notes in next-minor.md or next-major.md have been added, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size 1
A src/typed/isUndefined.ts 60

Footnotes

  1. Function size includes the import dependencies of the function.

* ```
*/
export function isUndefined(value: unknown): value is undefined {
return typeof value === 'undefined'
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

expect(result).toBeFalsy()
})
test('returns false for string class', () => {
const result = _.isUndefined(String('abc'))
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@RobinBobin RobinBobin changed the title isUndefined() added. feat: typed/isUndefined() added Nov 12, 2024
@RobinBobin
Copy link
Contributor Author

These checks

https://github.com/radashi-org/radashi/actions/runs/11803639848/job/32882043385?pr=305
https://github.com/radashi-org/radashi/actions/runs/11803639850/job/32882043229?pr=305

fail with
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'execa' imported from /home/runner/work/radashi/radashi/scripts/benchmarks/ci-bench-pr.ts
Is it me not having done something properly or the pipeline broke?

@radashi-bot
Copy link

radashi-bot commented Nov 12, 2024

Benchmark Results

Name Current
isUndefined: isUndefined 4,571,532.09 ops/sec ±0.06%

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.

@aleclarson aleclarson changed the title feat: typed/isUndefined() added feat: add isUndefined function Nov 13, 2024
@aleclarson aleclarson added new feature This PR adds a new function or extends an existing one prerelease Publish to NPM under the "beta" or "next" tag and removed prerelease Publish to NPM under the "beta" or "next" tag labels Nov 13, 2024
@aleclarson aleclarson added this to the v12.3.0 milestone Nov 20, 2024
@aleclarson aleclarson merged commit d527d98 into radashi-org:main Dec 1, 2024
9 checks passed
@aleclarson
Copy link
Member

Thanks for the contribution!

@RobinBobin
Copy link
Contributor Author

Thanks for radashi 🎉 !

@radashi-bot
Copy link

A stable release 12.3.0 has been published to NPM. 🚀

To install:

See the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants