You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vue-snip

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-snip

[![Build Status](https://travis-ci.org/ajobi/vue-snip.svg?branch=master)](https://travis-ci.org/ajobi/vue-snip) ![Coveralls github](https://img.shields.io/coveralls/github/ajobi/vue-snip) ![GitHub issues](https://img.shields.io/github/issues/ajobi/vue-sni

1.0.0-beta.5
Source
npmnpm
Version published
Weekly downloads
6.2K
10.2%
Maintainers
1
Weekly downloads
 
Created
Source

vue-snip

Build Status Coveralls github GitHub issues GitHub npm bundle size

Vue.js directive that clamps the content of a text element if it exceeds specified number of lines.

How it works

This library offers two snipping methods:

  • CSS method based on the -webkit-line-clamp
  • JavaScript method that is snipping the innerText until it does not exceed given number of lines

Global default is the CSS method (automatically falls back to the JavaScript method for non-supporting browsers), but you can freely switch snipping methods on a per-element basis as needed.

Each element is also immediately re-snipped when horizontally resized. This is detected via the ResizeObserver.

Installation

npm install vue-snip
yarn add vue-snip
import Vue from 'vue'
import VueSnip from 'vue-snip'

Vue.use(VueSnip)

Usage

The most basic usage looks like this:

<template>
  <p v-snip> ... </p>
</template>

Most of the time, you would probably pass in the explicit maxLines value:

<template>
  <p v-snip="3"> ... </p>
</template>

On top of that, you can pass in the snipping method too:

<template>
  <p v-snip:js="3"> ... </p>
</template>

Both of these are also reactive, so you can do even this:

<template>
  <p v-snip:[method]="maxLines"> ... </p>
</template>

<script>
  export default {
    data () {
      return {
        method: 'js',
        maxLines: 3
      }
    }
  }
</script>

Options

import Vue from 'vue'
import VueSnip from 'vue-snip'

const options = {
  // your setup
}

Vue.use(VueSnip, options)

If you don't pass in any options, default options are used. Any option passed will override the default value.

NameDefault ValueDescription
directiveName'snip'In preparation...
snipMethod'css'In preparation...
maxLines3In preparation...
separators['. ', ', ', ' ', '']In preparation...
ellipsis'.\u200A.\u200A.'In preparation...
resizeObserverPolyfillnullIn preparation...
debugModefalseIn preparation...

Caveats

TODO: Document flexbox...

TODO: Document style attribute...

Keywords

clamp

FAQs

Package last updated on 17 Jul 2020

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