npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

char-count-es6

v1.0.0

Published

A lightweight ES6 library for dealing with character counts on text fields

Readme

CharCount

A lightweight (~7KB min) ES6 library for dealing with character counts on text fields, providing events, live counters and more!

An interactive preview can be found on the GitHub page for this project.

The concept of the library is to define a state that the field is in dependent on where the field sits within the configured thresholds. The character count thresholds are seperated into 3 key targets; Warning, Danger and Expended. Warning is for "you're getting close!", Danger is for "for real, you are running out" and Expended is for "all used up!". When the field is empty an Empty state is declared, along with a similar Fine state being applied when the field sits between an Empty and Warning state. Based on this, events are fired to allow utilisation of that fact and a counter is placed underneath the field to display the remainder of the expended threshold to the user in realtime.

Installation

Via NPM

$ npm install char-count --save-dev

Via download

Download the minified source from dist and include in your project via

<script src="/path/to/charcount.min.js"></script>

Usage

To begin, import the ES6 library where required import CharCount from 'CharCount';

To create a new instance, you can define a new CharCount, e.g. let myCharCount = new CharCount( <options> );. The variable will contain an array of initialised instances, stored in the instances property. The element also has the instance registered against it, in the CharCount property.

Options

All the following is optional. When initialising the library, the following options can be provided as an object:

Core

  • selector: [String || Object (Element)] [Default 'cc-field'] - ID, Class or Element to initialse the library against

Thresholds

  • warningThreshold: [Int] [Default 25] - Character count threshold for the field to enter the warning state
  • dangerThreshold: [Int] [Default 10] - Character count threshold for the field to enter the danger state
  • expendedThreshold: [Int] [Default 100] - Character count for the maximum length of the field

Counter DOM Classes

  • counterClass: [String] [Default 'cc-count'] - Added to all counter elements
  • emptyClass: [String] [Default 'cc-is-empty'] - When the counter element's field is Empty
  • fineClass: [String] [Default 'cc-is-fine'] - When the counter element's field is Fine
  • warningClass: [String] [Default 'cc-is-warning'] - When the counter element's field is Warning
  • dangerClass: [String] [Default 'cc-is-danger'] - When the counter element's field is Danger
  • expendedClass: [String] [Default 'cc-is-expended'] - When the counter element's field is Expended

Callbacks

A field and remaining count is always sent to the method. The field is the element that called the event, with remaining being the current remaining character count of the field away from the expended state.

  • onFieldEmpty: (field, remaining) => {} - Fired when a fields text count is zero; not entirely sure on its continued usefulness
  • onFieldFine: (field, remaining) => {} - Fired when a fields text remaining count is a-okay, after coming from another state
  • onFieldWarning: (field, remaining) => {} - Fired when the desired warning threshold is reached
  • onFieldDanger: (field, remaining) => {} - Fired when the desired danger threshold is reached
  • onFieldExpended: (field, remaining) => {} - Fired when the remainder is all used up!

For example implementation of this, see src/example.app.js

Contributing & Development

If you wish to contribute, please just fork and play around! If you have any changes, just submit a PR.

Environment

The project utilises NPM for dependency management and webpack as a build tool, with a couple of NPM scripts setup to help with development.

When you first clone the project, run npm install from the project directory to get the baseline all squared away.

NPM Scripts

  • npm run dev - Build the development environment files, this is example.app.js to the docs directory
  • npm run watch - The usual watch script to automatically build the dev environment
  • npm run hot - Runs a webpack dev server at localhost:8080 from the docs directory
  • npm run prod - Builds the project out to the minified charcount.min.js in the dist directory

Project Structure

  • dist - Stores assets for distribution
  • docs - Stores assets to be served up to GitHub pages and the local webpack dev server. Build ouput of dev, hot and watch
  • legacy - Stores the original jQuery library
  • src - Stores the source files for the project. This includes the entry point for the library itself CharCount.js, its core and its helpers. There are also example assets in there, example.app.js for implementation and scss (Sass) for styling

Todo

  • Unit tests!