Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

patch-text

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

patch-text

Make multiple changes to a block of text by providing start and end indices and replacement text

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

patch-text Build Status

Make multiple changes to a block of text by providing start and end indices and replacement text

Install

$ npm install --save patch-text

Usage

var patch = require('patch-text');
var text = 'Hello guys!'
var updated = patch(text, [
  {
    start: 0,
    end: 5,
    replacement: 'Hi'
  },
  {
    start: 7,
    end: 9,
    replacement: 'al'
  }
])
// => 'Hi gals!'

Your patches shouldn't overlap, but they can shrink or increase the character count and your patches will still apply to the right text.

API

patch(text, patches) -> string
text

Required
Type: string

The text to patch.

patches

Required
Type: array[object]

The patches to apply to the text, each with:

  • start (number)
  • end (number)
  • replacement (string)

License

MIT © Ben Drucker

Keywords

FAQs

Package last updated on 05 Jun 2015

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