All Projects → RadLikeWhoa → Countable

RadLikeWhoa / Countable

Licence: mit
Add live paragraph-, word- and character-counting to an HTML element.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Countable

Decliner
Decline russian words with Decliner
Stars: ✭ 36 (-97.78%)
Mutual labels:  library, words
Adafruit ina219
INA219 Current Sensor
Stars: ✭ 129 (-92.05%)
Mutual labels:  library
Kite
🪁 Android Resources Wrapper Library
Stars: ✭ 127 (-92.17%)
Mutual labels:  library
Opacclient
A Java client library and an Android app to access more than 1,000 public and scientific libraries from all over the world.
Stars: ✭ 128 (-92.11%)
Mutual labels:  library
Rxmusicplayer Android
An android music player using ExoPlayer and RxJava2
Stars: ✭ 127 (-92.17%)
Mutual labels:  library
Unity Raymarching Framework
A framework to easy implement raymarching in unity. Include lots of hash,noise,fbm,SDF,rotate functions
Stars: ✭ 129 (-92.05%)
Mutual labels:  library
Libideviceactivation
A library to handle the activation process of iOS devices
Stars: ✭ 126 (-92.23%)
Mutual labels:  library
Ruffles
Lightweight and fully managed reliable UDP library.
Stars: ✭ 131 (-91.92%)
Mutual labels:  library
Amqpstorm
Thread-safe Python RabbitMQ Client & Management library
Stars: ✭ 130 (-91.99%)
Mutual labels:  library
Bash Argsparse
An high level argument parsing library for bash
Stars: ✭ 128 (-92.11%)
Mutual labels:  library
Cordova Node Xcode
Apache cordova
Stars: ✭ 128 (-92.11%)
Mutual labels:  library
Arare
Lightweight curried functional programming library
Stars: ✭ 127 (-92.17%)
Mutual labels:  library
Googlenewsstandanimation Android
Navigation pattern like in Google News Stand app with transitions
Stars: ✭ 130 (-91.99%)
Mutual labels:  library
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-92.17%)
Mutual labels:  library
Chat Ui Kit React
Build your own chat UI with React components in few minutes. Chat UI Kit from chatscope is an open source UI toolkit for developing web chat applications.
Stars: ✭ 131 (-91.92%)
Mutual labels:  library
Skin
Pure CSS framework designed & developed by eBay for a branded, e-commerce marketplace.
Stars: ✭ 126 (-92.23%)
Mutual labels:  library
Sensu Plugin
A framework for writing Sensu plugins & handlers with Ruby.
Stars: ✭ 127 (-92.17%)
Mutual labels:  library
Libasciidoc
A Golang library for processing Asciidoc files.
Stars: ✭ 129 (-92.05%)
Mutual labels:  library
Pluralize
Pluralize or singularize any word based on a count
Stars: ✭ 1,808 (+11.47%)
Mutual labels:  words
Svg To Ts
Build performant SVG icon libraries by converting raw SVG files to TypeScript that is optimized for modern tree shaking mechanisms.
Stars: ✭ 131 (-91.92%)
Mutual labels:  library

Countable

Build Status Code Climate Latest Tag License

Countable is a JavaScript function to add live paragraph-, word- and character-counting to an HTML element. Countable is a zero-dependency library and comes in at 1KB when minified and gzipped.

View the Demo

Installation

The preferred method of installation is npm or yarn.

npm i --save-dev countable
yarn add --dev countable

Alternatively, you can download the latest zipball or copy the script directly.

Usage

Countable is available as a Node / CommonJS module, an AMD module and as a global. All methods are accessed on the Countable object directly.

Callbacks

The on and count methods both accept a callback. The given callback is then called whenever needed with a single parameter that carries all the relevant data. this is bound to the current element. Take the following code for an example.

Countable.count(document.getElementById('text'), counter => console.log(this, counter))
=> <textarea id="text"></textarea>, { all: 0, characters: 0, paragraphs: 0, words: 0 }
Property Meaning
paragraphs The number of paragraphs. Paragraphs can be separated by either a soft or a hard (two line breaks) return. To use hard returns, set the corresponding option (hardReturns).
sentences The number of sentences. Sentences are separated by a sentence-terminating character.
words The number of words. Words are split using spaces.
characters The number of characters (without spaces). This contains all non-whitespace characters.
all The number of characters including whitespace. This is the total number of all characters in the element.

Countable.on(elements, callback, options)

Bind the callback to all given elements. The callback gets called every time the element's value or text is changed.

Countable.on(area, counter => console.log(counter))

Countable.off(elements)

Remove the bound callback from all given elements.

Countable.off(area)

Countable.count(elements, callback, options)

Similar to Countable.on(), but the callback is only executed once, there are no events bound.

Countable.count(area, counter => console.log(counter))

Countable.enabled(elements)

Checks the live-counting functionality is bound to the given.

Countable.enabled(area)

Options

Countable.on() and Countable.count() both accept a third argument, an options object that allows you to change how Countable treats certain aspects of your element's text.

{
  hardReturns: false,
  stripTags: false,
  ignore: []
}

By default, paragraphs are split by a single return (a soft return). By setting hardReturns to true, Countable splits paragraphs after two returns.

Depending on your application and audience, you might need to strip HTML tags from the text before counting it. You can do this by setting stripTags to true.

Sometimes it is desirable to ignore certain characters. These can be included in an array and passed using the ignore option.

Browser Support

Countable supports all modern browsers. Full ES5 support is expected, as are some ES6 features, namely let and const.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].