# emoji-parser

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

Latest version **0.1.2** (published 2016-08-28) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install emoji-parser
pnpm add emoji-parser
yarn add emoji-parser
bun add emoji-parser
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2016-08-28 |
| First published | 2014-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | FrissDieGurke |
| Maintainers | frissdiegurke |
| Keywords | emoji, parser, smileys |

## Links

- npm: https://www.npmjs.com/package/emoji-parser
- Repository: https://github.com/frissdiegurke/emoji-parser
- Homepage: https://github.com/frissdiegurke/emoji-parser#readme
- Issues: https://github.com/frissdiegurke/emoji-parser/issues
- npm.io page: https://npm.io/package/emoji-parser

## Dependencies (1)

- [wrench](https://npm.io/package/wrench.md) ~1.5.8

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2016-08-28
- 0.1.1 — 2014-09-21
- 0.1.0 — 2014-09-12
- 0.0.7 — 2014-07-28
- 0.0.6 — 2014-07-06
- 0.0.4 — 2014-07-06
- 0.0.3 — 2014-07-03
- 0.0.2 — 2014-07-03
- 0.0.1 — 2014-07-03

## README

# 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](https://github.com/arvida/emoji-cheat-sheet.com) of [emoji-cheat-sheet.com](http://www.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](https://github.com/frissdiegurke/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](https://github.com/HenrikJoreteg/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](#parser)) 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](#parser)) 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](#parser)) 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](#parser)) 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`

---
_Source: https://npm.io/package/emoji-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
