radashi-org / radashi

The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.
https://radashi.js.org
MIT License
314 stars 25 forks source link

feat: add `isNullish` function #277

Closed ilxqx closed 5 days ago

ilxqx commented 1 month ago

[!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

Add isNullish function to check if the given value is null or undefined

Related issue, if any:

For any code change,

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size [^1337]
A src/typed/isNullish.ts 53

[^1337]: Function size includes the import dependencies of the function.

MarlonPassos-git commented 1 month ago

Thanks for the PR, @ilxqx. Just one thing: for functions that have type assertions, it's a good idea to include a type test to ensure that the types are working correctly. You can create the isNullish.test-d.ts file based on other test files, such as the isArray test.

MarlonPassos-git commented 1 month ago

@ilxqx I find some lint errors in your changes, please run the pnpm lint and fix the errors.

@aleclarson The strange part is the CI catches the error, but they do not show the error in the check result. image

I'm going to try to find the CI problem

aleclarson commented 1 month ago

Hey @ilxqx, you should be able to run pnpm format to fix the formatting errors. Let me know if you encounter any difficulties. :)

ilxqx commented 1 month ago

@MarlonPassos-git I have added type test for isNullish and fixed the lint errors related to my committed file.

ilxqx commented 1 month ago

Hey @ilxqx, you should be able to run pnpm format to fix the formatting errors. Let me know if you encounter any difficulties. :)

I have run pnpm format and committed the changed files. It seems that everything is ok now.

aeharding commented 3 weeks ago

I would suggest that the docs mention that value == null should be considered as an alternative, with proper lint rules to help enforce this pattern :)

aleclarson commented 3 weeks ago

@aeharding That's personally what I use, but it is somewhat prone to hard-to-debug typos, since people have a muscle memory for strict equals (===).

aleclarson commented 3 weeks ago

Hey! There's a new requirement for PRs that introduce new features. Without this requirement met, we won't be able to merge this. Note that this PR can still be included in a beta prerelease before this requirement is fulfilled.

⚠️ Note: You need to run git rebase main before this file will appear locally.

radashi-bot commented 3 weeks ago

Benchmark Results

Name Current
isNullish: with null 4,420,577.76 ops/sec ±0.07%
isNullish: with undefined 4,375,786.76 ops/sec ±0.07%
isNullish: with number 4,376,821.49 ops/sec ±0.07%
isNullish: with string 4,303,992.83 ops/sec ±0.08%
isNullish: with array 4,423,341.88 ops/sec ±0.07%

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.

ilxqx commented 5 days ago

Hey! There's a new requirement for PRs that introduce new features. Without this requirement met, we won't be able to merge this. Note that this PR can still be included in a beta prerelease before this requirement is fulfilled.

⚠️ Note: You need to run git rebase main before this file will appear locally.

Done!

aleclarson commented 5 days ago

Thanks for the contribution! Hope to see more from you in the future :v:

radashi-bot commented 1 day ago

A stable release 12.3.0 has been published to NPM. :rocket:

To install:

pnpm add radashi@12.3.0

See the changes