ultimate-string-replace

2.3.0 • Public • Published

ultimate-string-replace

Build Status Code Coverage code style: prettier semantic-release dependencies Greenkeeper badge

NPM

Javascript library to allow to find and wrap matches in a string.

It's main purpose is to be used in filters of objects, so you can highlight matches.

If the string has accents, ultimate-string-replace will get rid of them and match anyway.

If the string to match has accents, it will only match exact matches (case-insensitive).

Install

npm i -S ultimate-string-replace

ultimate-string-replace is also published in bower

bower install ultimate-string-replace

Usage

import ultimateStringReplace from 'ultimate-string-replace';

const data = "Crème brûlée"
const response = ultimateStringReplace(data, "rème brûlée", {'wrap_preffix': "<b>", 'wrap_sufix': "</b>" })
// Result -> 'C<b>rème brûlée</b>';

Examples of matches

Matcher Input Output
he Hello hello <b>He</b>llo <b>he</b>llo
23 12 34 1<b>2 3</b>4
rème brûlée Crème brûlée C<b>rème brûlée</b>
Víctor victor Victor <b>Ví</b>ctor victor Victor
vi Víctor victor Victor <b>Ví</b>ctor <b>vi</b>ctor <b>Vi<b>ctor
Víctor victor Victor <b>Ví</b>ctor victor Victor
no Víctor victor Victor false
  • If you have doubts, check the tests.

Running the tests

npm run test

Build the application

npm run build

ultimate-string-replace is written as an ES6 module, but it also gets transpiled to ES5.

Contributing

PR Welcome!

/ultimate-string-replace/

    Package Sidebar

    Install

    npm i ultimate-string-replace

    Weekly Downloads

    3

    Version

    2.3.0

    License

    MIT

    Unpacked Size

    180 kB

    Total Files

    10

    Last publish

    Collaborators

    • vlaraort