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(isUndefined): Add compatibility with lodash #266

Merged
merged 9 commits into from
Jul 21, 2024
18 changes: 18 additions & 0 deletions benchmarks/performance/isUndefined.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bench, describe } from 'vitest';
import { isUndefined as isUndefinedToolkit } from 'es-toolkit';
import { isUndefined as isUndefinedLodash } from 'lodash';

describe('isUndefined', () => {
bench('es-toolkit/isUndefined', () => {
isUndefinedToolkit(undefined);
isUndefinedToolkit(null);
isUndefinedToolkit('');
isUndefinedToolkit(123);
});
bench('lodash/isUndefined', () => {
isUndefinedLodash(undefined);
isUndefinedLodash(null);
isUndefinedLodash('');
isUndefinedLodash(123);
});
});
2 changes: 1 addition & 1 deletion docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Even if a feature is marked "in review," it might already be under review to ens
| [isString](https://lodash.com/docs/4.17.15#isString) | ❌ |
| [isSymbol](https://lodash.com/docs/4.17.15#isSymbol) | ❌ |
| [isTypedArray](https://lodash.com/docs/4.17.15#isTypedArray) | ❌ |
| [isUndefined](https://lodash.com/docs/4.17.15#isUndefined) | 📝 |
| [isUndefined](https://lodash.com/docs/4.17.15#isUndefined) | |
| [isWeakMap](https://lodash.com/docs/4.17.15#isWeakMap) | ❌ |
| [isWeakSet](https://lodash.com/docs/4.17.15#isWeakSet) | ❌ |
| [lt](https://lodash.com/docs/4.17.15#lt) | ❌ |
Expand Down
2 changes: 1 addition & 1 deletion docs/ko/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ chunk([1, 2, 3, 4], 0);
| [isString](https://lodash.com/docs/4.17.15#isString) | ❌ |
| [isSymbol](https://lodash.com/docs/4.17.15#isSymbol) | ❌ |
| [isTypedArray](https://lodash.com/docs/4.17.15#isTypedArray) | ❌ |
| [isUndefined](https://lodash.com/docs/4.17.15#isUndefined) | 📝 |
| [isUndefined](https://lodash.com/docs/4.17.15#isUndefined) | |
| [isWeakMap](https://lodash.com/docs/4.17.15#isWeakMap) | ❌ |
| [isWeakSet](https://lodash.com/docs/4.17.15#isWeakSet) | ❌ |
| [lt](https://lodash.com/docs/4.17.15#lt) | ❌ |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_hans/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ chunk([1, 2, 3, 4], 0);
| [isString](https://lodash.com/docs/4.17.15#isString) | ❌ |
| [isSymbol](https://lodash.com/docs/4.17.15#isSymbol) | ❌ |
| [isTypedArray](https://lodash.com/docs/4.17.15#isTypedArray) | ❌ |
| [isUndefined](https://lodash.com/docs/4.17.15#isUndefined) | 📝 |
| [isUndefined](https://lodash.com/docs/4.17.15#isUndefined) | |
| [isWeakMap](https://lodash.com/docs/4.17.15#isWeakMap) | ❌ |
| [isWeakSet](https://lodash.com/docs/4.17.15#isWeakSet) | ❌ |
| [lt](https://lodash.com/docs/4.17.15#lt) | ❌ |
Expand Down
30 changes: 30 additions & 0 deletions src/compat/predicate/isUndefined.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import { isUndefined } from '../../predicate';
import { falsey } from '../_internal/falsey';

describe('isUndefined', () => {
it('should return `true` for `undefined` values', () => {
expect(isUndefined(undefined)).toBe(true);
});

it('should return `false` for non `undefined` values', () => {
const expected = falsey.map(value => value === undefined);
const actual = falsey.map((value, index) => (index ? isUndefined(value) : isUndefined(undefined)));
expect(actual).toEqual(expected);

(function (..._: any[]) {
raon0211 marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line prefer-rest-params
expect(isUndefined(arguments)).toBe(false);
raon0211 marked this conversation as resolved.
Show resolved Hide resolved
})(1, 2, 3);
expect(isUndefined([1, 2, 3])).toBe(false);
expect(isUndefined(true)).toBe(false);
expect(isUndefined(new Date())).toBe(false);
expect(isUndefined(new Error())).toBe(false);
expect(isUndefined(Array.prototype.slice)).toBe(false);
expect(isUndefined({ a: 1 })).toBe(false);
expect(isUndefined(1)).toBe(false);
expect(isUndefined(/x/)).toBe(false);
expect(isUndefined('a')).toBe(false);
expect(isUndefined(Symbol('a'))).toBe(false);
});
});