Giter Club home page Giter Club logo

vue-countable's Introduction

vue-countable

Vue binding for countable.js. Provides real-time paragraph, sentence, word, and character counting.

NPM Version NPM Downloads License Tweet

Demo

View Demo | View on NPM | View on GitHub

Install

# npm
npm i vue-countable

# yarn
yarn add vue-countable

Or you can include it through the browser at the bottom of your page:

<script src="https://unpkg.com/vue-countable/dist/vue-countable.min.js"></script>

About

Simple way to count characters, words, sentences, and paragraphs in your Vue apps.

Pass your text as a prop to the provided component, along with a unique elementId, and register for the change event to get real-time count updates.

Usage Example

import VueCountable from 'vue-countable'
Vue.component('vue-countable', VueCountable)
<!-- In your html - Make sure the elementId prop is unique on your page. -->
<vue-countable
    :text="myText" // Your text variable
    :elementId="'myId'" // A unique string id
    @change="change" // Register for the change event
></vue-countable>

<!-- The @change function -->
change (event) {
    console.log(event)
    // event.words to get word count, etc.
}

Now, anytime (and on component initialization) your myText variable changes, vue-countable will emit an event containing the details of your text. Register for this event as shown above to get your real-time counts.

Props

prop type description
text String Text you want to track.
elementId String A unique id for your tracking instance. This allows you to have multiple different counts on the same page.
hardReturns Boolean (Optional, defaults to false) Require two returns to count paragraphs
stripTags Boolean (Optional, defaults to false) Remove HTML before counting
ignore Array of Strings (Optional, defaults to empty) Characters to be ignored.

Events

event value description
change Object Provides character, word, sentence, paragraph, and all values.

Development

# install dependencies
npm install

# serve with hot reload
npm run watch

# run the tests
npm run test

# build demo page
npm run build:example

# build library
npm run build:library

# build everything and run tests
npm run build

Other

Go ahead and fork the project! Submit an issue if needed. Have fun!

Thank You

Sacha Schmid for countable.js.

License

MIT

Packaged with a mixture of vue-lib-template and vue-sfc-rollup. Using webpack 4.

vue-countable's People

Contributors

johndatserakis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-countable's Issues

event.words returning undefined

Hey, man. Super excited about the prospect of this component. Thanks for releasing it!

I'm a bit confused by the docs. Not sure where how to retrieve the output of my counts. I was expecting event.words to return a number of words, but it's returning undefined. Here's what I have in my app.vue:

<vue-countable
  :text="notes[selectedNoteIndexInList].contents"
  :elementId="toString(notes[selectedNoteIndexInList].id)"
  @change="change"
>sup yo</vue-countable>

...skipping stuff...

import VueCountable from 'vue-countable'
// skipping more irrelevant stuff

export default {
    components: {
      VueCountable
    }
}

and then in my methods...

change: function () {
  console.log(event.words)
}

console.log(event) returns a big object called MessageEvent that contains no count data (to my knowledge). And console.log(event.words) returns undefined.

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.