npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-scanner

v1.0.1

Published

Scans a given directory and get back a tree with the results of the path and its sub-paths.

Downloads

1

Readme

fs-scanner

Scans a given directory and get back a tree with the results of the path and its sub-paths.

What aims to?

This module aims to give you an object with a tree to get any directory found using the "dot" notation, an array collection of the sub-paths and some other options to help you more.

Where it can be used?

  • It can be used only with node because it uses the "fs" modules of node.js

Where it can not be used?

  • It cannot be used as a browser module because it uses the "fs" module of node.js, although in this repository I'm going to give you some examples which how can you make use of it as a simple workaround.

Pre-requisites

  1. A html file to use as template.
  2. The html file must include a div or any element with an id attribute to mount the component.
  3. The components path or a file with all the routes. (see react-router v4 docs)

Installation

npm install --save fs-scanner or yarn add fs-scanner

Usage

Whenever you import it, it will give you a class to create instances.

const Scanner = require('fs-scanner')

After having it imported you will need to pass some options to scan:

| name | type | default | description | | ------------- | ------------ | --------- | ------------------------------------------------------------------------------| | path | string | __dirname | Absolute path of the directory to scan. | | index | string | '_' | A name used in the tree to access to the root of each directory. | | prefix | object | null |This lets you to prepend a text to alter the name of each directory. | | suffix | object | null |This lets you to append a text to alter the name of each directory. | | ignore | string/array | null | You can ignore a path using piece of string or an array with the name of the directories. |

Examples:

const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)

const scanner = new Scanner()

console.log(scanner)

/*
Scanner {
  _path: '/Users/Owner/Projects/ScanDirectories',
  _ignore: null,
  _index: '_',
  _prefix: null,
  _suffix: null,
  _cwd: 'ScanDirectories',
  _directory: null,
  _isIgnored: false,
  _tree:
   { cwd:
      { _: '/Users/Owner/Projects/ScanDirectories',
        dist: [Object],
        src: [Object] } },
  _collection:
   [ '/Users/Owner/Projects/ScanDirectories',
     '/Users/Owner/Projects/ScanDirectories/dist',
     '/Users/Owner/Projects/ScanDirectories/src',
     '/Users/Owner/Projects/ScanDirectories/src/client',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets/css',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets/css/vendor',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets/fonts',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets/img',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets/js',
     '/Users/Owner/Projects/ScanDirectories/src/client/assets/js/vendor',
     '/Users/Owner/Projects/ScanDirectories/src/client/components',
     '/Users/Owner/Projects/ScanDirectories/src/client/components/about',
     '/Users/Owner/Projects/ScanDirectories/src/server',
     '/Users/Owner/Projects/ScanDirectories/src/server/router',
     '/Users/Owner/Projects/ScanDirectories/src/shared' ] }
*/

Custom path:

const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)

const scanner = new Scanner({
  path: root('./src')
})

console.log(scanner.tree)
console.log(scanner.collection)

/*
{ src:
   { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
     client:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client',
        assets: [Object],
        components: [Object] },
     server:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/server',
        router: [Object] },
     shared:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' } } }
[ '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets/css',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets/css/vendor',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets/fonts',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets/img',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets/js',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/assets/js/vendor',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/components',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/components/about',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/server',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/server/router',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' ]
*/

Ignoring:

const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)

const scanner = new Scanner({
  path: root('./src'),
  ignore: '/assets',
})

console.log(scanner.tree)
console.log(scanner.collection)

/*
{ src:
   { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
     client:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client',
        components: [Object] },
     server:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/server',
        router: [Object] },
     shared:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' } } }
[ '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/components',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/components/about',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/server',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/server/router',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' ]
*/

Ignoring array:

const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)

const scanner = new Scanner({
  path: root('./src'),
  ignore: ['/assets', 'server'],
})

console.log(scanner.tree)
console.log(scanner.collection)

/*
{ src:
   { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
     client:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client',
        components: [Object] },
     shared:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' } } }
[ '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/components',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/client/components/about',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' ]
*/

Using prefix and suffix:

const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)

const scanner = new Scanner({
  path: root('./src'),
  ignore: ['/assets', 'server'],
  prefix: {
    client: 'prefijo',
  },
  suffix: {
    client: 'sufijo',
  },
})

console.log(scanner.tree)
console.log(scanner.collection)

/*
{ src:
   { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
     client:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo',
        components: [Object] },
     shared:
      { _: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' } } }
[ '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo/components',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo/components/about',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' ]
*/

Using a custom index:

const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)

const scanner = new Scanner({
  path: root('./src'),
  ignore: ['/assets', 'server'],
  prefix: {
    client: 'prefijo',
  },
  suffix: {
    client: 'sufijo',
  },
  index: '__root__',
})

console.log(scanner.tree)
console.log(scanner.collection)

/*
{ src:
   { __root__: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
     client:
      { __root__: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo',
        components: [Object] },
     shared:
      { __root__: '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' } } }
[ '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo/components',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/prefijo/client/sufijo/components/about',
  '/Users/norman/Projects/2017/jul/github/personal/ScanDirectories/src/shared' ]
*/

Maintainers:

Image of Mantainer Norman Carcamo NPM - modules