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

wrench-sui

v0.0.3

Published

A forked version of wrenchjs that includes a critical recursive file fix. Credits to the original author(s) Ryan McGrath.

Downloads

37,501

Readme

wrench.js - Recursive file operations in Node.js

While I love Node.js, I've found myself missing some functions. Things like recursively deleting/chmodding a directory (or even deep copying a directory), or even a basic line reader, shouldn't need to be re-invented time and time again.

That said, here's my attempt at a re-usable solution, at least until something more formalized gets integrated into Node.js (hint hint). wrench.js is fairly simple to use - check out the documentation/examples below:

Possibly Breaking Change in v1.5.0

In previous versions of Wrench, we went against the OS-default behavior of not deleting a directory unless the operation is forced. In 1.5.0, this has been changed to be the behavior people expect there to be - if you try to copy over a directory that already exists, you'll get an Error returned or thrown stating that you need to force it.

Something like this will do the trick:

wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up', {
    forceDelete: true
});

If you desire the older behavior of Wrench... hit up your package.json. If you happen to find bugs in the 1.5.0 release please feel free to file them on the GitHub issues tracker for this project, or send me a pull request and I'll get to it as fast as I can. Thanks!

If this breaks enough projects I will consider rolling it back. Please hit me up if this seems to be the case.

Installation

npm install wrench

Usage

var wrench = require('wrench'),
	util = require('util');

Synchronous operations

// Recursively create directories, sub-trees and all.
wrench.mkdirSyncRecursive(dir, 0777);

// Recursively delete the entire sub-tree of a directory, then kill the directory
wrench.rmdirSyncRecursive('my_directory_name', failSilently);

// Recursively read directories contents.
wrench.readdirSyncRecursive('my_directory_name');

// Recursively chmod the entire sub-tree of a directory
wrench.chmodSyncRecursive('my_directory_name', 0755);

// Recursively chown the entire sub-tree of a directory
wrench.chownSyncRecursive("directory", uid, gid);

// Deep-copy an existing directory
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up', {
    forceDelete: bool, // Whether to overwrite existing directory or not
    excludeHiddenUnix: bool, // Whether to copy hidden Unix files or not (preceding .)
    preserveFiles: bool, // If we're overwriting something and the file already exists, keep the existing
    preserveTimestamps: bool, // Preserve the mtime and atime when copying files
    inflateSymlinks: bool, // Whether to follow symlinks or not when copying files
    filter: regexpOrFunction, // A filter to match files against; if matches, do nothing (exclude).
    whitelist: bool, // if true every file or directory which doesn't match filter will be ignored
    include: regexpOrFunction, // An include filter (either a regexp or a function)
    exclude: regexpOrFunction // An exclude filter (either a regexp or a function)
});

// Note: If a RegExp is provided then then it will be matched against the filename. If a function is
//       provided then the signature should be the following:
//       function(filename, dir) { return result; }

// Read lines in from a file until you hit the end
var f = new wrench.LineReader('x.txt');
while(f.hasNextLine()) {
	util.puts(f.getNextLine());
}

// Note: You will need to close that above line reader at some point, otherwise
// you will run into a "too many open files" error. f.close() or fs.closeSync(f.fd) are
// your friends, as only you know when it is safe to close.

Asynchronous operations

// Recursively read directories contents
var files = [];
wrench.readdirRecursive('my_directory_name', function(error, curFiles) {
    // curFiles is what you want
});

// If you're feeling somewhat masochistic
wrench.copyDirRecursive(srcDir, newDir, {forceDelete: bool /* See sync version */}, callbackfn);

Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)