feat(isNull): Add compatibility with lodash (#264)
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run

* feat(isNull): Add isNull benchmark

* feat(isNull): Add compat's isNull test code

* docs(isNull): Update isNull status from 'review' to 'complete'

* Update src/compat/predicate/isNull.spec.ts

* Update src/compat/predicate/isNull.spec.ts

---------

Co-authored-by: Sojin Park <raon0211@toss.im>
Co-authored-by: Sojin Park <raon0211@gmail.com>
This commit is contained in:
정해준 2024-07-21 11:06:54 +09:00 committed by GitHub
parent d0812b81ab
commit 999a4daf87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 57 additions and 3 deletions

View File

@ -0,0 +1,19 @@
import { bench, describe } from 'vitest';
import { isNull as isNullToolkit } from 'es-toolkit';
import { isNull as isNullLodash } from 'lodash';
describe('isNull', () => {
bench('es-toolkit/isNull', () => {
isNullToolkit(null);
isNullToolkit(undefined);
isNullToolkit('');
isNullToolkit(123);
});
bench('lodash/isNull', () => {
isNullLodash(null);
isNullLodash(undefined);
isNullLodash('');
isNullLodash(123);
});
});

View File

@ -217,7 +217,7 @@ Even if a feature is marked "in review," it might already be under review to ens
| [isNaN](https://lodash.com/docs/4.17.15#isNaN) | ❌ |
| [isNative](https://lodash.com/docs/4.17.15#isNative) | ❌ |
| [isNil](https://lodash.com/docs/4.17.15#isNil) | 📝 |
| [isNull](https://lodash.com/docs/4.17.15#isNull) | 📝 |
| [isNull](https://lodash.com/docs/4.17.15#isNull) | |
| [isNumber](https://lodash.com/docs/4.17.15#isNumber) | ❌ |
| [isObject](https://lodash.com/docs/4.17.15#isObject) | ❌ |
| [isObjectLike](https://lodash.com/docs/4.17.15#isObjectLike) | ❌ |

View File

@ -218,7 +218,7 @@ chunk([1, 2, 3, 4], 0);
| [isNaN](https://lodash.com/docs/4.17.15#isNaN) | ❌ |
| [isNative](https://lodash.com/docs/4.17.15#isNative) | ❌ |
| [isNil](https://lodash.com/docs/4.17.15#isNil) | 📝 |
| [isNull](https://lodash.com/docs/4.17.15#isNull) | 📝 |
| [isNull](https://lodash.com/docs/4.17.15#isNull) | |
| [isNumber](https://lodash.com/docs/4.17.15#isNumber) | ❌ |
| [isObject](https://lodash.com/docs/4.17.15#isObject) | ❌ |
| [isObjectLike](https://lodash.com/docs/4.17.15#isObjectLike) | ❌ |

View File

@ -217,7 +217,7 @@ chunk([1, 2, 3, 4], 0);
| [isNaN](https://lodash.com/docs/4.17.15#isNaN) | ❌ |
| [isNative](https://lodash.com/docs/4.17.15#isNative) | ❌ |
| [isNil](https://lodash.com/docs/4.17.15#isNil) | 📝 |
| [isNull](https://lodash.com/docs/4.17.15#isNull) | 📝 |
| [isNull](https://lodash.com/docs/4.17.15#isNull) | |
| [isNumber](https://lodash.com/docs/4.17.15#isNumber) | ❌ |
| [isObject](https://lodash.com/docs/4.17.15#isObject) | ❌ |
| [isObjectLike](https://lodash.com/docs/4.17.15#isObjectLike) | ❌ |

View File

@ -0,0 +1,35 @@
import { describe, expect, it } from 'vitest';
import { isNull } from '../../predicate';
import { falsey } from '../_internal/falsey';
/**
* @see https://github.com/lodash/lodash/blob/main/test/isNull.spec.js
*/
describe('isNull', () => {
it('should return `true` for `null` values', () => {
expect(isNull(null)).toBe(true);
});
it('should return `false` for non `null` values', () => {
const expected = falsey.map(value => value === null);
const actual = falsey.map((value, index) => (index ? isNull(value) : isNull(undefined)));
// eslint-disable-next-line
(function (..._args: any[]) {
// eslint-disable-next-line
expect(isNull(arguments)).toBe(false);
})(1, 2, 3);
expect(actual).toEqual(expected);
expect(isNull([1, 2, 3])).toBe(false);
expect(isNull(true)).toBe(false);
expect(isNull(new Date())).toBe(false);
expect(isNull(new Error())).toBe(false);
expect(isNull(Array.prototype.slice)).toBe(false);
expect(isNull({ a: 1 })).toBe(false);
expect(isNull(1)).toBe(false);
expect(isNull(/x/)).toBe(false);
expect(isNull('a')).toBe(false);
expect(isNull(Symbol('a'))).toBe(false);
expect(isNull(undefined)).toBe(false);
});
});