UNPKG

@igorskyflyer/chars-in-string

Version:

๐Ÿช Determines whether an array of chars is present inside a given String. โ˜„

192 lines (129 loc) โ€ข 5.34 kB
<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> ## ๐Ÿ“ƒ Table of Contents - [Features](#-features) - [Usage](#-usage) - [API](#-api) - [Examples](#๏ธ-examples) - [Changelog](#-changelog) - [Support](#-support) - [License](#-license) - [Related](#-related) - [Author](#-author) <br> <br> ## ๐Ÿค– Features - ๐Ÿ” 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> ## ๐Ÿ•ต๐Ÿผ Usage 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> ## ๐Ÿคน๐Ÿผ API 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> ## ๐Ÿ—’๏ธ Examples ```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> ## ๐Ÿ“ Changelog ๐Ÿ“‘ The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-chars-in-string/blob/main/CHANGELOG.md). <br> <br> ## ๐Ÿชช License Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-chars-in-string/blob/main/LICENSE). <br> <br> ## ๐Ÿ’– Support <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> ## ๐Ÿงฌ Related [@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/)).