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

tidydir

v1.0.4

Published

Utility for handling (read, write, remove) files and directories

Downloads

7

Readme

Tidy Dir

Simplified way to work with files and folders in NodeJS.

How to use

Prerequisite

Node JS

https://nodejs.org/

Examples

mkTree()

Makes directiories, inclusing the necessary path. For example ./foo/bar/hello if foo/bar does not exists, it will make it. Returns a promise. If directories exist returned promise will be resolved. If it can't make any of the directiories, the returned promise will be rejected.

@dirs - paths of dirs | string,array

Notes:

  • Paths may use either / or \
  • if dir or any dirs in path exist already, there is no error thrown (since the desired result is already there)

mkFile()

Makes files, including the necessary path.

@files - file object @file.path - path must include filename and extension @file.content - content of the file - string @file.options - options (see fs.writeFile for node) - string (sets character encoding)|object|undefined(defaults to 'utf8', if you want the buffer obj put null as encoding)

Notes:

  • Paths may use either / or \
  • it will make any missing dirs in the filepath
  • overwrites existing files with same path (if file already exists at same path, it will overwrite it)
Possible params:
- path, content, options
- {path, content, options}, options 
- [{path,content,options}], options

//options within object overrides param options

listTree()

Returns tree content as an object with a two properties, files and dirs (both are arrays of strings).

rmFile()

Removes file(s).

rmDir()

Like the native rmdir from Node's fs module, but:

  • is promisified
  • allows multiple dirs as arugment (array of paths)

rmTree()

Removes tree(s) and all it's content (all contained files and folders).

emptyTree()

Removes all contents (files and directories) within a given path.

readTree()

path, options, filter
{path, options, filter}, options, filter
[path], options, filter
[{path, options, filter}], options, filter

readFile()

Reads files For single file path returns single file obj for array of file paths returns array of file objects

@files - file object @file.path - path must include filename and extension @file.options - options (see fs.writeFile for node) - string (sets character encoding)|object|undefined(defaults to 'utf8', if you want the buffer obj put null as encoding)

Notes:

  • For non-text items you should set options = null or options.encoding = null
path, options, filter
{path, options}, options, filter
[path], options, filter
[{path, options}], options, filter

mk()

Will figure out based on path (see tidypath isFile()) and will make a tree or file accordingly.

Put differently, automagical synonym for both mkFile() and mkTree().

read()

Will figure out based on path (see tidypath isFile()) and will read a tree or file accordingly.

Put differently, automagical synonym for both readFile() and readTree().

rm()

Will figure out based on path (see tidypath isFile()) and will remove a tree or file accordingly.

Put differently, automagical synonym for both rmFile() and rmTree().

empty()

Synonym for emptyTree()

list()

Synonym for listTree()

ls()

Synonym for listTree()