Socket
Socket
Sign inDemoInstall

replace

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replace

Command line search and replace utility


Version published
Weekly downloads
222K
increased by1.72%
Maintainers
1
Weekly downloads
 
Created

What is replace?

The 'replace' npm package is a utility for performing search and replace operations on files. It allows you to replace text in files using a simple API, making it useful for tasks such as updating configuration files, modifying source code, or performing batch text replacements.

What are replace's main functionalities?

Basic Text Replacement

This feature allows you to replace occurrences of a specified string (in this case, 'foo') with another string ('bar') in the specified file ('file.txt'). The 'recursive' option allows the operation to be performed in all files within the specified directory, and 'silent' suppresses the output.

const replace = require('replace');

replace({
  regex: 'foo',
  replacement: 'bar',
  paths: ['file.txt'],
  recursive: true,
  silent: true
});

Regular Expression Replacement

This feature allows you to use regular expressions for more complex search patterns. In this example, any string matching the pattern 'foo' followed by one or more digits will be replaced with 'bar'.

const replace = require('replace');

replace({
  regex: /foo\d+/g,
  replacement: 'bar',
  paths: ['file.txt'],
  recursive: true,
  silent: true
});

Replacement with Function

This feature allows you to use a function to determine the replacement text. In this example, any occurrence of 'foo' will be replaced with its uppercase version.

const replace = require('replace');

replace({
  regex: 'foo',
  replacement: (match) => match.toUpperCase(),
  paths: ['file.txt'],
  recursive: true,
  silent: true
});

Other packages similar to replace

Keywords

FAQs

Package last updated on 25 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc