Skip to content

Commit c98b0e1

Browse files
refactor(guardString): add guard for primitive String object
1 parent cae5ea1 commit c98b0e1

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Function.
22
import { isString } from '../../is/lib/is-string.func';
33
// Type.
4+
import { AnyString } from '../../type/any-string.type';
45
import { GuardString } from '../type/guard-string.type';
56
import { ResultCallback } from '../../type/result-callback.type';
67
/**
7-
* Guard the `value` to be a `string`.
8-
* @param value A `string` type `value` to guard.
9-
* @param callback Optional `ResultCallback` function to handle result before returns.
10-
* @returns A `boolean` indicating whether or not the `value` is a `string`.
8+
* Guard the `value` to be any type of a string.
9+
* @param value An `AnyString` type `value` to guard.
10+
* @param callback An Optional `ResultCallback` function to handle result before returns.
11+
* @returns A `boolean` indicating whether or not the `value` is a `string` type or `String` object.
1112
*/
12-
export const guardString: GuardString = (value: string, callback?: ResultCallback): value is string =>
13+
export const guardString: GuardString = <S extends AnyString>(value: S, callback?: ResultCallback): value is S =>
1314
isString(value, callback);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
import { AnyString } from '../../type/any-string.type';
12
import { ResultCallback } from '../../type/result-callback.type';
2-
export type GuardString = (value: string, callback?: ResultCallback) => value is string;
3+
export type GuardString = <S extends AnyString>(value: S, callback?: ResultCallback) => value is S;

0 commit comments

Comments
 (0)