{"id":16788749,"url":"https://github.com/markmead/alpinejs-character-count","last_synced_at":"2025-04-10T23:25:12.267Z","repository":{"id":98518886,"uuid":"502126453","full_name":"markmead/alpinejs-character-count","owner":"markmead","description":"Track the character count of an input with the option to compare against the max length 🔟","archived":false,"fork":false,"pushed_at":"2025-03-07T08:14:21.000Z","size":22,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T20:12:32.133Z","etag":null,"topics":["alpine-js","alpinejs","alpinejs-plugin","javascript"],"latest_commit_sha":null,"homepage":"https://js.hyperui.dev/examples/form-input-character-count","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/markmead.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-10T17:25:30.000Z","updated_at":"2025-03-07T08:14:22.000Z","dependencies_parsed_at":"2025-03-07T09:32:31.476Z","dependency_job_id":null,"html_url":"https://github.com/markmead/alpinejs-character-count","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-character-count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-character-count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-character-count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-character-count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmead","download_url":"https://codeload.github.com/markmead/alpinejs-character-count/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313654,"owners_count":21082892,"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":["alpine-js","alpinejs","alpinejs-plugin","javascript"],"created_at":"2024-10-13T08:24:37.724Z","updated_at":"2025-04-10T23:25:12.247Z","avatar_url":"https://github.com/markmead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alpine JS Character Count\n\nTrack the character count of an input with the option to compare against the max\nlength 🔟\n\n## Example\n\n```html\n\u003cdiv x-data=\"{ message: 'Hello' }\"\u003e\n  \u003ctextarea x-model=\"message\" maxlength=\"50\"\u003e\u003c/textarea\u003e\n\n  \u003cp\u003eYou have written \u003cspan x-count=\"message\"\u003e\u003c/span\u003e characters.\u003c/p\u003e\n\n  \u003cp\u003eYou have \u003cspan x-count.50=\"message\"\u003e\u003c/span\u003e characters remaining.\u003c/p\u003e\n\u003c/div\u003e\n```\n\nThis will return the following:\n\n```html\n\u003cp\u003eYou have written 5 characters.\u003c/p\u003e \u003cp\u003eYou have 45 characters remaining\u003c/p\u003e\n```\n\nThe modifier in the example `50` is the max character count which you can pair\nup with the `maxlength` attribute on the HTML input. If you want a more dynamic\napproach to this, you can do the following.\n\n### Using Alpine JS Refs\n\n```html\n\u003cdiv x-data=\"{ message: 'Hello' }\"\u003e\n  \u003ctextarea x-model=\"message\" maxlength=\"100\" x-ref=\"textarea\"\u003e\u003c/textarea\u003e\n\n  \u003cp\u003eYou have written \u003cspan x-count=\"message\"\u003e\u003c/span\u003e characters.\u003c/p\u003e\n\n  \u003cp\u003eYou have \u003cspan x-count.textarea=\"message\"\u003e\u003c/span\u003e characters remaining.\u003c/p\u003e\n\u003c/div\u003e\n```\n\nInstead of passing the max character count as the modifier, you pass the name of\nan Alpine JS `x-ref`.\n\n## Install\n\n### CDN\n\n```html\n\u003cscript\n  defer\n  src=\"https://unpkg.com/alpinejs-character-count@latest/dist/count.min.js\"\n\u003e\u003c/script\u003e\n\n\u003cscript defer src=\"https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js\"\u003e\u003c/script\u003e\n```\n\n### NPM/Yarn\n\n```shell\nnpm i -D alpinejs-character-count\n\nyarn add -D alpinejs-character-count\n```\n\nThen you can register the plugin.\n\n```js\nimport Alpine from 'alpinejs'\nimport count from 'alpinejs-character-count'\n\nAlpine.plugin(count)\n\nwindow.Alpine = Alpine\n\nAlpine.start()\n```\n\n### Stats\n\n![](https://img.shields.io/bundlephobia/min/alpinejs-character-count)\n![](https://img.shields.io/npm/v/alpinejs-character-count)\n![](https://img.shields.io/npm/dt/alpinejs-character-count)\n![](https://img.shields.io/github/license/markmead/alpinejs-character-count)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-character-count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmead%2Falpinejs-character-count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-character-count/lists"}