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 |
4 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 |
None of the input arguments are mutated. That's checked by unit tests from group 4.x
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
Hi! 99% of people in the society are passive - consumers. They wait for others to take action, they prefer to blend in. The remaining 1% are proactive citizens who will do something rather than wait. If you are one of that 1%, you're in luck because I am the same and together we can make something happen.
If you want a new feature in this package or you would like to change some of its functionality, raise an issue on this repo. Also, you can email me. Just let it out.
If you tried to use this library but it misbehaves, or you need an advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo. Alternatively, you can email me.
If you don't like the code in here and would like to give advice about how something could be done better, please do. Same drill - GitHub issues or email, your choice.
If you would like to add or change some features, just fork it, hack away, and file a pull request. I'll do my best to merge it quickly. Code style is
airbnb-base
, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.
Licence
MIT License (MIT)
Copyright © 2018 Codsen Ltd, Roy Revelt