Countable

screenshot of Countable

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

Overview

Countable is a lightweight JavaScript library designed for live counting of paragraphs, words, and characters in HTML elements. With a mere 1KB size when minified and gzipped, it embraces a zero-dependency approach, making it an efficient choice for developers looking to integrate counting functionality into their web applications without the burden of heavy libraries. Whether you're building a content management system or a simple text box counting tool, Countable aims to provide ease of use alongside powerful features.

What sets Countable apart is its flexibility and the ability to customize how counts are calculated. The library supports multiple installation methods, including npm and yarn, and offers integration as a Node/CommonJS module, AMD module, or as a global variable. With callback functions that respond to text changes, Countable ensures that users receive real-time updates on their text input seamlessly.

Features

  • Zero-Dependency Library: Countable is lightweight, coming in at only 1KB when minified and gzipped, ensuring minimal impact on loading times.

  • Multiple Install Options: Easily install Countable through npm, yarn, or by downloading a zipball, allowing for flexibility based on project needs.

  • Customizable Counting Methods: Users can configure how paragraphs, sentences, and words are counted through options, including the ability to use hard returns for paragraphs.

  • Dynamic Callbacks: The library supports callback functions that are triggered upon changes in the text, providing real-time feedback and allowing for enhanced interactivity.

  • Options to Strip Tags and Ignore Characters: Developers can strip HTML tags and define characters to ignore during counting, making it adaptable for various applications.

  • Comprehensive Browser Support: Countable works seamlessly across all modern browsers, supporting essential ES5 features and some ES6 syntax for compatibility.

  • Easy to Use API: With straightforward methods like Countable.on(), Countable.off(), and Countable.count(), integrating counting functionality is simple and efficient.