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

find-replace-in-files

v1.0.4

Published

Simple and lightweight package that finds the text in files in the directories and replaces it with new content.

Downloads

8

Readme

find-replace-in-files

Simple and lightweight package that finds the text in files in the directories and replaces it with new content.

Installation

You will need Node.js 18+ and npm installed on your local development machine.

npm i find-replace-in-files

Usage

basic usage

This package is an ESM-only module and you are not able to import it with require(). The library's return is an object with the following properties 'matchFound', 'numberOfFiles' and 'filesList' which are determined operations in files.

import { findReplaceInFiles } from "find-replace-in-files";

const result = await findReplaceInFiles({
	dirPath: "./src",
	find: /foo/g,
	replace: "bar"
});

console.log(result); // result returns an object with { matchFound, numberOfFiles, filesList } properties

Options

| Name | Type | Description | Requirement | | :------ | :----------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------: | | dirPath | string | Path to find all the files in the directory and subdirectories. | Required | | find | RegExporstring | Regex or string to find. Note that if a string is used, only the first match in each file will be replaced. To replace all occurrences of a pattern within a string using a regular expression, add the 'g' flag to the end of your regex pattern. | Required | | replace | string | The string will be used as a replacement for the original string. string. | Required | | files | array | An array of strings used to locate specific files. It can be used to search for files by extension, filename, or part of a filename. | Optional | | log | string or null | By default, after completing the operation, the library generates a log indicating the number of matches and changed files with the list of array of file names modified. To customize this message, provide a string that will be logged upon successful completion of the replacement. To disable logging entirely, pass null as the value. | Optional |

Example with required and optional parameters

import { findReplaceInFiles } from "find-replace-in-files";

const result = await findReplaceInFiles({
	dirPath: "./dist/folder",
	find: /foo/g, // Or string to replace first occurrence. example: "foo"
	replace: "bar",
	filse: [".js", ".ts", ".html", ".txt", ".docx", "file.jsx", "filenames", "index.min.js"],
	log: null // Or string to override default message. example: "Files have been successfully replaced."
});

License

(MIT License)

Copyright 2024, Saeed Rohani

Issues/Requests

Feel free to submit questions at: github.com/saeed-rohani/find-replace-in-files/issues