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

@yukaii/emojify.js

v2.0.3

Published

A Javascript module to convert emoji keywords to images.

Downloads

1

Readme

emojify.js

Note: This is fork rewrite version of emojify.js with TypeScript and up-to-date dependencies.


A swiss-army-knife for all emoji, in Javascript. Used by Gitter and Mapbox.

The emoji keywords are as described by emoji-cheat-sheet.com.

Features

  • Fast
  • Awesome
  • Converts emoticons like :) :( :'(
  • Allows customisation of processed emoji
  • Multiple modes; img, sprites and data-URI
  • Available on a CDN (gasp)
  • Includes a sample .htaccess file for caching Javascript and CSS
  • Switchable emoji sets (SOON!)
  • Made from unicorn blood

Installation

Via npm

npm install @yukaii/emojify.js --save

API

setConfig([object])

This works in the browser and on Node

Parameters

  • object - Optional JSON object with any of the following attributes:

Option | Default | Description --- | --- | --- blacklist.elements | ['script', 'textarea', 'a', 'pre', 'code'] | An array of elements you don't want emojified blacklist.classes | ['no-emojify'] | An array of classes you don't want emojified mode | img | By default, emojify will output an img with a src attribute for each emoji found. But if mode is set to sprite or data-uri, then spans with classes are outputted. Don't forget to include the appropriate CSS for your choice though, see the /dist directory. tag_type | null | When set, emojify uses this element with the class emoji emoji-#{emojiname} instead of an img with a src attribute. Example valid values: div, span. This takes precedence over the mode option. Note: if you're not using imgs, .emoji-+1 isn't a valid class, so .emoji-plus1 is used instead. only_crawl_id | null | [DEPRECATED] Restricts searching for emojis to a specified element & it's children. If null, and no object is passed to run(), document.body is used img_dir | 'images/emoji' | Defines the path to the emoji images ignore_emoticons | false | If true, only convert emoji like :smile: and ignore emoticons like :)

Usage

emojify.setConfig({tag_type : 'div'});

run([element], [replacer])

This works in the browser and Node

Parameters

  • element - Optional HTML element to restrict the emojification to.
  • replacer - Optional Function to override emoji replacement behaviour with your own. The function will receive two arguments, the emoji pattern found (emoji), and the emoji name (name). In the case of emoticons, for example, emoji = ':)' and name = 'smile'. Your function must return a HTMLElement.
Browser
emojify.run();
// OR
emojify.run(document.getElementById('my-element'))
// OR
emojify.run(null, function(emoji, emojiName){
  var span = document.createElement('span');
  span.className = 'emoji emoji-'  + emojiName;
  span.innerHTML = emoji + ' replaced';
  return span;
});
Node.js

Requires you to have jsdom installed: npm i jsdom --save

var jsdom = require('jsdom')

jsdom.env({
    html: "<p><code>jhhh</code><em>:)</em></p>",
    done: function(errors, window) {
        emojify.run(window.document.body)
    }
});

replace(string, [callback])

This works in the browser and on Node

Parameters

  • string - String to emojify
  • callback - Optional callback function to output emoji with

Usage

By default, emojify.js uses the internal function defaultReplacer() to replace emoji. You can override this behaviour by supplying your own callback function.

Your callback function will receive two arguments, the emoji pattern found (emoji), and the emoji name (name). In the case of emoticons, for example, emoji = ':)' and name = 'smile'.

The context in which your replacer function is run will have the config available. So you can access properties such as img_dir at this.config.img_dir.

emojify.replace('I am happy :)');
// OR
replacer = function(emoji, name) {
    // Customise output here
    return emojifiedString;
}

emojify.replace('I am happy :)', replacer);

Contributing changes

Please read CONTRIBUTING.md.

Credits

License

Please read LICENSE.md. For image attributions, please read LICENSE-IMAGES.md