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

glob-possible-parent

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-possible-parent

Find out if a path can be a parent of a file you are looking for

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

glob-possible-parent Build Status Coverage Status

Find out if a path can be a parent of a file you are looking for.

Installation

$ npm install glob-possible-parent

Usage

This library can be used with a glob matching library (micromatch, minimatch, etc.) to create a matcher that will match not only the given pattern, but also any parent directories. This can be used to optimize glob implementation, and prevent unnecessary disk access, by immediately ruling out directories which can't contain any matching files.

var gpp = require('glob-possible-parent');
var micromatch = require('micromatch'); // you can use any matcher implementation here

// 1. use gpp() to transform the original pattern into an array of patterns which can be passed to the matching library
// 2. create a RegExp from each pattern
// 3. join all created RegExps

var gppRegExp = new RegExp('^(?:\\/$|(?:' + gpp('src/js/**/*.js').map(function (pattern) {
	return micromatch.makeRe(pattern, { dot: true }).toString().slice(1, -1);
}).join('|') + '))$');

console.log(gppRegExp.test('src')); // => true
console.log(gppRegExp.test('src/js')); // => true
console.log(gppRegExp.test('src/js/x.js')); // => true

console.log(gppRegExp.test('src/css')); // => false

License

Copyright (c) 2016 Martin Kolárik. Released under the MIT license.

Keywords

FAQs

Package last updated on 02 Apr 2016

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