An open API service indexing awesome lists of open source software.

https://github.com/igorskyflyer/npm-chars-in-string

๐Ÿช Provides ways of testing whether an array of chars is present inside a given String. โ˜„
https://github.com/igorskyflyer/npm-chars-in-string

back-end characters chars check igorskyflyer javascript mocha node nodejs string utility

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

          


Icon of Chars in String

Chars in String




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




## ๐Ÿ“ƒ Table of Contents

- [Features](#-features)
- [Usage](#-usage)
- [API](#-api)
- [Examples](#๏ธ-examples)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)




## ๐Ÿค– 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




## ๐Ÿ•ต๐Ÿผ 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
```




## ๐Ÿคน๐Ÿผ 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).




```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`.




```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`.




## ๐Ÿ—’๏ธ 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
```




## ๐Ÿ“ Changelog

๐Ÿ“‘ The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-chars-in-string/blob/main/CHANGELOG.md).




## ๐Ÿชช License

Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-chars-in-string/blob/main/LICENSE).




## ๐Ÿ’– Support


I work hard for every project, including this one and your support means a lot to me!


Consider buying me a coffee. โ˜•




Donate to igorskyflyer




Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š




## ๐Ÿงฌ 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. ๐Ÿ”_


[@igorskyflyer/recursive-readdir](https://www.npmjs.com/package/@igorskyflyer/recursive-readdir)

> _๐Ÿ“– Provides recursive readdir() and readdirSync() functions. ๐Ÿ“_


[@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! ๐Ÿ’Ž_


[@igorskyflyer/adblock-filter-counter](https://www.npmjs.com/package/@igorskyflyer/adblock-filter-counter)

> _๐Ÿฒ A dead simple npm module that counts Adblock filter rules.๐Ÿฆ˜_


[@igorskyflyer/scramble](https://www.npmjs.com/package/@igorskyflyer/scramble)

> _๐Ÿƒ Scrambles (rearranges randomly) Strings and Arrays. ๐ŸŽ‹_






## ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author
Created by **Igor Dimitrijeviฤ‡** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).