Ecosyste.ms: Awesome
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: 2 days 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 (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T22:53:42.000Z (over 1 year ago)
- Last Synced: 2024-09-25T20:54:57.667Z (about 1 month 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
## ['C', 'h', 'a', 'r', 's'] in 'String'
🪐 Provides ways of testing whether an array of chars is present inside a given String. ☄
✨ Since `v.2.0.0` `chars-in-string` is a hybrid module that supports both CommonJS (legacy) and ES modules, thanks to [Modern Module](https://github.com/igorskyflyer/npm-modern-module).
### 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 **beggining** of the `String`, at the **end** or **anywhere** (default).
```ts
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.
```ts
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:
```shell
npm i "@igor.dvlpr/chars-in-string"
```and then use it like:
```js
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
```