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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ai.kozlov/file-tools

v1.0.2

Published

A Node.js library for copying folders and performing file content replacements

Readme

@mpenny/file-tools

A lightweight Node.js library for copying folders and performing text replacements across all files in a folder structure.

Features

  • 📁 Copy entire folder structures recursively
  • 🔄 Copy folders with automatic text/pattern replacement in all files
  • 🎯 Filter files by extension (include/exclude)
  • 📊 Get detailed statistics about copy operations
  • 🔒 Safe handling of binary files
  • ⚡ Built on native Node.js fs promises API

Installation

npm install @mpenny/file-tools

Usage

Import the library

const { copyFolder, copyFolderWithReplace } = require('@mpenny/file-tools');

Or with ES6 imports:

import { copyFolder, copyFolderWithReplace } from '@mpenny/file-tools';

Copy a folder

Simple folder copy operation:

const { copyFolder } = require('@mpenny/file-tools');

async function example() {
  try {
    await copyFolder('./source-folder', './destination-folder');
    console.log('Folder copied successfully!');
  } catch (error) {
    console.error('Error copying folder:', error);
  }
}

example();

Copy a folder with text replacement

Copy a folder and replace text in all files:

const { copyFolderWithReplace } = require('@mpenny/file-tools');

async function example() {
  try {
    const stats = await copyFolderWithReplace(
      './template-project',
      './new-project',
      'PLACEHOLDER_NAME',
      'MyAwesomeProject'
    );
    
    console.log('Copy complete!');
    console.log(`Files processed: ${stats.filesProcessed}`);
    console.log(`Files modified: ${stats.filesModified}`);
    console.log(`Files skipped: ${stats.filesSkipped}`);
    console.log(`Directories created: ${stats.directoriesCopied}`);
  } catch (error) {
    console.error('Error:', error);
  }
}

example();

Using regular expressions for replacement

Replace using regex patterns:

const { copyFolderWithReplace } = require('@mpenny/file-tools');

async function example() {
  const stats = await copyFolderWithReplace(
    './source',
    './destination',
    /version:\s*\d+\.\d+\.\d+/g,
    'version: 2.0.0'
  );
  
  console.log(`Modified ${stats.filesModified} files`);
}

example();

Filter files by extension

Only process specific file types or exclude certain extensions:

const { copyFolderWithReplace } = require('@mpenny/file-tools');

async function example() {
  // Only replace in .js and .json files
  const stats = await copyFolderWithReplace(
    './source',
    './destination',
    'oldValue',
    'newValue',
    {
      includeExtensions: ['.js', '.json']
    }
  );

  // Or exclude binary files
  const stats2 = await copyFolderWithReplace(
    './source',
    './destination',
    'oldValue',
    'newValue',
    {
      excludeExtensions: ['.jpg', '.png', '.pdf', '.zip']
    }
  );
}

example();

API Reference

copyFolder(source, destination)

Recursively copies a folder from source to destination.

Parameters:

  • source (string): Source folder path
  • destination (string): Destination folder path

Returns: Promise<void>

Throws: Error if copy operation fails


copyFolderWithReplace(source, destination, searchValue, replaceValue, options)

Recursively copies a folder and replaces text in all files.

Parameters:

  • source (string): Source folder path
  • destination (string): Destination folder path
  • searchValue (string | RegExp): Text or pattern to search for
  • replaceValue (string): Text to replace with
  • options (object, optional):
    • excludeExtensions (string[]): File extensions to exclude from replacement
    • includeExtensions (string[]): Only process files with these extensions

Returns: Promise<CopyFolderWithReplaceStats>

Stats Object:

{
  filesProcessed: number;    // Files checked for replacements
  filesModified: number;      // Files where replacements were made
  filesSkipped: number;       // Files skipped (binary or excluded)
  directoriesCopied: number;  // Directories created
}

Throws: Error if operation fails

Use Cases

  • Project Templates: Create project templates with placeholders and generate new projects with replaced values
  • Code Generation: Copy boilerplate code and customize it for different contexts
  • Configuration Management: Duplicate configuration directories with environment-specific values
  • Documentation: Generate customized documentation from templates
  • Build Processes: Create modified copies of source code for different build targets

Requirements

  • Node.js >= 14.0.0

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.