Skip to content

Commit 7d288c2

Browse files
refactor(isInstance()): improve usage of instanceof operator.
1 parent de5d72a commit 7d288c2

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/is/lib/is-instance.func.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Function.
2-
import { isClass } from './is-class.func';
3-
import { isFunction } from './is-function.func';
4-
import { isObject } from './is-object.func';
52
import { resultCallback } from '../../lib/result-callback.func';
63
// Interface.
74
import { CallbackPayload } from '../../interface/callback-payload.interface';
85
// Type.
96
import { Constructor } from '../../type/constructor.type';
107
import { ResultCallback } from '../../type/result-callback.type';
118
/**
12-
* Checks if any `value` is an `object` of a generic `Obj` type and an `instance` of `Constructor` type.
9+
* Checks if any `value` is an `object` type, an instance of `Object` and an instance of the provided `constructor`.
1310
* @param value The `value` of any type to check against an instance of the provided `constructor`.
1411
* @param constructor A `class` or `function` that specifies the type of the `Constructor`.
1512
* @param callback A callback function of `ResultCallback` type with `payload` parameter of the default `CallbackPayload` shape and the
@@ -28,11 +25,11 @@ export const isInstance = <Obj, Payload extends object>(
2825
payload?: Payload
2926
): value is Obj =>
3027
callback(
31-
isObject<Obj>(value)
32-
? isClass<Obj>(constructor) || isFunction(constructor)
33-
? value instanceof constructor === true
34-
: false
35-
: false,
28+
typeof value === 'object' &&
29+
value instanceof Object === true &&
30+
typeof constructor === 'function'
31+
? value instanceof constructor === true
32+
: false,
3633
{
3734
...{
3835
name: isInstance.name,

0 commit comments

Comments
 (0)