Git Product home page Git Product logo

npm-chars-in-string's Introduction

['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

npm-chars-in-string's People

Contributors

igorskyflyer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

npm-chars-in-string's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.