i-replace

1.1.0 • Public • Published

JavaScript Style Guide

Table of Contents

iReplace

Convenient case insensitive string replacement with optional multiple replacement.

Parameters

  • haystack string The string to search within.
  • needle string The string to search for within the haystack, case insensitive.
  • replacement string The string to replace the needle with. Regexp replacement strings can be used here.
  • multi boolean Whether to enable multiple replacemement. Default is to only replace the first occurence. (optional, default false)

Examples

const iReplace = require('i-replace')
const haystack = '<HEAD></HEAD>'
const needle = '</head'
const replacement = '<style>body { margin: 0}</style>$1'
console.log(iReplace(haystack, needle, replacement))
// outputs <HEAD><style>body { margin: 0}</style></HEAD>

Returns string the haystack after needle replacement

Package Sidebar

Install

npm i i-replace

Weekly Downloads

6

Version

1.1.0

License

MIT

Last publish

Collaborators

  • tommedema