Skip to content

v2.0.0

Choose a tag to compare

@iansinnott iansinnott released this 01 Jan 23:35
· 3 commits to master since this release

Breaking Changes

Index parameter now starts at 0

The index parameter passed to the replacement callback now returns the logical match index (0, 1, 2, 3...) instead of the internal array index (1, 3, 5, 7...).

Before (v1.x):

reactStringReplace('a b c', /(\w)/g, (match, index) => {
  console.log(index); // 1, 3, 5
});

After (v2.0):

reactStringReplace('a b c', /(\w)/g, (match, index) => {
  console.log(index); // 0, 1, 2
});

This makes the index more intuitive and useful for React key props.

Migration

If your code relies on the old index values, update your callback logic to expect 0-indexed sequential values.


Fixes #32, closes #92

Full Changelog: v1.2.0...v2.0.0