JSPM

  • Created
  • Published
  • Downloads 6442
  • Score
    100M100P100Q134071F
  • License MIT

like _.includes but with wildcards

Package Exports

  • array-includes-with-glob

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-includes-with-glob) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array-includes-with-glob

Standard JavaScript

like Lodash _.includes but with wildcards

Build Status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies Coverage Status Downloads/Month

Install

$ npm install --save array-includes-with-glob

Table of Contents

How it works

Lodash _.includes can tell, does an array contain given string among its elements:

_.includes(['abcd', 'aaa', 'bbb'], 'bc')
// => true

_.includes(['abcd', 'aaa', 'bbb'], 'zzz')
// => false

This library is a supercharged version of the Lodash _.includes, letting you to put wildcards:

includesWithGlob(['xc', 'yc', 'zc'], '*c')
// => true (all 3)

includesWithGlob(['xc', 'yc', 'zc'], '*a')
// => false (none found)

includesWithGlob(['something', 'anything', 'zzz'], 'some*')
// => true (1 hit)

Wildcard means zero or more Unicode characters.

You can also do fancy things like a wildcard in the middle of a string, or multiple wildcards in a string:

includesWithGlob(['something', 'zzz', 'soothing'], 'so*ing')
// => true (2 hits)

This library will tolerate non-string values in the source array, it will skip those values.

This library is astral-character friendly, supports all Unicode characters (including emoji) and doesn't mutate the input.

API

includesWithGlob (
  sourceArray,   // input array of strings
  stringToFind   // string to look for. Can contain wildcards, "*"'s
)

API - Input

Input argument Type Obligatory? Description
sourceArray Array or String yes Source array of strings
stringToFind String yes What to look for. Can contain wildcards.

None of the input arguments are mutated.

API - Output

Type Description
Boolean Returns true if at least one stringToFind is found, else false.

Conditions when this library will throw

This library will throw an error if:

  • any of inputs is missing
  • any of inputs are of the wrong type (first-one must be an array and second must be string)

Also, if first input argument, a source array, is an empty array, the result will always be false.

Test

$ npm test

For unit tests we use AVA, Istanbul CLI and JS Standard notation.

Contributing & testing

All contributions are welcome. Please stick to Standard JavaScript notation and supplement the test.js with new unit tests covering your feature(s).

If you see anything incorrect whatsoever, do raise an issue. If you file a pull request, I'll do my best to help you to get it merged in a timely manner. If you have any comments on the code, including ideas how to improve things, don't hesitate to contact me by email. Everybody belong to Open Source community.

Licence

MIT License (MIT)

Copyright (c) 2017 Codsen Ltd, Roy Reveltas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.