Package Exports
- array-pull-all-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-pull-all-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-pull-all-with-glob
pullAllWithGlob - like _.pullAll but pulling stronger, with globs
Install
npm i array-pull-all-with-glob
// consume as CommonJS require():
const pullAllWithGlob = require("array-pull-all-with-glob");
// or as ES Module:
import pullAllWithGlob from "array-pull-all-with-glob";
Here's what you'll get:
Type | Key in package.json |
Path | Size |
---|---|---|---|
Main export - CommonJS version, transpiled to ES5, contains require and module.exports |
main |
dist/array-pull-all-with-glob.cjs.js |
3 KB |
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import /export . |
module |
dist/array-pull-all-with-glob.esm.js |
3 KB |
UMD build for browsers, transpiled, minified, containing iife 's and has all dependencies baked-in |
browser |
dist/array-pull-all-with-glob.umd.js |
17 KB |
Table of Contents
Pulling
Let's say you have an array of strings and another array of strings to remove from the aforementioned array. That's easy to achieve with Lodash's _.pullAll. However, what if you are not sure what to-be-removed strings exactly look like and know only how their names begin, or there are too many of them to type manually, yet all begin with the same letters? What if you need to remove 99 elements: module-1
, module-2
, ... module-99
from an array?
You need be able to put a glob in a search query, that is, a string pattern (*
), which means any character from here on.
Check it out how easy it is to achieve that using this library:
var pullAllWithGlob = require("array-pull-all-with-glob");
sourceArray = ["keep_me", "name-1", "name-2", "name-jhkgdhgkhdfghdkghfdk"];
removeThese = ["name-*"];
console.dir(pullAllWithGlob(sourceArray, removeThese));
// => ['keep_me']
Personally, I needed this library for another library, email-remove-unused-css, where I had to whitelist certain CSS classes (array of strings), removing them from another array.
API
pullAllWithGlob(
sourceArray, // input array of strings
removeThese // array of strings to pull
);
API - Input
Input argument | Type | Obligatory? | Description |
---|---|---|---|
sourceArray |
Array | yes | Source array of strings |
removeThese |
Array | yes | Array of strings to remove from the source array |
otps |
Plain object | no | An 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 key |
Type | Default | Description |
---|---|---|---|
{ | |||
caseSensitive |
Boolean | true |
Are 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
Type | Description |
---|---|
Array | Array of strings with elements removed |
Test
$ npm test
For unit tests we use AVA, Istanbul CLI and JS Standard notation.
Contributing
If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.
If you tried to use this library but it misbehaves, or you need advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.
If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Prettier is enabled, so you don't need to worry about the code style.
Licence
MIT License (MIT)
Copyright © 2018 Codsen Ltd, Roy Revelt