-
-
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(isStringIncludesSome()): checks if any value is a string or an i…
…nstance of String that includes some of the given words.
- Loading branch information
1 parent
f809f32
commit 5c85a03
Showing
1 changed file
with
38 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,38 @@ | ||
// Function. | ||
import { isArray } from './is-array.func'; | ||
import { isString } from './is-string.func'; | ||
import { isStringType } from './is-string-type.func'; | ||
import { resultCallback } from '../../lib/result-callback.func'; | ||
// Interface. | ||
import { CallbackPayload } from '../../type/callback-payload.type'; | ||
// Type. | ||
import { ResultCallback } from '../../type/result-callback.type'; | ||
|
||
/** | ||
* Checks if any `value` is a `string` type or an instance of `String`(by using `isString()`) that includes some of the specified words. | ||
* @param value The `value` of any type to check against the string that contains some of the words from the given `includes`. | ||
* @param includes An `Array` of `string` as words to be case-sensitive searched for within the given `value`. | ||
* @param callback A callback `function` of `ResultCallback` type with parameters, the `value` that has been checked, the `result` of this | ||
* check, and `payload` of the default `CallbackPayload` shape, with the `includes` and optional properties from the provided `payload`, | ||
* to handle them before the `result` return. By default, it uses `resultCallback()` function. | ||
* @param payload An optional `object` of a generic type variable `Payload` that is assigned to the `payload` of the provided `callback` | ||
* function. | ||
* @returns The return value is a `boolean` indicating whether the provided `value` is a `string` type or an instance of `String` that | ||
* includes some of the specified words. | ||
* @angularpackage | ||
*/ | ||
export const isStringIncludesSome = <Payload extends object>( | ||
value: any, | ||
includes: string[], | ||
callback: ResultCallback<any, typeof payload> = resultCallback, | ||
payload?: CallbackPayload<{ includes: typeof includes } & Payload> | ||
): value is string => | ||
callback( | ||
isString(value) | ||
? isArray(includes) | ||
? includes.some((include) => value.valueOf().includes(include)) | ||
: false | ||
: false, | ||
value, | ||
{ name: isStringIncludesSome.name, includes, ...payload } as any | ||
); |