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 install --save array-pull-all-with-glob
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 & testing
All contributions are welcome. Please stick to Standard JavaScript notation and supplement the test.js
with new unit tests covering your feature(s).
If you see anything incorrect whatsoever, do raise an issue. If you file a pull request, I'll do my best to help you to get it merged in a timely manner. If you have any comments on the code, including ideas how to improve things, don't hesitate to contact me by email. Everybody belong to Open Source community.
Licence
MIT License (MIT)
Copyright (c) 2017 Codsen Ltd, Roy Reveltas
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.