2.1.4 • Published 7 days ago

react-mustache-template-component v2.1.4

Weekly downloads
12
License
MIT
Repository
github
Last release
7 days ago

npm License GitHub Bugs GitHub issues GitHub last commit GitHub Workflow Status Codecov npm type definitions DeepScan grade contributions welcome Known Vulnerabilities Bundlephobia

React Mustache Template Component

The Template component that uses Mustache.js to render the a component, sanitized by dompurify.

Demo

See Storybook

Installation and Usage

$ npm install react-mustache-template-component

The use it in your app:

import TemplateComponent from 'react-mustache-template-component'

...
const template = `<img class="img" src="{{url}}" />`;
const data = { url: 'http://example.com/img' };

<TemplateComponent template={template} data={data} />

This will be rendered as

<div><img class="img" src="http://example.com/img" /></div>

Notes

  • Input is properly sanitized by dompurify. This can be switched off (... sanitize={false} ...) but is highly discouraged, as this might introduce XSS issues

Props

Props that are used:

NameRequiredTypeDefaultComments
templateYesstring-Mustache template string that is used in your template component
dataNoobject{}Data used by Mustache to replace placeholders (marked by {{}})
typeNostring"div"Type of container. Can be any HTMLElement, like div, span, i etc
sanitizeNobooleantrueSanitize the result using dompurify
sanitizeOptionsNoobject{}Sanitation can be changed by Dompurify.Config options

Besides these props, it can also use all basic HTML attributes, like className, style, id, etc.

Development

To install dependencies

$ npm install

To build

$ npm run build

To run tests

$ npm run test

To run Storybook

$ npm run storybook

License

MIT Licensed. Copyright (c) Jelte Lagendijk 2020.

2.1.4

7 days ago

2.1.3

23 days ago

2.1.2

9 months ago

2.1.1

9 months ago

2.1.0

9 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.1

4 years ago

1.0.0

4 years ago