@igorskyflyer/chars-in-string
Version:
๐ช Determines whether an array of chars is present inside a given String. โ
192 lines (129 loc) โข 5.34 kB
Markdown
<div align="center">
<img src="https://raw.githubusercontent.com/igorskyflyer/npm-chars-in-string/main/media/chars-in-string.png" alt="Icon of Chars in String" width="256" height="256">
<h1>Chars in String</h1>
</div>
<br>
<h4 align="center">
๐ช Determines whether an array of chars is present inside a given String. โ
</h4>
<br>
<br>
- [Features](
- [Usage](
- [API](
- [Examples](
- [Changelog](
- [Support](
- [License](
- [Related](
- [Author](
<br>
<br>
- ๐ Find instantly - See if your text contains what youโre looking for
- ๐ฏ Target precisely - Match at the start, end, or anywhere in the text
- ๐ Match your way - Choose caseโsensitive or caseโinsensitive search
- ๐งฎ Works with one or many - Search for single characters or whole words/phrases
- โก Quick answers - Stops searching as soon as a match is found
- ๐ Crossโplatform friendly - Works the same on any OS or environment
<br>
<br>
Install it by executing any of the following, depending on your preferred package manager:
```bash
pnpm add @igorskyflyer/chars-in-string
```
```bash
yarn add @igorskyflyer/chars-in-string
```
```bash
npm i @igorskyflyer/chars-in-string
```
<br>
<br>
An `enum` is available publicly, used for setting the position of the search, see more below. ๐
```ts
enum Position {
Any,
Start,
End
}
```
It allows you define where the matching should occur, at the **beginning** of the `String`, at the **end** or **anywhere** (default).
<br>
<br>
```ts
function charsInString(characters: string[], input: string, position = Position.Any, caseSensitive = true): boolean
```
`characters: string[]` - the characters to search for, expects a single character per entry, if multiple are found it will take the first one,
`input: string` - the String which needs to be checked,
`[position: Position=Position.Any]` - controls where the matching should occur, at the **beginning** of the `String`, at the **end** or **anywhere** (default),
`[caseSensitive: boolean=true]` - controls whether the search is case-sensitive, defaults to `true`.
<br>
<br>
```ts
function stringsInString(strings, input, position = Position.Any, caseSensitive = true): boolean
```
`strings[]: string[]` - the strings to search for,
`input: string` - the String which needs to be checked,
`[position: Position=Position.Any]` - controls where the matching should occur, at the **beginning** of the `String`, at the **end** or **anywhere** (default),
`[caseSensitive: boolean=true]` - controls whether the search is case-sensitive, defaults to `true`.
<br>
<br>
```ts
import { charsInString, stringsInString, Position } from '@igorskyflyer/chars-in-string'
console.log(charsInString([], '')) // prints false
console.log(charsInString([], 'test')) // prints false
console.log(charsInString([':', ','], '')) // prints false
console.log(charsInString([':', ','], 'hello:world')) // prints true
console.log(charsInString([':', ',', '^'], 'helloworld^')) // prints true
console.log(charsInString([':', ',', '^'], 'helloworld')) // prints false
console.log(stringsInString(['abc', 'owom', 'wqp', 'world', 'hel'], 'helloworld', Position.Start)) // prints true
```
<br>
<br>
๐ The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-chars-in-string/blob/main/CHANGELOG.md).
<br>
<br>
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-chars-in-string/blob/main/LICENSE).
<br>
<br>
<div align="center">
I work hard for every project, including this one and your support means a lot to me!
<br>
Consider buying me a coffee. โ
<br>
<br>
<a href="https://ko-fi.com/igorskyflyer" target="_blank"><img src="https://raw.githubusercontent.com/igorskyflyer/igorskyflyer/main/assets/ko-fi.png" alt="Donate to igorskyflyer" width="180" height="46"></a>
<br>
<br>
<em>Thank you for supporting my efforts!</em> ๐๐
</div>
<br>
<br>
[@igorskyflyer/str-is-in](https://www.npmjs.com/package/@igorskyflyer/str-is-in)
> _๐งต Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. ๐_
<br>
[@igorskyflyer/recursive-readdir](https://www.npmjs.com/package/@igorskyflyer/recursive-readdir)
> _๐ Provides recursive readdir() and readdirSync() functions. ๐_
<br>
[@igorskyflyer/astro-post-excerpt](https://www.npmjs.com/package/@igorskyflyer/astro-post-excerpt)
> _โญ An Astro component that renders post excerpts for your Astro blog - directly from your Markdown and MDX files. Astro v2+ collections are supported as well! ๐_
<br>
[@igorskyflyer/adblock-filter-counter](https://www.npmjs.com/package/@igorskyflyer/adblock-filter-counter)
> _๐ฒ A dead simple npm module that counts Adblock filter rules.๐ฆ_
<br>
[@igorskyflyer/scramble](https://www.npmjs.com/package/@igorskyflyer/scramble)
> _๐ Scrambles (rearranges randomly) Strings and Arrays. ๐_
<br>
<br>
<br>
## ๐จ๐ปโ๐ป Author
Created by **Igor Dimitrijeviฤ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).