v-sanitize-directive
A utility library providing input sanitization using dompurify and Vue.js.
999
| Install | |
|---|---|
npm install v-sanitize-directive |
|
| Latest Version: | 0.0.8 |
| Vue: | 3 |
| License: | GPL-3.0 |
| Last Updated: | May 19, 2023 |
| Links: | GitHub · npm |
Maintainer: mustafadalga
Vue 3 Sanitize Input Plugin
- This is a Vue 3 directive for sanitizing input fields using DOMPurify.
Installing
Package manager
Using npm:
npm i v-sanitize-directive
Then, import and register the component:
Global Registration
In your main.js or main.ts file, globally register the plugin:
main.js
import { sanitizePlugin } from "v-sanitize-directive";
app.use(sanitizePlugin);
Local Registration
- Composition API
<script lang="ts" setup>
import { sanitize as vSanitize } from "v-sanitize-directive";
</script>
- Options API
<script>
import { sanitize } from "v-sanitize-directive";
export default {
directives: {
"sanitize": sanitize
},
}
</script>
Usage
- Example 1: Options API - In your component.
<script>
import { sanitize } from "v-sanitize-directive";
export default {
directives: {
"sanitize": sanitize
},
data () {
return {
text: ""
}
}
}
</script>
<template>
<input v-sanitize="text"
v-model="text"
type="text" />
</template>
- Example 2: Composition API - In your component.
<script setup>
import { sanitize as vSanitize } from "v-sanitize-directive";
import { ref } from "vue";
const text = ref("");
</script>
<template>
<input v-sanitize="text"
v-model="text"
type="text" />
</template>
- Example 3: Global Registration with Composition API.After globally registering the plugin, in your component.
<script lang="ts" setup>
import { ref } from "vue";
const text = ref("");
</script>
<template>
<input v-sanitize="text"
v-model="text"
type="text" />
</template>
- Example 4: Global Registration with Options API.After globally registering the plugin, in your component.
<script lang="ts" >
export default {
data() {
return {
text: ""
}
}
}
</script>
<template>
<input v-sanitize="text"
v-model="text"
type="text" />
</template>
Demo
License
Related Packages
@radya/nuxt-dompurify
A Nuxt 3 module that integrates DOMPurify for sanitizing HTML content and protec...
28,438
8
@benedictleejh/nuxt-sanitise-html
A Nuxt module to sanitise HTML to protect against XSS attacks
1,732
1
purrrify
A Nuxt module that integrates sanitize-html for sanitizing HTML content and prot...
2,066
4
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.0.8 | ^3.3.2 | GPL-3.0 | |
| 0.0.7 | ^3.3.2 | GPL-3.0 | |
| 0.0.6 | ^3.3.2 | GPL-3.0 | |
| 0.0.5 | ^3.3.2 | GPL-3.0 | |
| 0.0.4 | ^3.3.2 | GPL-3.0 | |
| 0.0.3 | ^3.3.2 | GPL-3.0 | |
| 0.0.2 | ^3.3.2 | GPL-3.0 | |
| 0.0.1 | ^3.3.2 | GPL-3.0 | |
| 0.0.0 | ^3.3.2 | GPL-3.0 |