array-pull-all-with-glob4.12.72

pullAllWithGlob - like _.pullAll but pulling stronger, with globs

§ Quick Take

import { strict as assert } from "assert";
import pullAllWithGlob from "array-pull-all-with-glob";

assert.deepEqual(
  pullAllWithGlob(
    [
      "keep_me",
      "name-1",
      "name-2",
      "name-jhkgdhgkhdfghdkghfdk",
    ],
    ["name-*"]
  ),
  ["keep_me"]
);

§ Purpose

This program removes strings from array if they match a glob pattern. It's like Lodash's _.pullAll opens in a new tab except with globby opens in a new tab on top.

For example, we use it in email-comb to whitelist CSS class/id names.

§ API

pullAllWithGlob(sourceArray, removeThese, [opts]);

In other words, it's a function which takes three input arguments, third-one being optional (marked by square brackets).

§ API - Input

Input argumentTypeObligatory?Description
sourceArrayArrayyesSource array of strings
removeTheseArray of zero or more strings or a stringyesArray of zero or more strings or a single string to be removed from the source array
otpsPlain objectnoAn Optional Options Object. See its API below.

By the way, none of the input arguments are mutated. That's checked by unit tests from group 4.x

§ An Optional Options Object

Type: object - an Optional Options Object.

options object's keyTypeDefaultDescription
caseSensitiveBooleantrueAre comparisons case-sensitive? Default answer is yes, but you can override it to no using this.

Here are all defaults in one place for copying:

{
caseSensitive: true,
}

When unused, Optional Options Object can be also passed as a null or undefined value.

§ API - Output

TypeDescription
ArrayArray of strings with elements removed

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 array-of-arrays-into-ast 1.9.50
turns an array of arrays of data into a nested tree of plain objects
📦 array-of-arrays-sort-by-col 2.12.13
sort array of arrays by column, rippling the sorting outwards from that column
📦 array-includes-with-glob 2.12.42
like _.includes but with wildcards
📦 arrayiffy-if-string 3.11.38
Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
📦 array-group-str-omit-num-char 2.1.48
Groups array of strings by omitting number characters