JSPM

patch-text

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28327
  • Score
    100M100P100Q145303F
  • License MIT

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

Package Exports

  • patch-text

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (patch-text) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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