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

@asmala/emoji-parser

v1.0.0

Published

Emoji Parser for Node.js based on www.Emoji-Cheat-Sheet.com

Downloads

47

Readme

This is a "fork" of https://github.com/frissdiegurke/emoji-parser. Since the original repository has disappeared, the files in this repository are from the npm package. They were uglified so running them through prettier helped a bit but not much.


emoji-parser for node.js and bower

About

Server-Side (node.js)

This script makes it easy to keep the emoji-images in sync with the official repository of emoji-cheat-sheet.com. It's just an additional call on server-startup (or whenever you want to synchronize).

The actual parsing works without any DOM-manipulation or whatever, just a simple replace call.

Client-Side (bower)

The actual bower-component is located within the emoji-parser-bower repository, but it gets generated by grunt using only files within this repository.

On client-side you may use this script to easily parse the emoji (like server-side) without any DOM-manipulation.

When used client-side this module of cause cannot ensure that you're using the latest emoji images but I'll try to keep it up-to-date :wink:.

Why another one?

This project is inspired by emoji-images, but this project hasn't been modified for some time now and the author isn't responding to issues.

Because of this and a few more customizations I rewrote this in coffee-script which is much more fun to code :smile:.

So this has become way more customizable (up to passing own parser-function) and the emoji-synchronization happens server-side instead of project-side.

Usage

API

node.js (server-side)

var emojiParser = require('emoji-parser');

  • emojiParser.init([directory]) initializes the module.

    • directory (default: module-path + '/emoji') - The file-system path of the directory where to store the images (without trailing /).
  • emojiParser.update([remain], [token], [callback]) downloads missing emoji images to keep your images up-to-date.

    • remain (default: true) - If false the directory gets cleared before downloading all images. Otherwise only images get loaded that don't already exist.
    • token (default: null) - If set it will get used as GitHub access_token.
    • callback (default: null) - Function that gets called after update is complete.
  • [String] emojiParser.parse(text, url, [options]) replaces all emoji-occurrences within given text.

    • text - The text to parse.
    • url - The base-url where the clients find the images (without trailing /).
    • options (default: {}) - The options to use for parsing:
      • list: A list of emoji to overwrite default one.
      • parser: A Parser (see below) to replace the default parser.
      • classes: A String of the content for the class-attribute of the img-tag (default parser).
      • attributes (default: {'title':function(match,name,parameter){if (parameter != null) return parameter + " (" + name + ")"; else return name;}, 'alt':function(match){return match;}}): An object of attributes and their value-producing function (gets passed matching string, emoji-name and parameter (if any): ":smiley[parameter]:", "smiley", "parameter"). The attributes get added to the img-tag with the generated values (default parser).
    • Returns the text with parsed emoji.
  • [String] emojiParser.parse(text, url, parser) replaces all emoji-occurrences within given text, using given parser.

    • text - The text to parse.
    • url - The base-URL to pass to the parser (without trailing /).
    • parser - The Parser (see below) to use.
    • Returns the text with parsed emoji.
  • [Array of Strings] emojiParser.list([newList]) - Getter and/or Setter for the list of available images.

    • newList (default: null) - The list to use for parsing, gets ignored if null.
    • Returns the list of emoji that get used for parsing (not sorted).
  • [Array of Strings] emojiParser.emoji - The list of images that have been found on file-system or got downloaded by emojiParser.update(...).

bower (client-side)

If you use require.js or similar frameworks you can use it to get the module, otherwise you can use window.emojiParser.

  • [String] emojiParser(text, url, [options]) replaces all emoji-occurrences within given text.

    • text - The text to parse.
    • url - The base-url where the clients find the images (without trailing /).
    • options (default: {}) - The options to use for parsing:
      • list: A list of emoji to overwrite default one.
      • parser: A Parser (see below) to replace the default parser.
      • classes: A String of the content for the class-attribute of the img-tag (default parser).
      • attributes (default: {'title':function(match,name,parameter){if (parameter != null) return parameter + " (" + name + ")"; else return name;}, 'alt':function(match){return match;}}): An object of attributes and their value-producing function (gets passed matching string, emoji-name and parameter (if any): ":smiley[parameter]:", "smiley", "parameter"). The attributes get added to the img-tag with the generated values (default parser).
  • [String] emojiParser(text, url, parser) replaces all emoji-occurrences within given text, using given parser.

    • text - The text to parse.
    • url - The base-URL to pass to the parser (without trailing /).
    • parser - The Parser (see below) to use.
    • Returns the text with parsed emoji.
  • [Array of Strings] emojiParser.list([newList]) - Getter and/or Setter for the list of available images.

    • newList (default: null) - The list to use for parsing, gets ignored if null.
    • Returns the list of emoji that get used for parsing (not sorted).

Parser

A parser is just a function that gets called for each emoji-occurrence with the following parameters:

  1. [Array] match - An array containing the string that gets interpreted as emoji, the name of the emoji and the parameter for the emoji (if any)
  2. [String] url - The base-URL that got passed to emojiParser.parse-function.
  3. [String] classes - The classes the img-tag should use.
  4. [Object] options - The options that get used by the emojiParser.parse-function.

The return-value will replace the emoji-occurrence.

Example

node.js

var emoji = require("emoji-parser");

// keep emoji-images in sync with the official repository
emoji.init().update();

// calls to http://example.com/emoji/images/*.png should resolve to path/to/node_modules/emoji-parser/emoji/*.png
emoji.parse(
  "This is a :telephone: :smiley[:D]:",
  "http://example.com/emoji/images"
);
// This is a <img class="emoji" src="http://example.com/emoji/images/telephone.png" title="telephone" alt=":telephone:" /> <img class="emoji" src="http://example.com/emoji/images/smiley.png" title=":D (smiley)" alt=":smiley[:D]:" />

bower

var emoji = require ? require("emoji-parser") : window.emojiParser;

emoji("This is a :telephone: :smiley[:D]:", "http://example.com/emoji/images");
// This is a <img class="emoji" src="http://example.com/emoji/images/telephone.png" title="telephone" alt=":telephone:" /> <img class="emoji" src="http://example.com/emoji/images/smiley.png" title=":D (smiley)" alt=":smiley[:D]:" />

Installation

node.js

npm install emoji-parser

bower

bower install emoji-parser