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

matched

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matched

Super fast globbing library.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
131K
decreased by-12.26%
Maintainers
1
Weekly downloads
 
Created
Source

matched NPM version

Super fast globbing library.

Why?

Install

Install with npm:

npm i matched --save-dev

Usage

├── node_modules/...
├── index.js
├── README.md
└── test/test.js

API

matched(patterns, options)

See supported globby options.

patterns

Required

Type: string|array

See minimatch for options and supported patterns.

options

Type: object

exclusions

Matched excludes certain directories to speed up search.

Type: array

Default: ['.git', 'node_modules', 'temp', 'tmp']

Pass an array of additional directories to exclude:

matched(['**/*.js'], {omit: ['vendor']});

See node-glob for all supported options.

Tests

In the command line, run:

mocha

Globbing patterns

Just a quick overview.

  • * matches any number of characters, but not /
  • ? matches a single character, but not /
  • ** matches any number of characters, including /, as long as it's the only thing in a path part
  • {} allows for a comma-separated list of "or" expressions
  • ! at the beginning of a pattern will negate the match

Various patterns and expected matches.

See multimatch if you need to match against a list instead of the filesystem.

Why?

Problem

Let's say you want to return all of the .js files in a project, excluding node_modules and a few other similar directories. Normally you would need to do something like this:

glob(['**/*.js', '!**/node_modules/**']);

The problem with this approach is that typically even the excluded file paths are fully expanded before the result set is returned. e.g. all of the files in node_modules would be scanned first.

Solution

Matched allows you to exlude directories before they reach globby. In a nutshell, matched uses fs.readdirSync to build up a list of directories relative to the cwd, then for each (non-excluded) directory matched passes the glob pattern to globby. The following is all that's needed to return all of the .js files in a project.

var matched = require('matched');
matched('**/*.js');
//=> ['index.js', 'test/test.js']

Try it, you'll be surprised how fast it is comparatively. However, I'm not sure how well this approach will scale with complicated patterns. See the tests for the use cases that are covered so far. Feel free to create pull requests or issues if you have suggestions for improvement.

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on June 26, 2014.

Keywords

FAQs

Package last updated on 26 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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