JSPM

splice-string

3.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 471
  • Score
    100M100P100Q95257F
  • License MIT

Remove or replace part of a string like `Array#splice`

Package Exports

  • splice-string

Readme

splice-string

Remove or replace part of a string like Array#splice

It correctly handles slicing strings with emoji.

Install

$ npm install splice-string

Usage

import spliceString from 'splice-string';

spliceString('unicorn', 3, 4, 'verse');
//=> 'universe'

spliceString('❤️🐴🐴', 1, 1, '🦄');
//=> '❤️🦄🐴'

API

spliceString(string, index, count, insert?)

string

Type: string

index

Type: number

Index to start splicing.

count

Type: number

Number of characters to remove.

insert

Type: string

String to insert in place of the removed substring.