tag-wrapper

1.0.5 • Public • Published

tag-wrapper

Build Status npm Version

Tag-wrapper provides a function to wrap all instances of a query within a string within the provided "tags." If you've ever wanted to wrap all instances of a string's substring(s) within HTML tags, regardless of case, you may find this package useful.

Installation

npm install tag-wrapper --save

Usage

import tagWrapper from 'tag-wrapper'

const tags = ['<em>', '</em>']
const query = 'fox'
const str = 'The quick brown fox jumps over the lazy FOX.'
const formattedStr = tagWrapper(tags, query, str)

formattedStr // 'The quick brown <em>fox</em> jumps over the lazy <em>FOX</em>.'

API

tagWrapper(tags, query, str)

Wrap str's instances of query substring in provided tags.

Returns the str argument if the query is not in the str or the query, str, or either tags index is falsy.

param type description example
tags array Array containing string "tags" to wrap instances of query text within str. Preceding tag should be the first index, succeeding tag should be the second. ['<em>', '</em>']
query string Subtext in str to wrap within tags 'foo'
str string Text containing instances of query to wrap in tags 'foo bar'

Package Sidebar

Install

npm i tag-wrapper

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

7.26 kB

Total Files

8

Last publish

Collaborators

  • alexzielonko