{"id":19760843,"url":"https://github.com/barbwire-1/grapheme-counter","last_synced_at":"2026-07-22T00:36:23.610Z","repository":{"id":228642219,"uuid":"774467655","full_name":"BarbWire-1/grapheme-counter","owner":"BarbWire-1","description":"Lightweight (1.6Kb) unicode relying grapheme cluster and emoji counter ","archived":false,"fork":false,"pushed_at":"2024-03-19T19:19:14.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T23:26:37.880Z","etag":null,"topics":["composed-emojis","diacritical-marks","grapheme-cluster","string-length","unicode"],"latest_commit_sha":null,"homepage":"","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/BarbWire-1.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}},"created_at":"2024-03-19T15:47:27.000Z","updated_at":"2024-03-19T19:59:32.000Z","dependencies_parsed_at":"2024-03-19T20:05:10.968Z","dependency_job_id":null,"html_url":"https://github.com/BarbWire-1/grapheme-counter","commit_stats":null,"previous_names":["barbwire-1/grapheme-counter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarbWire-1%2Fgrapheme-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarbWire-1%2Fgrapheme-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarbWire-1%2Fgrapheme-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarbWire-1%2Fgrapheme-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BarbWire-1","download_url":"https://codeload.github.com/BarbWire-1/grapheme-counter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241090667,"owners_count":19907994,"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":["composed-emojis","diacritical-marks","grapheme-cluster","string-length","unicode"],"created_at":"2024-11-12T03:38:52.359Z","updated_at":"2025-10-15T04:53:56.786Z","avatar_url":"https://github.com/BarbWire-1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grapheme-Counter\n\n`Grapheme-Counter` is a lighweight JavaScript library (1.6Kb!) that provides functions for giving the \"correct\" length of any strings by counting grapheme clusters, accounting for combined emoji sequences and diacritical marks. It offers two main methods of usage: as a standalone function or by extending the `String.prototype` with a `count` property.\n\n### [Documentaion](documentation.md)\n***\n## Installation\n\nYou can install Grapheme-Counter via npm:\n\n```bash\nnpm install grapheme-counter\n```\nAlternatively, you can directly include the GraphemeCounter.js file in your project.\n\n***\n## API\n\n* `initStringCountProperty()`\nInitializes the count property on the String.prototype, allowing direct usage on strings.\n\n* `countCharacters(str)`\nCounts the number of grapheme clusters in the input string str, accounting for combined emoji sequences and diacritical marks.\n\n* `str (String)`\nThe input string to count grapheme clusters in.\nReturns an object with the following properties:\n\n* `count (Number)`\nThe count of grapheme clusters in the input string.\n[Example-Counts](#examples)\n\n\n## Usage\nIn vanilla JS - copy the GraphemeCounter.js into your project.\nIn node require the package.\n\nUsing String.prototype.count Property\n```js\n// Import and initialize the count property on String.prototype\nimport { initStringCountProperty } from 'GraphemeCounter.js';\ninitStringCountProperty();\n\n// Use the count property directly on strings\nconst text = 'A flag 🏳️‍🌈!!!';\nconsole.log(text.count); // Output: 11\n```\nUsing countCharacters Function-return ({count})\n```js\n// Import the countCharacters function\nimport { countCharacters } from 'GraphemeCounter.js';\n\n// Count grapheme clusters in a string\nconst text = 'A flag 🏳️‍🌈!!!';\nconst count = countCharacters(text).count;\nconsole.log('Grapheme cluster count:', count); // Output: 11\n```\n\n\n\n\n***\n## Examples\n\u003cdetails\u003e\n  \u003csummary\u003eClick to view examples\u003c/summary\u003e\n\n  \u003cpre\u003e\u003ccode class=\"language-javascript\"\u003e\n    const examples = {\n        Greek: \"Γειά σου Κόσμε\",// 14\n        Korean: \"안녕하세요 세상\",// 8\n        Hebrew: \"שלום עולם\",// 9\n        Arabic: \"مرحبا بالعالم\",// 13\n        Russian: \"Привет, мир\",// 11\n        Japanese: \"こんにちは、世界\",// 8\n        Chinese: \"你好，世界\",// 5\n        RainbowFlag: \"🏳️‍🌈\",// 1\n        Family: \"👨‍👩‍👧‍👦👨‍👨‍👧‍👧👩‍👩‍👦‍👦👩‍👧‍👧👨‍👦‍👦\",// 5\n        Man: \"👨‍\",// 1\n        Text: \"tex  t\",// 6\n        Click: \"̰Click\",// 5\n        Gujarati: \"જૂની ગુજરાતી\",// 7\n        Sinhala: \"දන්නවා\",//\n        Dream: \"rêve\",// 4\n        Math: \"∀x ∈ ℝ: ∑(x_i) = ∫(f(x) dx)\",// 27\n        EgyptianHieroglyphs: \"𓇓𓏏𓈖𓂋 𓆣𓍑𓆓𓎛\",// 9\n        WavingIntlFlag1:\"\\ud83c\\udff4\\udb40\\udc67\\udb40\\udc62\\udb40\\udc65\\udb40\\udc6e\\udb40\\udc67\\udb40\\udc7f\",// 1\n        WavingIntlFlag2:\"🏴\",// 1\n        BlackFlag: \"🏴\",// 1\n        testSinhala: \"ඐ\" // 1\n    };\n\n    for (const [language, str] of Object.entries(examples)) {\n         console.log(str.count);\n    }\n\n  \u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n***\n## Compatibility\n* Requires ECMAScript 6 (ES6) support.\n* Compatible with modern browsers and environments that support Unicode regular expressions.\n## License\nGrapheme Counter is licensed under the MIT License.\n\n\n## Reporting Issues\n\nIf you encounter any bugs, have suggestions for improvements, or would like to request new features, please [open an issue](link-to-issues) on GitHub. When reporting issues, please include detailed information such as:\n\n- Steps to reproduce the issue\n- Expected behavior\n- Actual behavior\n- Any error messages or console logs\n\nYour feedback is valuable and helps improve the quality of the project. Thank you for contributing!\n\n\n\n## Contributing\n\nWe welcome contributions from the community! If you'd like to contribute to this project, please follow these guidelines:\n\n1. Fork the repository and clone it to your local machine.\n2. Create a new branch for your changes (`git checkout -b feature/your-feature-name`).\n3. Make your changes and ensure they follow the project's coding style and conventions.\n4. Write tests for your changes if applicable (I know, I didn't).\n5. Commit your changes with a clear and descriptive message.\n6. Push your changes to your fork (`git push origin feature/your-feature-name`).\n7. Submit a pull request to the main repository's `main` branch.\n\nPlease be respectful and constructive in your interactions with others. We appreciate your contributions and look forward to working with you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarbwire-1%2Fgrapheme-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarbwire-1%2Fgrapheme-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarbwire-1%2Fgrapheme-counter/lists"}