1.0.5 • Published 7 years ago

tag-wrapper v1.0.5

Weekly downloads
9
License
MIT
Repository
github
Last release
7 years ago

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.

paramtypedescriptionexample
tagsarrayArray 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>']
querystringSubtext in str to wrap within tags'foo'
strstringText containing instances of query to wrap in tags'foo bar'
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.2--beta-0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago