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

folder-sync

v1.3.0

Published

Provides a class which synchronously takes a snapshot of a directory and its contents.

Downloads

8

Readme

folder-sync

Provides a class which synchronously takes a snapshot of a directory and its contents.
Usage:

var Folder = require('folder-sync');

var folder = new Folder('/path/to/directory');
var readme = folder.findFile('README.md');

readme.write('This is my readme!');
readme.read(); // => "This is my readme!"
readme.isFile; // => true

Installation

npm install folder-sync --save-dev

Disclaimer

I DON'T recommend using this module on a web-facing environment. This is because everything in this module is done synchronously, meaning it's a blocking process. I primarily use it for Grunt tasks.

Class: Folder

Creation:
var folder = new Folder('/path/to/directory');
A Folder represents contents of a directory on the file system. It does not update itself - it's just a snapshot.

folder.files
An array of Item objects, which represent the files in the folder. This does not include dot-files.

folder.folders
An array of Item objects, which represent the folders in the folder. This does not include dot-files.

folder.dotFiles
An array of Item objects, which represent the dot-files in the folder.

folder.dotFolders
An array of Item objects, which represent the dot-folders in the folder.

folder.allFiles
An array of Item objects, which represent all files in the folder (dot-files included).

folder.allFolders
An array of Item objects, which represent all folders in the folder (dot-folders included).

folder.findFile(name)
Searches the folder for a file with the given name (e.g. myFile.txt), and returns an Item object of that file. If not found, it returns null.

folder.findFolder(name)
Same as above, but for folders instead of files.

folder.filterFiles(regexp [, group])
Returns an array of file Item objects that contain the given pattern. By default, it won't return dot-files, but the optional group argument can be dot to only return dot-files, or all to return any type of file.

folder.filterFolders(regexp [, group])
Same as above, but for folders instead of files.

Class: Item

item.name
The name of the item (e.g. myFile.txt)

item.dirname
The path to the item's parent directory (e.g. /path/to)

item.path
The entire path to the item (e.g. /path/to/myFile.txt)

item.bytes
The byte-size of the item.

item.bytesOnDisk
The number of bytes that the item takes up on the disk.

item.changed
An instance of Date, which is the last time the item was changed in any way (contents, permissions, properties, etc.)

item.modified
An instance of Date, which is the last time the item's contents were changed.

item.accessed
An instance of Date, which is the last time the item was accessed in any way.

item.created
An instance of Date, which is the time when the item was created.

item.isFile
Boolean. Whether or not the item is a file or not.

item.isDirectory
Boolean. Whether or not the item is a directory or not.

item.isFolder
Same as item.isDirectory.

item.read()
Returns the text content of the file, as a string.
If the item is not a file, returns undefined.

item.write(string)
Overwrites the file contents with string, and returns true.
If the item is not a file, returns undefined.

item.readFolder()
Returns an instance of Folder which represents this item.
If the item is not a directory, returns undefined.