Skip to content

Commit

Permalink
feat(isStringIncludesSome()): checks if any value is a string or an i…
Browse files Browse the repository at this point in the history
…nstance of String that includes some of the given words.
  • Loading branch information
sciborrudnicki committed Aug 28, 2021
1 parent f809f32 commit 5c85a03
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/is/lib/is-string-includes-some.func.ts
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
);

0 comments on commit 5c85a03

Please sign in to comment.