Socket
Socket
Sign inDemoInstall

@bartozzz/scan-dir

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @bartozzz/scan-dir

Searches for files in a directory and executes a callback for each. All insecure symlinks, dotfiles and files without extension are ignored.


Version published
Maintainers
1
Install size
10.0 kB
Created

Readme

Source

scan-dir

Tests Known Vulnerabilities npm package size npm version npm dependency Status npm downloads


scan-dir searches for files in a directory and executes a callback for each. All symlinks, dotfiles and files without extension are ignored. Supports deep-loading. It can be used as an autoloader for JavaScript.

Installation

$ npm install @bartozzz/scan-dir

Usage

import scan, { scanRecursively } from "scan-dir";

scan(directory, callback);
scanRecursively(directory, callback);

Examples

Basic loading
import path from "path";
import scan, from "scan-dir";

const models = path.resolve(__dirname, "./path/to/models");
const routes = path.resolve(__dirname, "./path/to/routes");

scan(models, (fpath, fname) => {
  console.log(`Found file: ${fname} (absolute path: ${fpath})`);
});

// You can initialize modules from a directory easily:
scan(models, (fpath) => require(fpath)(some, variables, ...here));
scan(routes, (fpath) => require(fpath)(some, variables, ...here));
Deep loading
import path from "path";
import scan, { scanRecursively } from "scan-dir";

const modules = path.resolve(__dirname, "../node_modules");

// Those two calls are equivalents:
scan(modules, (fpath, fname) => /* … */, true);
scanRecursively(modules, (fpath, fname) => /* … */);

Tests

$ npm test

Keywords

FAQs

Last updated on 01 Aug 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc