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

emojicharstring

v0.1.2

Published

[![npm version](https://badge.fury.io/js/emojicharstring.svg)](https://badge.fury.io/js/emojicharstring) [![Build Status](https://travis-ci.org/YingshanDeng/EmojiCharString.svg?branch=master)](https://travis-ci.org/YingshanDeng/EmojiCharString) [![Coverag

Downloads

12

Readme

EmojiCharString

npm version Build Status Coverage Status JavaScript Style Guide

When the string contains emoji, we use String.prototype.length cannot get the characters count correctly! Such as:

  • '👦🏿'.length return 4, it should be 1!
  • '👨‍👩‍👦'.length return 8, it alse should be 1!

EmojiCharString is based on a RegExp to work with JavaScript String's unicode problem. It can solve the problem above.

❗️Note that it is not for good performance but for accuracy, because it uses a complex RegExp to analyze the string.

Install

Using NPM, install EmojiCharString, and add it to your package.json dependencies.

npm install emojicharstring --save

And then you can import it

// CommonJS
const EmojiCharString = require('EmojiCharString');

// or ES6
import EmojiCharString from 'EmojiCharString'

Or include the file in your HTML page using the following tags:

<script src="/path/to/dist/EmojiCharString.min.js"></script>

Usage

initialise EmojiCharString

var emojiStr = new EmojiCharString('👦🏿')

length

Get the string's length correctly.

var emojiStr = new EmojiCharString('👦🏿')
var len = emojiStr.length // 1

toString

Get the string you pass in.

var emojiStr = new EmojiCharString('hello')
var str = emojiStr.toString() // hello

reverse ()

Reverse the string in place.

var emojiStr = new EmojiCharString('👦🏿👨‍👩‍👦')
console.log(emojiStr.reverse()) // '👨‍👩‍👦👦🏿'

substring (begin = 0, end)

The substring() method returns a subset of a string between begin index and end index

| Param | Type | Default | Description | |---|---|---|---| | begin | Number | 0 | begin index | | end | Number | none | end index |

var emojiStr = new EmojiCharString('👨‍👨‍👦 our family 我们一家 ❤️')
console.log(emojiStr.substring(2, 5)) // 'our'

substr (begin = 0, len)

The substr() method return the characters in a string beginning at the specified location through the specified number of characters.

| Param | Type | Default | Description | |---|---|---|---| | begin | Number | 0 | Location at which to begin extracting characters | | len | Number | none | The number of characters to extract |

var emojiStr = new EmojiCharString('👨‍👨‍👦 our family 我们一家 ❤️')
console.log(emojiStr.substr(2, 5)) // 'our f'

License

MIT