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 🙏

© 2025 – Pkg Stats / Ryan Hefner

folder-snap

v1.0.9

Published

Snap your folders into portable text files and restore them anywhere, with gitignore support

Readme

Folder Snap

Snap your folders into portable text files and restore them anywhere! Perfect for backing up, sharing, or archiving project structures while respecting .gitignore rules.

✨ Features

  • 📸 Snap Folders: Convert entire folder structures into portable text files
  • 🔄 Restore Anywhere: Recreate folders from snap files with perfect fidelity
  • 🚫 Smart Ignoring: Automatically ignores node_modules, venv, and respects .gitignore
  • 📊 Detailed Stats: Get comprehensive information about folder contents
  • 🎯 Selective Processing: Choose to include/exclude hidden files
  • 💾 Perfect Restoration: Maintains exact folder hierarchy and file contents
  • 🖥️ CLI & Library: Use from command line or integrate into your projects

🚀 Installation

npm install folder-snap

Or install globally for CLI usage:

npm install -g folder-snap

📖 Usage

CLI Usage

# Snap a folder to a .snap file
folder-snap pack ./my-project

# Snap with custom output name
folder-snap pack ./my-project ./backup.snap

# Restore from snap file
folder-snap unpack ./my-project.snap ./restored-project

# Get folder statistics
folder-snap stats ./my-project

Library Usage

const FolderSnap = require("folder-snap");

const snap = new FolderSnap({
  encoding: "utf8",
  gitignoreFile: ".gitignore",
  includeHidden: false,
});

// Snap folder to text file
const result = snap.folderToText("./my-project", "./my-project.snap");
console.log(result);

// Restore from snap file
const restored = snap.textToFolder("./my-project.snap", "./restored-project");
console.log(restored);

// Get folder statistics
const stats = snap.getFolderStats("./my-project");
console.log(stats);

🔧 API Reference

Constructor Options

const snap = new FolderSnap({
  encoding: "utf8", // File encoding (default: 'utf8')
  gitignoreFile: ".gitignore", // Gitignore file name (default: '.gitignore')
  includeHidden: false, // Include hidden files/folders (default: false)
});

Methods

folderToText(folderPath, outputPath)

Snaps a folder structure to a text file.

Parameters:

  • folderPath (string): Path to the source folder
  • outputPath (string): Path for the output snap file

Returns: Object with success status, output path, and statistics

textToFolder(snapFilePath, outputFolder)

Restores a folder structure from a snap file.

Parameters:

  • snapFilePath (string): Path to the snap file
  • outputFolder (string): Path for the restored folder

Returns: Object with success status, output folder, and statistics

getFolderStats(folderPath)

Gets statistics about a folder.

Parameters:

  • folderPath (string): Path to the folder

Returns: Object with file count, directory count, and total size

🚫 Default Ignored Patterns

The library automatically ignores these patterns:

  • node_modules/
  • venv/
  • .git/
  • *.log
  • .DS_Store
  • Thumbs.db
  • Custom patterns from .gitignore

📄 Snap File Format

The generated snap file contains:

# Folder Snap Export
# Generated on: 2024-01-01T12:00:00.000Z
# Source: my-project
# Files: 25, Directories: 8

<FOLDER_SNAP_START>
{
  "metadata": {
    "timestamp": "2024-01-01T12:00:00.000Z",
    "sourceFolder": "my-project",
    "totalFiles": 25,
    "totalDirectories": 8
  },
  "structure": [
    {
      "type": "directory",
      "path": "src",
      "name": "src"
    },
    {
      "type": "file",
      "path": "src/index.js",
      "name": "index.js",
      "content": "console.log('Hello World!');",
      "size": 26
    }
  ]
}
<FOLDER_SNAP_END>

💡 Examples

Basic Usage

const FolderSnap = require("folder-snap");

const snap = new FolderSnap();

// Snap React project
snap.folderToText("./my-react-app", "./backup.snap");

// Later, restore from snap
snap.textToFolder("./backup.snap", "./restored-react-app");

With Custom Options

const snap = new FolderSnap({
  includeHidden: true, // Include hidden files
  gitignoreFile: ".myignore", // Custom ignore file
});

const stats = snap.getFolderStats("./my-project");
console.log(`Project has ${stats.files} files (${stats.totalSizeFormatted})`);

Error Handling

const result = snap.folderToText("./nonexistent", "./output.snap");

if (!result.success) {
  console.error("Error:", result.error);
} else {
  console.log("Success!", result.stats);
}

CLI Examples

# Snap current directory
folder-snap pack ./

# Snap with custom name
folder-snap pack ./my-project ./project-backup.snap

# Restore to specific location
folder-snap unpack ./project-backup.snap ./restored

# Check folder stats before snapping
folder-snap stats ./my-project

🎯 Use Cases

  • 📦 Project Backup: Create lightweight backups of your projects
  • 🤝 Code Sharing: Share entire project structures in a single file
  • 📚 Documentation: Archive project snapshots for documentation
  • 🚀 Migration: Move projects between different environments
  • 📝 Version Control: Store project states outside of git
  • 🔄 Quick Deploy: Package projects for quick deployment
  • 💾 Space Saving: Human-readable alternative to zip files

🧪 Testing

Run the included test:

npm test

Or run the example:

node test.js

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details

📈 Changelog

v1.0.0

  • 🎉 Initial release with folder-snap branding
  • 📸 Snap folders to portable text files
  • 🔄 Restore folders from snap files
  • 🚫 Smart gitignore support
  • 🖥️ CLI interface with intuitive commands
  • 📊 Comprehensive folder statistics
  • 🎯 Selective file processing options