mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 03:32:58 +03:00
feat(isNull): Add compatibility with lodash (#264)
* 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:
parent
d0812b81ab
commit
999a4daf87
19
benchmarks/performance/isNull.bench.ts
Normal file
19
benchmarks/performance/isNull.bench.ts
Normal 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);
|
||||
});
|
||||
});
|
@ -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) | ❌ |
|
||||
|
@ -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) | ❌ |
|
||||
|
@ -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) | ❌ |
|
||||
|
35
src/compat/predicate/isNull.spec.ts
Normal file
35
src/compat/predicate/isNull.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user