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 🙏

© 2024 – Pkg Stats / Ryan Hefner

grapheme-counter

v1.0.0

Published

This script allows to count graphemeClusters in a string or combined emojis as 1 character.

Downloads

2

Readme

Grapheme-Counter

Grapheme-Counter is a JavaScript library that provides functions for giving the "correct" length of any strings bycounting grapheme clusters in strings, 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.

Documentaion


Installation

You can install Grapheme-Counter via npm:

npm install grapheme-counter

Alternatively, you can directly include the GraphemeCounter.js file in your project.


API

  • initStringCountProperty() Initializes the count property on the String.prototype, allowing direct usage on strings.

  • countCharacters(str) Counts the number of grapheme clusters in the input string str, accounting for combined emoji sequences and diacritical marks.

  • str (String) The input string to count grapheme clusters in. Returns an object with the following properties:

  • count (Number) The count of grapheme clusters in the input string. Example-Counts

Usage

Using String.prototype.count Property

// Import and initialize the count property on String.prototype
import { initStringCountProperty } from 'grapheme-counter';
initStringCountProperty();

// Use the count property directly on strings
const text = 'A flag 🏳️‍🌈!!!';
console.log(text.count); // Output: 11

Using countCharacters Function-return ({count})

// Import the countCharacters function
import { countCharacters } from 'grapheme-counter';

// Count grapheme clusters in a string
const text = 'A flag 🏳️‍🌈!!!';
const count = countCharacters(text).count;
console.log('Grapheme cluster count:', count); // Output: 11

Examples


Compatibility

  • Requires ECMAScript 6 (ES6) support.
  • Compatible with modern browsers and environments that support Unicode regular expressions.

License

Grapheme Counter is licensed under the MIT License.

Reporting Issues

If you encounter any bugs, have suggestions for improvements, or would like to request new features, please open an issue on GitHub. When reporting issues, please include detailed information such as:

  • Steps to reproduce the issue
  • Expected behavior
  • Actual behavior
  • Any error messages or console logs

Your feedback is valuable and helps improve the quality of the project. Thank you for contributing!

Contributing

We welcome contributions from the community! If you'd like to contribute to this project, please follow these guidelines:

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your changes (git checkout -b feature/your-feature-name).
  3. Make your changes and ensure they follow the project's coding style and conventions.
  4. Write tests for your changes if applicable (I know, I didn't).
  5. Commit your changes with a clear and descriptive message.
  6. Push your changes to your fork (git push origin feature/your-feature-name).
  7. Submit a pull request to the main repository's main branch.

Please be respectful and constructive in your interactions with others. We appreciate your contributions and look forward to working with you!