Giter Site home page Giter Site logo

igorskyflyer / npm-str-is-in Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 237 KB

๐Ÿงต Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. ๐Ÿ”

Home Page: https://www.npmjs.com/package/@igor.dvlpr/str-is-in

License: MIT License

TypeScript 100.00%
array back-end check igorskyflyer includes js module node nodejs package

npm-str-is-in's Introduction

" ".IsIn([ ])


๐Ÿงต Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. ๐Ÿ”




๐Ÿ’– Support further development

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! ๐Ÿ™๐Ÿ˜Š


Donate to igorskyflyer

@igorskyflyer



๐Ÿ•ต๐Ÿผ Usage

Install it by executing:

npm i "@igor.dvlpr/str-is-in"

๐Ÿคน๐Ÿผ API

ComparatorCallback

A type named ComparatorCallback is exposed and used as a signature for the comparator parameter of the strIsIn() function.


type ComparatorCallback = (entry: string, value: string) => boolean

strIsIn()

strIsIn(value: string, entries: string[], comparator?: ComparatorCallback): boolean

Checks whether the given String is present in the provided array of Strings.


findMatch

findMatch.full(value: string, entries: string[]): string

Performs a case-insensitive and full-matching search for a given value inside an array of values and returns the found match (with the original case being preserved). If none is found an empty string is returned.


findMatch.partial(value: string, entries: string[]): string

Performs a case-insensitive and partial-matching search for a given value inside an array of values and returns the found match (with the original case being preserved). If none is found an empty string is returned.


Examples

import { strIsIn, findMatch } from '@igor.dvlpr/str-is-in'

// #1 - use default Comparator, non-existent string, full match
console.log(strIsIn('bin', ['abc', 'cde', 'def', 'binary'])) // prints false

// #2 - use default Comparator, existing string, full match
console.log(strIsIn('bin', ['abc', 'cde', 'bin', 'adc'])) // prints true

// #3 - empty array passed
console.log(strIsIn('bin', [])) // prints false

// #4 - custom Comparator, partial match
console.log(strIsIn('bin', ['abc', 'cde', 'def', 'binary'], (entry, value) => entry.indexOf(value) > -1)) // prints true

// #5 - custom Comparator, partial match
console.log(strIsIn('bin', ['abc', 'cde', 'def', 'HellobinaryWorld'], (entry, value) => entry.indexOf(value) > -1)) // prints true

// #6 - custom Comparator, partial match, non-existent string
console.log(
  strIsIn('t', ['abc', 'cde', 'def', 'HellobinaryWorld'], (entry, value) => entry.toLowerCase() === value.toLowerCase())
) // prints false

// #7 - custom Comparator, partial match, existing string, case-insensitive
console.log(strIsIn('WORLD', ['abc', 'cde', 'def', 'world'], (entry, value) => entry.toLowerCase() === value.toLowerCase())) // prints true

// #8 - custom Comparator, partial match, case-insensitive
console.log(
  strIsIn(
    'WORLD',
    ['abc', 'cde', 'def', 'HellobinaryWorld'],
    (entry, value) => entry.toLowerCase().indexOf(value.toLowerCase()) > -1
  )
) // prints true

// #9 - full match-finding
console.log(findMatch.full('WORLD', ['abc', 'cde', 'world', 'HellobinaryWorld'])) // prints 'world'

// #10 - partial match-finding
console.log(findMatch.partial('WORLD', ['abc', 'cde', 'world-foo', 'HellobinaryWorld'])) // prints 'world-foo'

๐Ÿชช License

Licensed under the MIT license which is available here, MIT license.


๐Ÿงฌ Related

@igor.dvlpr/pathexists

๐Ÿงฒ Provides ways of properly checking if a path exists inside a given array of files/directories both on Windows and UNIX-like operating systems. ๐Ÿ—บ

@igor.dvlpr/valid-path

๐Ÿงฐ Provides ways of testing whether a given value can be a valid file/directory name. ๐Ÿœ

@igor.dvlpr/regkeys

๐Ÿ“š An NPM package for fetching Windows registry keys. ๐Ÿ—

@igor.dvlpr/extendable-string

๐Ÿฆ€ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐Ÿช€

@igor.dvlpr/normalized-string

๐Ÿ’Š NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐Ÿ“ฎ



Provided by Igor Dimitrijeviฤ‡ (@igorskyflyer).

npm-str-is-in's People

Contributors

igorskyflyer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

npm-str-is-in'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.