Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including i-replace with all npm packages installed. Try it out:

var iReplace = require("i-replace")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

i-replace v1.1.0

Convenient case insensitive string replace.

JavaScript Style Guide

Table of Contents


Convenient case insensitive string replacement with optional multiple replacement.


  • 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)


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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free