0.2.0 โ€ข Published 2 years ago

@blac-sheep/character-count v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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.