Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

matched

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matched - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

2

lib/async.js

@@ -11,3 +11,3 @@ 'use strict';

let promise = glob(patterns, options);
const promise = glob(patterns, options);

@@ -14,0 +14,0 @@ if (typeof callback === 'function') {

'use strict';
const path = require('path');
const util = require('util');
const glob = util.promisify(require('glob'));
const utils = require('./utils');
const { Glob } = require('glob');
module.exports = async(patterns, options) => {
let { expand, getPaths, sift, setIgnores } = utils;
const glob = (pattern, options) => {
const onMatch = utils.onMatch(pattern, options);
return new Promise((resolve, reject) => {
const globber = new Glob(pattern, options, (err, files) => {
globber.off('match', onMatch);
if (err) {
reject(err);
} else {
resolve(files);
}
});
globber.on('match', onMatch);
});
};
module.exports = async (patterns, options) => {
const { expand, getPaths, sift, setIgnores } = utils;
patterns = [].concat(patterns || []);
let opts = { cwd: '.', nosort: true, ...options };
const opts = { cwd: '.', nosort: true, ...options };
opts.cwd = path.resolve(expand(opts.cwd));
let sifted = sift(patterns, opts);
const sifted = sift(patterns, opts);
if (sifted === null) {

@@ -24,9 +41,20 @@ return Promise.reject(new Error('invalid glob pattern: ' + patterns));

let { excludes, includes } = sifted;
let config = include => setIgnores(opts, excludes, include.index);
let pending = [];
let files = [];
const { excludes, includes } = sifted;
const config = include => setIgnores(opts, excludes, include.index);
const pending = [];
const files = [];
for (let include of includes) {
pending.push(glob(include.pattern, config(include)).then(res => files.push(...res)));
const onFiles = options => {
return dirents => {
files.push(...dirents);
if (options.onFiles) {
return options.onFiles(dirents, options);
}
};
};
for (const include of includes) {
const opt = config(include);
pending.push(glob(include.pattern, opt).then(onFiles(opt)));
}

@@ -33,0 +61,0 @@

@@ -8,3 +8,3 @@ 'use strict';

module.exports = (patterns, options) => {
let { expand, getPaths, sift, setIgnores } = utils;
const { expand, getPaths, sift, setIgnores } = utils;
patterns = [].concat(patterns || []);

@@ -16,3 +16,3 @@

let sifted = sift(patterns, opts);
const sifted = sift(patterns, opts);
if (sifted === null) {

@@ -26,10 +26,22 @@ throw new Error('invalid glob pattern: ' + patterns);

let { excludes, includes } = sifted;
let config = include => setIgnores(opts, excludes, include.index);
let files = [];
const { excludes, includes } = sifted;
const config = include => setIgnores(opts, excludes, include.index);
const files = [];
for (let include of includes) {
files.push(...glob.sync(include.pattern, config(include)));
for (const include of includes) {
const dirOpts = config(include);
// simulate onMatch, for parity with async
const dirents = glob.sync(include.pattern, dirOpts);
const onMatch = utils.onMatch(include.pattern, options);
dirents.forEach(dirent => {
files.push(dirent);
onMatch(dirent);
});
if (dirOpts.onFiles) {
dirOpts.onFiles(dirents, dirOpts);
}
}
return files;
};

@@ -24,8 +24,8 @@ 'use strict';

exports.sift = (patterns, options = {}) => {
let results = { includes: [], excludes: [], globs: 0 };
const results = { includes: [], excludes: [], globs: 0 };
let index = 0;
for (let pattern of [].concat(patterns || [])) {
for (const pattern of [].concat(patterns || [])) {
if (typeof pattern !== 'string') return null;
let res = picomatch.scan(pattern);
const res = picomatch.scan(pattern);
res.pattern = path.posix.join(res.base, res.glob);

@@ -59,6 +59,6 @@ res.index = index++;

exports.setIgnores = (options, excludes, inclusiveIndex) => {
let opts = Object.assign({}, options);
let negations = [];
const opts = Object.assign({}, options);
const negations = [];
for (let exclusive of excludes) {
for (const exclusive of excludes) {
if (exclusive.index > inclusiveIndex) {

@@ -86,2 +86,18 @@ negations.push(exclusive.pattern);

/**
* Create an event listener for .on('match', ...).
*
* @param {String} pattern
* @param {Object} options
* @return {Function}
*/
exports.onMatch = (pattern, options) => {
return filepath => {
if (options && typeof options.onMatch === 'function') {
options.onMatch({ pattern, options, path: filepath });
}
}
};
/**
* Get paths from non-glob patterns

@@ -95,8 +111,38 @@ *

exports.getPaths = (paths, options = {}) => {
let resolve = fp => path.resolve(exports.expand(options.cwd), fp);
paths = paths.filter(fp => fs.existsSync(resolve(fp)));
if (options.realpath) {
return paths.map(resolve);
const resolve = fp => path.resolve(exports.expand(options.cwd), fp);
const result = [];
for (const filepath of paths) {
const onMatch = exports.onMatch(filepath, options);
const absolute = resolve(filepath);
let resolved = filepath;
if (options.absolute) {
resolved = absolute;
}
if (options.realpath) {
try {
resolved = fs.realpathSync(absolute);
} catch (err) {
continue;
}
}
if (!fs.existsSync(absolute)) {
continue;
}
if (options.onMatch) {
onMatch(resolved);
}
result.push(resolved);
}
return paths;
if (options.onFiles) {
options.onFiles(result, options);
}
return result;
};
{
"name": "matched",
"description": "Adds array support to node-glob, sync and async. Also supports tilde expansion (user home) and resolving to global npm modules.",
"version": "4.0.0",
"version": "5.0.0",
"homepage": "https://github.com/jonschlinkert/matched",

@@ -11,2 +11,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

],
"funding": "https://github.com/sponsors/jonschlinkert",
"repository": "jonschlinkert/matched",

@@ -23,3 +24,3 @@ "bugs": {

"engines": {
"node": ">=8"
"node": ">=12"
},

@@ -33,11 +34,11 @@ "scripts": {

"dependencies": {
"glob": "^7.1.3",
"picomatch": "^2.0.5"
"glob": "^7.1.6",
"picomatch": "^2.2.1"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint": "^6.8.0",
"gulp-format-md": "^2.0.0",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"rimraf": "^2.6.3"
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"rimraf": "^3.0.0"
},

@@ -104,2 +105,2 @@ "keywords": [

}
}
}

@@ -1,2 +0,2 @@

# matched [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/matched.svg?style=flat)](https://www.npmjs.com/package/matched) [![NPM monthly downloads](https://img.shields.io/npm/dm/matched.svg?style=flat)](https://npmjs.org/package/matched) [![NPM total downloads](https://img.shields.io/npm/dt/matched.svg?style=flat)](https://npmjs.org/package/matched) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/matched.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/matched)
# matched [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/matched.svg?style=flat)](https://www.npmjs.com/package/matched) [![NPM monthly downloads](https://img.shields.io/npm/dm/matched.svg?style=flat)](https://npmjs.org/package/matched) [![NPM total downloads](https://img.shields.io/npm/dt/matched.svg?style=flat)](https://npmjs.org/package/matched) [![Build Status](https://travis-ci.org/jonschlinkert/matched.svg?branch=master)](https://travis-ci.org/jonschlinkert/matched)

@@ -9,3 +9,3 @@ > Adds array support to node-glob, sync and async. Also supports tilde expansion (user home) and resolving to global npm modules.

Install with [npm](https://www.npmjs.com/):
Install with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) >=12):

@@ -41,3 +41,3 @@ ```sh

(async() => {
let files = await glob('*.txt');
const files = await glob('*.txt');
console.log(files);

@@ -60,3 +60,3 @@ //=> ['foo.txt', 'bar.txt']

```js
let files = glob.sync(['*.js']);
const files = glob.sync(['*.js']);
//=> ['utils.js', 'index.js']

@@ -70,3 +70,3 @@ ```

```js
let files = glob(['*.js'], { cwd: 'test' });
const files = glob(['*.js'], { cwd: 'test' });
console.log(files);

@@ -76,2 +76,8 @@ //=> ['test.js']

## v4.1
* Adds support for `options.onMatch()` which is passed to [node-glob](https://github.com/isaacs/node-glob) as a listener for the `match` event.
* Adds support for `options.onFiles()` to allow the user to get the files returned by each glob pattern.
* Small optimizations in logic for handling non-glob patterns that are passed for matching literal file names.
## v4.0

@@ -135,3 +141,3 @@

| --- | --- |
| 68 | [jonschlinkert](https://github.com/jonschlinkert) |
| 73 | [jonschlinkert](https://github.com/jonschlinkert) |
| 8 | [TrySound](https://github.com/TrySound) |

@@ -150,3 +156,3 @@ | 1 | [sindresorhus](https://github.com/sindresorhus) |

Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
Copyright © 2020, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

@@ -156,2 +162,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 29, 2019._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on January 15, 2020._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc