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 |
4 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 |
28 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-comb, 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 of zero or more strings or a string | yes | Array of zero or more strings or a single string to be removed 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 see an error, raise an issue.
- If you want a new feature but can't code it up yourself, also raise an issue. Let's discuss it.
- If you tried to use this package, but something didn't work out, also raise an issue. We'll try to help.
- If you want to contribute some code, fork the monorepo via BitBucket, then write code, then file a pull request via BitBucket. We'll merge it in and release.
In monorepo, npm libraries are located in packages/
folder. Inside, the source code is located either in src/
folder (normal npm library) or in the root, cli.js
(if it's a command line application).
The npm script "dev
", the "dev": "rollup -c --dev --silent"
builds the development version retaining all console.log
s with row numbers. It's handy to have js-row-num-cli installed globally so you can automatically update the row numbers on all console.log
s.
Licence
MIT License
Copyright (c) 2015-2019 Roy Revelt and other contributors