Skip to content

Commit

Permalink
feat(guardStringLengthBetween()): guard string length between.
Browse files Browse the repository at this point in the history
  • Loading branch information
angularpackage committed Jan 28, 2022
1 parent 0e48591 commit 5d044f9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/guard/lib/guard-string-length-between.func.ts
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);

0 comments on commit 5d044f9

Please sign in to comment.