New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dolinks

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dolinks

Make links clickable in chosen HTML component preserving newlines symbols of your text

latest
npmnpm
Version
1.2.11
Version published
Maintainers
1
Created
Source

Not tested with Vue3

Vue directive to make links clickable in chosen HTML component, preserving newlines symbols of your text.

  • Instalation
  • Usage examples
  • Options
  • Known issues
  • Changelog

Installation

$ npm i dolinks

Import

// import dolinks in your project root
import dolinks from 'dolinks'

// pass it to Vue.use() method
Vue.use(dolinks);

Additional options object:

interface IOptions {
  urlRegEx?: RegExp,
  target?: '_self' | '_blank' | '_parent' | '_top',
  disableWarnings?: boolean,
}

Pass options object as a Vue.use() parameter:

Vue.use(dolinks, options);

Usage examples

dolinks assumes that you'll pass your text to the template using the Vue "Mustache" syntax.

  • Mark you HTML tag with v-dolinks directive:
  • Pass text using {{ yourText }}

Preserve your \n symbols:

Input:

<template>
  <p v-dolinks :style="{'white-space': 'pre-wrap'}">
    {{ yourText }}
  </p>
</template>

<script>
  data() {
    return {
      yourText: 'Some \n splited \n https://achievki.io \n here'
    }
  }
</script>

Output:

<p style="white-space: pre-wrap;">
  "Some splited"
  <a href="https://achievki.io" target="_blank">https://achievki.io</a> 
 " here"
</p>

Sanitizes all other HTML tags:

Input:

<script>
  data() {
    return {
      yourText: 'https://example.com Let`s try to pass some <script> with <a href="https://google.com">GOOGLE LINK</a> <\/script>'
    }
  }
</script>

Output:

<p style="white-space: pre-wrap;">
  <a href="https://example.com" target="_blank">https://example.com</a>
  " Let`s try to pass some &lt;script&gt; with &lt;a href=""
  <a href="https://google.com" target="_blank">https://google.com</a>
  ""&gt;GOOGLE LINK&lt;/a&gt; &lt;/script&gt;
</p>

Options

urlRegEx

Should be valid RegExp. By this expression, dolinks will deside what text should be transformed to an <a> tag.
Text, matched this regex, also will be used as a value for href atribute.

Default:

/https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b[-a-zA-Z0-9@:%._\+~#=\/]{0,2048}/

target

The value for target atribute of an <a> tag. Should be a valid value for target:

  • _self
  • _blank (default)
  • _parent
  • _top

disableWarnings

If true - disables all dolinks warnings and errors. Default - false.

Known issues

  • If text inside your tag with v-dolinks directive needs to be reactive, you should re-render component on each text update (e.g. use <p v-dolinks :key="yourText">{{ yourText }}</p>). update and componentUpdated Vue directive hooks not working correctly with 1.2.0 and disabled for 1.2.1.

License

MIT © vladhutsal

Keywords

vue

FAQs

Package last updated on 15 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts