Hyuchia / character-count

A simple utility to count characters equally

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Character Count

Counting characters in a string seems like a trivial thing until emojis get involved. This simple function will allow you to count emojis in a string as a single character each.

Installation

This library is provided as an UMD module that can be installed by adding the files manually to your project or via a package manager.

Yarn

yarn add @blac-sheep/character-count

NPM

npm install @blac-sheep/character-count

Adding it manually

<script src="character-count.min.js"></script>

Usage

NodeJS

const characterCount = require('@blac-sheep/character-count').default;

ES6

import characterCount from '@blac-sheep/character-count';

Browser

const characterCount = CharacterCount.default;

Examples

countCharacters('Hi there! πŸ‘©πŸΏβ€πŸ¦½'); // returns: 11
countCharacters('🀲🏿'); // returns: 1
countCharacters('πŸ‘©β€πŸ‘§β€πŸ‘§'); // returns: 1
countCharacters('πŸ‘©β€πŸ‘§β€πŸ‘§πŸ‘©β€πŸ‘§β€πŸ‘§'); // returns: 2
countCharacters('πŸ‘©β€πŸ‘§β€πŸ‘§πŸ‘©β€πŸ‘§β€πŸ‘§πŸ‘©β€πŸ‘§β€πŸ‘§'); // returns: 3
countCharacters('πŸ˜€'); // returns: 1

License

This library is released under the MIT license.

About

A simple utility to count characters equally

License:MIT License


Languages

Language:JavaScript 100.0%