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

file-regex

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-regex

Find files by using regex

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
480
increased by11.63%
Maintainers
1
Weekly downloads
 
Created
Source

file-regex Build Status npm version

Blazing Fast matching file finder for the given regex pattern.
This library neither loads up the CPU nor does the job sequentially, instead under the hood, it uses lib-promise-pool with concurrency = 10(default). Hence 10 directories are searched concurrently.

Please visit this wiki for V2.x Docs

Installation

npm install file-regex -S

Usage

Assume the below folder structure:

  - file1.js
  - file2.js
  - file3.ts
  + dir1
    - file4.ts
    - file5.js
  + dir2
    - file6.js
    + dir3
      + dir4
        test1.txt

  1. Example (file-name regex match):
import FindFiles from 'file-regex'

const result = await FindFiles(__dirname, /\.js$/);

console.log(result)
// [{dir: __dirname, file: file1.js}, {dir: __dirname, file: file2.js}]

  1. Example (file-path + file-name regex match) If you want to match the absolute path for the files against the regex, then specify global flag (for ex: /\dir3.*\.js$/g):
import FindFiles from 'file-regex'

const result = await FindFiles(__dirname, /\/dir1\/.*?\.js$/g, 5);

console.log(result)
// [{dir: __dirname, file: file5.js}]

The above example doesn't match the files in other directories except dir1

Documentation

FindFiles(dir, pattern, depth = 0, options = {concurrency: 10})

ParamDescription
dirBase Directory where the search would begin
patternRegex-Pattern for testing the matching files. If a global regex (for ex: /\/dir3/g) is used, then the entire path will be checked for a match
depthNumber of recursions into the directories upto which the file search shall proceed. Defaults to 0
optionsOptions for controlling execution
options.concurrencyNumber of concurrent folder search. Defaults to 10

Contribution

I know this is very small module, but any improvements or pull request are always welcome.

Thanks to the contributors:

Roy Laurie

Keywords

FAQs

Package last updated on 30 Sep 2019

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