@igorskyflyer/chars-in-string
v3.0.0
Published
🪐 Determines whether an array of chars is present inside a given String. ☄
Maintainers
Readme
📃 Table of Contents
🤖 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:
pnpm add @igorskyflyer/chars-in-stringyarn add @igorskyflyer/chars-in-stringnpm i @igorskyflyer/chars-in-string🤹🏼 API
An enum is available publicly, used for setting the position of the search, see more below. 👇
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).
function charsInString(characters: string[], input: string, position = Position.Any, caseSensitive = true): booleancharacters: 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.
function stringsInString(strings, input, position = Position.Any, caseSensitive = true): booleanstrings[]: 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
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.
🪪 License
Licensed under the MIT license which is available here, MIT license.
💖 Support
🧬 Related
🧵 Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. 🔍
@igorskyflyer/recursive-readdir
📖 Provides recursive readdir() and readdirSync() functions. 📁
@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
🐲 A dead simple npm module that counts Adblock filter rules.🦘
🃏 Scrambles (rearranges randomly) Strings and Arrays. 🎋
👨🏻💻 Author
Created by Igor Dimitrijević (@igorskyflyer).
