Skip to content

Commit

Permalink
refactor(isInstance()): improve usage of instanceof operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
sciborrudnicki committed Aug 20, 2021
1 parent de5d72a commit 7d288c2
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/is/lib/is-instance.func.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// Function.
import { isClass } from './is-class.func';
import { isFunction } from './is-function.func';
import { isObject } from './is-object.func';
import { resultCallback } from '../../lib/result-callback.func';
// Interface.
import { CallbackPayload } from '../../interface/callback-payload.interface';
// Type.
import { Constructor } from '../../type/constructor.type';
import { ResultCallback } from '../../type/result-callback.type';
/**
* Checks if any `value` is an `object` of a generic `Obj` type and an `instance` of `Constructor` type.
* Checks if any `value` is an `object` type, an instance of `Object` and an instance of the provided `constructor`.
* @param value The `value` of any type to check against an instance of the provided `constructor`.
* @param constructor A `class` or `function` that specifies the type of the `Constructor`.
* @param callback A callback function of `ResultCallback` type with `payload` parameter of the default `CallbackPayload` shape and the
Expand All @@ -28,11 +25,11 @@ export const isInstance = <Obj, Payload extends object>(
payload?: Payload
): value is Obj =>
callback(
isObject<Obj>(value)
? isClass<Obj>(constructor) || isFunction(constructor)
? value instanceof constructor === true
: false
: false,
typeof value === 'object' &&
value instanceof Object === true &&
typeof constructor === 'function'
? value instanceof constructor === true
: false,
{
...{
name: isInstance.name,
Expand Down

0 comments on commit 7d288c2

Please sign in to comment.