Giter Club home page Giter Club logo

svelte-purify's Introduction

svelte-purify

npm-version npm-license npm-download-month npm-min-size ci.yml

๐Ÿ’Ž Safe html expansion for Svelte with DOMPurify

Installation

npm i svelte-purify

Usage

See DOMPurify for detailed settings.

<script>
  import { Render } from 'svelte-purify'

  const code = '<h1>Hello World</h1>'
</script>

<Render html={code} config={/* DOMPurify Config */} />

<!-- Equivalent to {@html code} -->

SSR

Render uses DOMPurify internally and only works in the browser or at Node runtime.
There are 3 options for use in non-node environments such as the edge.

  1. Use svelte-sanitize

Enables the use of html rendering in non-node environments at the expense of detailed compatibility.
Please check the link for details.

<script>
  import { Render } from 'svelte-sanitize'
</script>

<Render html={/* ... */} />
  1. Use Browser Only Entry Point

In this case, html is not rendered on the server.

<script>
  import { Render } from 'svelte-purify/browser-only'
</script>

<Render html={/* ... */} />
  1. Manual Config

Conditional Exports is not yet fully supported, so 2. may not work.
Sacrificing bundle size avoids this problem.

npm i dompurify
<script>
  import { browser } from '$app/environment'
  import DOMPurify from 'dompurify'
</script>

{@html browser ? DOMPurify.sanitize(/* ... */) : 'server-fallback-value'}

License

MIT

svelte-purify's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

svelte-purify's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • jill64/playwright-config v2.4.0@79be820c194e134cd595ded9bd0258f2297175f3
npm
package.json
  • universal-dompurify 1.0.15
  • @jill64/eslint-config-svelte 1.3.1
  • @jill64/npm-demo-layout 1.0.233
  • @jill64/playwright-config 2.4.0
  • @jill64/prettier-config 1.0.0
  • @jill64/sentry-sveltekit-edge 1.2.41
  • @jill64/universal-sanitizer 1.3.0
  • @playwright/test 1.45.2
  • @sveltejs/adapter-vercel 5.4.1
  • @sveltejs/kit 2.5.18
  • svelte 4.2.18
  • typescript 5.5.3
  • vite 5.3.4
  • @sveltejs/vite-plugin-svelte 3.1.1
  • svelte ^4.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.