Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→array-includes-with-globnext

array-includes-with-glob5.2.0

Like _.includes but with wildcards

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — INCLUDESWITH…
  • API — DEFAULTS
  • API — VERSION
  • WILDCARDS
  • PRACTICAL USA…
  • Changelog

Installation

Quick Take

Examples

  • opts.arrayVsArrayAllMustBeFound
  • Match glob patterns without matching letter case
  • Handle a glob that matches no array items
  • Match a glob against a single string

Purpose

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)

API — includesWithGlob()

The main function includesWithGlob() is imported like this:

It’s a function which takes three input arguments, third-one optional:

Input argumentTypeObligatoryDescription
source
Type: A string or array of strings
Obligatory: yes
sourceA string or array of stringsyesSource string or array of strings
whatToFind
Type: A string or array of strings
Obligatory: yes
whatToFindA string or array of stringsyesWhat to look for. Can contain wildcards. Can be one string or array of strings
options
Type: Plain object
Obligatory: no
optionsPlain objectnoOptions object. See below for its API.

None of the input arguments will be mutated by this program, we have unit tests to prove that.

The optional options object has the following shape:

KeyValueDefaultDescription
arrayVsArrayAllMustBeFound
Default: any
arrayVsArrayAllMustBeFoundany or allanyWhen a source (the first argument) is array, and what to look for (the second argument) is also array, you can have the match performed two ways: any setting will return true if any of the second argument array’s elements are found in the source array. all setting will return true only if all elements within the second argument are found within the source array.
caseSensitive
Default: true
caseSensitivebooleantruePassed directly to matcheropens in a new tab

The function returns a boolean.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

Wildcards

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.

You can also query multiple values and request that ANY (default behaviour) or ALL (optional setting) should be found in the source, to yield a result ”true“. See its example.

Practical usage

For example, object-merge-advanced can skip certain keys upon request. That request, technically, is an array, it may or may not contain globs, and this program processes all that:

mergeAdvanced(
  {
    // first object to merge
    something: "a",
    anything: "b",
    everything: "c",
  },
  {
    // second object to merge
    something: ["a"],
    anything: ["b"],
    everything: "d",
  },
  {
    ignoreKeys: ["*thing"],
  },
);

In the example above, you need to run a check through all keys of the first object and check, are any covered by the ignoreKeys array. If so, those keys would not get merged and keep their values.

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab