-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(guardStringLengthBetween()): guard string length between.
- Loading branch information
1 parent
0e48591
commit 5d044f9
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Function. | ||
import { isStringLengthBetween } from '../../is'; | ||
// Type. | ||
import { AnyString } from '../../type/any-string.type'; | ||
import { ResultCallback } from '../../type/result-callback.type'; | ||
import { StringOfLength } from '../../type/string-of-length.type'; | ||
/** | ||
* Guards the value to be `string` or `String` instance of a length between the specified range. | ||
* @param value The value of a generic type variable `Type` constrained by `AnyString`, by default of the type captured from itself to | ||
* guard. | ||
* @param min The **minimum** length of generic type variable `Min` of a given `value`. | ||
* @param max The **maximum** length of generic type variable `Max` of a given `value`. | ||
* @param callback An optional `ResultCallback` function to handle the result before returns. | ||
* @param payload Optional `object` of generic type variable `Payload` is assigned to the `payload` of the provided `callback` function. | ||
* @returns The return value is a `boolean` indicating whether the `value` is a `string` type or an instance of `String` of a length between | ||
* the specified range. | ||
* @angularpackage | ||
*/ | ||
export const guardStringLengthBetween = < | ||
Type extends AnyString, | ||
Min extends number, | ||
Max extends number, | ||
Payload extends object = object | ||
>( | ||
value: Type, | ||
min: Min, | ||
max: Max, | ||
callback?: ResultCallback<Type, { min: Min, max: Max } & Payload>, | ||
payload?: Payload | ||
): value is StringOfLength<Min, Max, Type> => | ||
isStringLengthBetween(value, min, max, callback, payload); |