Skip to content

kzhrk/wrap-with-tag

Repository files navigation

wrap-with-tag

Build Status Coverage Status npm version

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.

Docs

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/dist/index.umd.js">
<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.

Licence

MIT

Author

kzhrk

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages