Socket
Socket
Sign inDemoInstall

@igor.dvlpr/chars-in-string

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @igor.dvlpr/chars-in-string

🪐 Provides ways of testing whether an array of chars is present inside a given String. ☄


Version published
Maintainers
1
Install size
10.3 kB
Created

Readme

Source

['C', 'h', 'a', 'r', 's'] in 'String'

🪐 Provides ways of testing whether an array of chars is present inside a given String. ☄



💖 Support further development

Donate to igorskyflyer


✨ Since v.2.0.0 chars-in-string is a hybrid module that supports both CommonJS (legacy) and ES modules, thanks to Modern Module.


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 beggining of the String, at the end or anywhere (default).



function charsInString(characters: string[], string: 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,

string: String - the String which needs to be checked,

[position: Position=Position.Any] - controls where the matching should occur, at the beggining of the String, at the end or anywhere (default),

[caseSensitive: boolean=true] - controls whether the search is case-sensitive, defalts to true.



function stringsInString(strings, string, position = Position.Any, caseSensitive = true

strings[]: string[] - the strings to search for,

string: String - the String which needs to be checked,

[position: Position=Position.Any] - controls where the matching should occur, at the beggining of the String, at the end or anywhere (default),

[caseSensitive: boolean=true] - controls whether the search is case-sensitive, defalts to true.


Usage

Install it by:

npm i "@igor.dvlpr/chars-in-string"

and then use it like:

const { charsInString, stringsInString, Position } = require('@igor.dvlpr/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

Keywords

FAQs

Last updated on 26 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc