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. โ
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-chars-in-string
- Owner: igorskyflyer
- License: mit
- Created: 2021-07-17T01:20:21.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T22:53:42.000Z (about 3 years ago)
- Last Synced: 2025-04-12T15:06:01.330Z (about 1 year ago)
- Topics: back-end, characters, chars, check, igorskyflyer, javascript, mocha, node, nodejs, string, utility
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/chars-in-string
- Size: 169 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
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. โ
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/)).