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

profs

v1.1.1

Published

A promissory fs module with extra helpful goodness

Downloads

14

Readme

Build Status Coverage Status dependencies Status

Profs exports the primisified fs library and includes multiple customized implimentation from fs-extra such as walk, touch, and mkdirp.

mkdirp

Acts like the linux command "mkdir -p" and creates the full path to a directory. mkdirp Will not throw EEXIST or ENOENT but will throw for any other error.

const fs = require('profs')
var path = 'this/doesnt/exit/yet'

fs.mkdirp(path).then(() => console.log('done!'))

touch & touchp

Acts like the linux command "touch" and creates an empty file. touchp will create the path to the file if it doesn't exist.

fs.touch('to/my/file.txt').then(() => console.log('done!'))

walk

Recursively walks a given path and produces a File tree.

fs.walk('path/to/dir').then( tree_root => {
  var everything = tree_root.flatten()
  tree_root.children.forEach(node => { /*...*/ })
})

The options include a file filter function which is provided a File object and must return true to include it in the tree.

examples

// get all '.js' files
var options = {
  filter: file => file.isDirectory || file.endsWith('.js')
}
fs.walk('path/to/dir', options).then( tree_root => {
  var js_files = tree_root.flatten().filter(file => file.isFile)
})
// get all '.js' file names using `onFile` callback
var js_files = []

var options = {
  filter: file => file.isDirectory || file.basename.endsWith('.js'),
  onFile: (file, parent) => js_files.push(file.basename)
}

fs.walk('..', options).return(js_files)

API

Generated with dox

File(filepath:String, dirname:String, basename:String)

The file object contains the dirname, basename, children, isFile or isDirectory value, and a stat() function.

File.each(fn:Function, leaves_first:Boolean)

Iterates a callback over all children, if the callback produces a promise it will resolve before subsequent children are iterated over.

If the leaves_first parameter is truthy the callback will iterate over the tree in a leaf-to-root direction.

File.flatten(filter:Function)

Flattens all File nodes into a single flat array.

walk(root:String, opts:[object Object])

Walk will recursively walk a directory structure creating a file tree as it progresses. The file tree is a composite of "nodes" where each node is a File object and may be traversed by the File.children property; File.children is an array of File objects.

Walk will return the root node once the promised is fulfilled.

options.filter is a filter function on each node which determines if a node will be included, or excluded, from the file tree. The filter option may also be an object with a file and directory filter function such as { file: f=>true, directory: d=>true }; These explicit filter functions are passed either only files or directories respectively.

The onFile and onDirectory functions are handler functions which are pass the file or directory, the parent directory, and the options passed to the walk function (if any).

The filter, if truthy, will flatten the file tree before it is returned. This may also be a filter function to return only specific Files.

The promissory chain will wait for all `filter`, `onFile`, `onDirectory` callbacks to finish if they return a promise; returning a promise is not necessary.

mkdirp(filepath:String)

Creates all non-existing directories in a root-to-leaf direction after checking if the leaf doesn't exist. The root promise should be fulfilled in a race-tolerant way ( EEXIST are allowed after an ENOENT )

touch(path:String|Buffer, truncate:Boolean, mode:Integer)

Creates a file if it does not exist by opening it with 'a+', or truncating it with 'w+' when the truncate flag is truthy. Will fail if the file cannot be read or written to (EACCESS) or is an existing directory (EISDIR).

removerf(filepath:String)

Recursively removes all files and folders.
Files will be unlinked, and directories are deleted with rmdir from leaf to root.