wrap-with-tag
v1.2.0
Published
A wrap-with-tag provides a simple function to wrap string with html.
Downloads
31
Readme
wrap-with-tag
Wrap-with-tag provides a simple function to wrap string with html.
Description
Wrap-with-tag provides a function wrapping specific word with html tag assigned with certain class.
The use case is to wrap specific word, like a company name, with a span element assigned with class for applying font-family.
Install
$ yarn add wrap-with-tag
or
$ npm install wrap-with-tag -d
Usage
The recommend use case is using import
statements.
import wrapWithTag from 'wrap-with-tag';
wrapWithTag({
regexp: /(Company Name)/g,
className: 'special-font',
tagName: 'span',
attr: {
tabindex: -1
}
});
Alternatively, you can use script
tag with html file.
You can find all versions of the CDN at UNPKG.
<script src="https://unpkg.com/wrap-with-tag">
<script>
wrapWithTag({
regexp: /(Company Name)/g,
className: 'special-font',
tagName: 'span',
attr: {
tabindex: -1
}
});
</script>
Options
| name | default | description | |:-----|:------- |:------------| | regexp | /([a-zA-Z0-9,¥.-]+)/g | The regular expression of string wrapped with html tag defined with tagName option. | | className | diff | The string is added to html tag defined with tagName option. | | tagName | span | The html tag wraps string. | | attr | {} | The object is applied to html tag defined with tagName option. |