Skip to content

Commit 77a26b6

Browse files
refactor(guardObjectKey): use isObjectKey() instead of guardObject()
1 parent 9a7a0a0 commit 77a26b6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Function.
2-
import { guardObject } from './guard-object.func';
3-
import { isKey } from '../../is/lib/is-key.func';
2+
import { isObjectKey } from '../../is/lib/is-object-key.func';
43
// Type.
54
import { GuardObjectKey } from '../type/guard-object-key.type';
5+
import { Key } from '../../type/key.type';
6+
import { ResultCallback } from '../../type/result-callback.type';
67
/**
78
* Guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the `Key` type.
89
* @param value A generic `Obj` type `value` that contains the `key` to guard.
9-
* @param key A `Key` type name of the property that the `value` contains.
10+
* @param key A `Key` or `Key[]` type name of the property that the `value` contains.
11+
* @param callback An optional `ResultCallback` function to handle result before returns.
1012
* @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`.
1113
*/
12-
export const guardObjectKey: GuardObjectKey = <Obj extends object, Key extends keyof Obj>(value: Obj, key: Key): value is Obj =>
13-
guardObject<Obj>(value) ? isKey(key) ? key in value : true : false;
14+
export const guardObjectKey: GuardObjectKey = <Obj extends object>(value: Obj, key: Key | Key[], callback?: ResultCallback): value is Obj =>
15+
isObjectKey<Obj>(value, key, callback);

0 commit comments

Comments
 (0)