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-sniff

v1.6.3

Published

File system sniffer

Downloads

35

Readme

FS Sniff

Simple helper sniffing for files based on provided patterns.

Methods

file(path)

Searches for local files based on passed parameters.

If you searching for docs/readme.md file you can call file() method passing path as a parameter.

require('fs-sniff')
  .file('docs/readme.md')     // file location
  .then((file) => {
    return console.log(file)
  }).catch((error) => {
    console.log(error)
  })

Method returns promise. If file exist promise resolve with file object, which contains 2 parameters:

  • path - file location (string)
  • stats - fs.Stats object

If you would like to check if file exists in more than one directory you can call file() method passing into it an array of paths, eg.:

require('fs-sniff')
  .file([
    'docs/readme.md',          // first possible location
    'temp/docs/readme.md'      // second possible location
  ]).then((file) => {
    return console.log(file)
  }).catch((error) => {
    console.log(error)
  })

file(path, options)

Method file allows "sniffing" options object to be passed as a second parameter. It should have either of (or both) properties:

  • index - array of index files
  • ext - file extensions you are looking for
  • type file type string: 'any' (default), 'file', 'dir'

Below code will look for public/index.html and public/index.htm in that order

require('fs-sniff').file('public', {
  index: ['index.html', 'index.htm'],
  //type: 'file'  // set by default because of 'index' property
}).then((file) => {
  return console.log(file)
})

Another example, looking for directory:

  • lib/script/

and files:

  • lib/script.jsx,
  • lib/script.js
  • lib/script.cofee

in that order.

require('fs-sniff').file('lib/script', {
  ext: ['jsx', 'js', 'coffee'],
  type: 'any'
}).then((file) => {
  return console.log(file)
})

list(path, options)

Returns list of files from path location. I takes two parameters:

  • path location string
  • opts object as an optional parameter with two properties
    • depth recursive listing depth (default: 0)
    • type file type string: 'any' (default), 'file', 'dir'
require('fs-sniff')
	.list('path/to/a/folder', {type: 'dir', depth: 2})
	.then((list) => {
		console.log(JSON.stringify(list, null, 2))
	})

Should output something like:

[
  "directory-1",
  "directory-1\subcategory-1",
  "directory-1\subcategory-2",
]

tree(path, options)

Returns array of dir objects from path location. Method takes two parameters: poath and options object with internal properties listed below.

  • path location string
  • opts object as an optional parameter with two properties
    • depth recursive listing depth (default: 0)
    • rootPrefix if false it won't prefix uri properties with root directory
require('fs-sniff')
	.tree(config.blog.path, {rootPrefix: 'false', depth: 2})
	.then((list) => {
		console.log(JSON.stringify(list, null, 2))
	})

Should output something like:

{
  "name": "example",
  "uri": "",
  "path": "full/path/to/directory",
  "dirs": [
    /* nested dir objects */
  ],
  "files": [
    "index.js",
    "another-file.md
  ]
}

Notice that uri property is empty ("") because opts.rootPrefix parameter passed to a method is set to false