New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@stdlib/string-base-replace

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stdlib/string-base-replace

Replace search occurrences with a replacement string.

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
115K
decreased by-3.22%
Maintainers
4
Weekly downloads
 
Created

What is @stdlib/string-base-replace?

@stdlib/string-base-replace is a utility package for performing string replacement operations. It provides a simple and efficient way to replace parts of a string based on a search pattern and a replacement string.

What are @stdlib/string-base-replace's main functionalities?

Basic String Replacement

This feature allows you to replace a substring within a string with another substring. In this example, 'world' is replaced with 'stdlib'.

const replace = require('@stdlib/string-base-replace');
const str = 'Hello, world!';
const result = replace(str, 'world', 'stdlib');
console.log(result); // 'Hello, stdlib!'

Regular Expression Replacement

This feature allows you to use regular expressions to find and replace patterns within a string. In this example, all occurrences of 'foo' are replaced with 'baz'.

const replace = require('@stdlib/string-base-replace');
const str = 'foo bar foo';
const result = replace(str, /foo/g, 'baz');
console.log(result); // 'baz bar baz'

Function as Replacement

This feature allows you to use a function to determine the replacement string. The function receives the matched substring and can return a modified version of it. In this example, 'foo' is replaced with its uppercase version.

const replace = require('@stdlib/string-base-replace');
const str = 'foo bar foo';
const result = replace(str, /foo/g, (match) => match.toUpperCase());
console.log(result); // 'FOO bar FOO'

Other packages similar to @stdlib/string-base-replace

Keywords

FAQs

Package last updated on 26 Jul 2024

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