{"id":15025217,"url":"https://github.com/radlikewhoa/countable","last_synced_at":"2025-05-14T21:06:42.406Z","repository":{"id":44161882,"uuid":"8664451","full_name":"RadLikeWhoa/Countable","owner":"RadLikeWhoa","description":"Add live paragraph-, word- and character-counting to an HTML element.","archived":false,"fork":false,"pushed_at":"2022-02-11T05:13:43.000Z","size":24966,"stargazers_count":1643,"open_issues_count":10,"forks_count":132,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-05-13T17:13:52.709Z","etag":null,"topics":["counting","javascript","library","words"],"latest_commit_sha":null,"homepage":"https://sacha.me/Countable","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RadLikeWhoa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-09T03:20:42.000Z","updated_at":"2025-03-27T15:13:20.000Z","dependencies_parsed_at":"2022-07-21T11:04:55.696Z","dependency_job_id":null,"html_url":"https://github.com/RadLikeWhoa/Countable","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadLikeWhoa%2FCountable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadLikeWhoa%2FCountable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadLikeWhoa%2FCountable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadLikeWhoa%2FCountable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RadLikeWhoa","download_url":"https://codeload.github.com/RadLikeWhoa/Countable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227612,"owners_count":22035669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["counting","javascript","library","words"],"created_at":"2024-09-24T20:01:45.953Z","updated_at":"2025-05-14T21:06:37.394Z","avatar_url":"https://github.com/RadLikeWhoa.png","language":"JavaScript","readme":"# Countable\n\n[![Build Status](http://img.shields.io/travis/RadLikeWhoa/Countable.svg)](https://travis-ci.org/RadLikeWhoa/Countable)\n[![Code Climate](https://codeclimate.com/github/RadLikeWhoa/Countable/badges/gpa.svg)](https://codeclimate.com/github/RadLikeWhoa/Countable)\n[![Latest Tag](http://img.shields.io/github/tag/RadLikeWhoa/Countable.svg)](https://github.com/RadLikeWhoa/Countable/tags)\n[![License](http://img.shields.io/badge/license-MIT-orange.svg)](https://github.com/RadLikeWhoa/Countable/blob/master/LICENSE.md)\n\nCountable 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.\n\n[**View the Demo**](http://radlikewhoa.github.io/Countable#demo)\n\n## Installation\n\nThe preferred method of installation is [**npm**](https://www.npmjs.com/) or [**yarn**](https://yarnpkg.com/).\n\n```\nnpm i --save-dev countable\nyarn add --dev countable\n```\n\nAlternatively, you can download the latest [zipball](https://github.com/RadLikeWhoa/Countable/archive/master.zip) or copy the [script](https://raw.github.com/RadLikeWhoa/Countable/master/Countable.js) directly.\n\n## Usage\n\nCountable is available as a Node / CommonJS module, an AMD module and as a global. All methods are accessed on the Countable object directly.\n\n### Callbacks\n\nThe `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.\n\n```javascript\nCountable.count(document.getElementById('text'), counter =\u003e console.log(this, counter))\n```\n\n```\n=\u003e \u003ctextarea id=\"text\"\u003e\u003c/textarea\u003e, { all: 0, characters: 0, paragraphs: 0, words: 0 }\n```\n\nProperty   | Meaning\n---------- | --------------------------------------------------------------------------------------------\nparagraphs | 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`).\nsentences  | The number of sentences. Sentences are separated by a sentence-terminating character.\nwords      | The number of words. Words are split using spaces.\ncharacters | The number of characters (without spaces). This contains all non-whitespace characters.\nall        | The number of characters including whitespace. This is the total number of all characters in the element.\n\n### Countable.on(elements, callback, options)\n\nBind the callback to all given elements. The callback gets called every time the element's value or text is changed.\n\n```javascript\nCountable.on(area, counter =\u003e console.log(counter))\n```\n\n### Countable.off(elements)\n\nRemove the bound callback from all given elements.\n\n```javascript\nCountable.off(area)\n```\n\n### Countable.count(elements, callback, options)\n\nSimilar to `Countable.on()`, but the callback is only executed once, there are no events bound.\n\n```javascript\nCountable.count(area, counter =\u003e console.log(counter))\n```\n\n### Countable.enabled(elements)\n\nChecks the live-counting functionality is bound to the given.\n\n```javascript\nCountable.enabled(area)\n```\n\n### Options\n\n`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.\n\n```javascript\n{\n  hardReturns: false,\n  stripTags: false,\n  ignore: []\n}\n```\n\nBy default, paragraphs are split by a single return (a soft return). By setting `hardReturns` to true, Countable splits paragraphs after two returns.\n\nDepending 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.\n\nSometimes it is desirable to ignore certain characters. These can be included in an array and passed using the `ignore` option.\n\n## Browser Support\n\nCountable supports all modern browsers. Full ES5 support is expected, as are some ES6 features, namely `let` and `const`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradlikewhoa%2Fcountable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradlikewhoa%2Fcountable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradlikewhoa%2Fcountable/lists"}