-
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from JoshuaKGoldberg/v2-refactor-refactor
v2 Refactor, Refactored
- Loading branch information
Showing
14 changed files
with
5,952 additions
and
4,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
node_modules | ||
*.log | ||
*.sublime-project | ||
*.sublime-workspace | ||
*.txt | ||
test.js | ||
coverage | ||
coverage/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "0.10" | ||
- "lts/*" | ||
- "node" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,228 @@ | ||
# node-emoji | ||
|
||
[![NPM version (1.0.3)](https://img.shields.io/npm/v/node-emoji.svg?style=flat-square)](https://www.npmjs.com/package/node-emoji) [![NPM Downloads](https://img.shields.io/npm/dm/node-emoji.svg?style=flat-square)](https://www.npmjs.com/package/node-emoji) [![Build Status](https://img.shields.io/travis/omnidan/node-emoji/master.svg?style=flat-square)](https://travis-ci.org/omnidan/node-emoji) [![Dependencies](https://img.shields.io/david/omnidan/node-emoji.svg?style=flat-square)](https://david-dm.org/omnidan/node-emoji) [![https://paypal.me/DanielBugl/9](https://img.shields.io/badge/donate-paypal-yellow.svg?style=flat-square)](https://paypal.me/DanielBugl/9) | ||
[![NPM Version](https://img.shields.io/npm/v/node-emoji.svg?style=flat-square)](https://www.npmjs.com/package/node-emoji) | ||
[![NPM Downloads](https://img.shields.io/npm/dm/node-emoji.svg?style=flat-square)](https://www.npmjs.com/package/node-emoji) | ||
[![Build Status](https://img.shields.io/travis/omnidan/node-emoji/master.svg?style=flat-square)](https://travis-ci.org/omnidan/node-emoji) | ||
[![https://paypal.me/DanielBugl/9](https://img.shields.io/badge/donate-paypal-yellow.svg?style=flat-square)](https://paypal.me/DanielBugl/9) | ||
|
||
_simple emoji support for node.js projects_ | ||
_Friendly emoji lookups and parsing utilities for Node.js._ β¨ | ||
|
||
![node-emoji example](https://i.imgur.com/yIo5Uux.png) | ||
`node-emoji` provides a fun, straightforward interface on top of the following excellent libraries: | ||
|
||
**Help wanted:** We are looking for volunteers to maintain this project, if you are interested, feel free to contact me at [me@omnidan.net](mailto:me@omnidan.net) | ||
- [`emojilib`](https://npmjs.org/package/emojilib): provides a list of emojis and keyword search on top of it | ||
- [`skin-tone`](https://npmjs.org/package/skin-tone): parses out base emojis from skin tones | ||
|
||
## Installation | ||
To install `node-emoji`, you need [node.js](http://nodejs.org/) and [npm](https://github.com/npm/npm#super-easy-install). :rocket: | ||
> **Help wanted:** We are looking for volunteers to maintain this project. | ||
> If you are interested, feel free to contact me at [me@omnidan.net](mailto:me@omnidan.net). | ||
Once you have that set-up, just run `npm install --save node-emoji` in your project directory. :ship: | ||
## Install | ||
|
||
You're now ready to use emoji in your node projects! Awesome! :metal: | ||
```sh | ||
npm install node-emoji | ||
``` | ||
|
||
## Usage | ||
```javascript | ||
var emoji = require('node-emoji') | ||
emoji.get('coffee') // returns the emoji code for coffee (displays emoji on terminals that support it) | ||
emoji.which(emoji.get('coffee')) // returns the string "coffee" | ||
emoji.get(':fast_forward:') // `.get` also supports github flavored markdown emoji (http://www.emoji-cheat-sheet.com/) | ||
emoji.emojify('I :heart: :coffee:!') // replaces all :emoji: with the actual emoji, in this case: returns "I β€οΈ βοΈ!" | ||
emoji.random() // returns a random emoji + key, e.g. `{ emoji: 'β€οΈ', key: 'heart' }` | ||
emoji.search('cof') // returns an array of objects with matching emoji's. `[{ emoji: 'βοΈ', key: 'coffee' }, { emoji: β°', key: 'coffin'}]` | ||
emoji.unemojify('I β€οΈ π') // replaces the actual emoji with :emoji:, in this case: returns "I :heart: :pizza:" | ||
emoji.find('π') // Find the `pizza` emoji, and returns `({ emoji: 'π', key: 'pizza' })`; | ||
emoji.find('pizza') // Find the `pizza` emoji, and returns `({ emoji: 'π', key: 'pizza' })`; | ||
emoji.hasEmoji('π') // Validate if this library knows an emoji like `π` | ||
emoji.hasEmoji('pizza') // Validate if this library knowns a emoji with the name `pizza` | ||
emoji.strip('β οΈ γ°οΈ γ°οΈ low disk space') // Strips the string from emoji's, in this case returns: "low disk space". | ||
emoji.replace('β οΈ γ°οΈ γ°οΈ low disk space', (emoji) => `${emoji.key}:`) // Replace emoji's by callback method: "warning: low disk space" | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
emoji.emojify('I :heart: :coffee:!') // 'I β€οΈ βοΈ!' | ||
|
||
emoji.find('heart') // { emoji: 'β€', name: 'heart' } | ||
emoji.find('β€οΈ') // { emoji: 'β€', name: 'heart' } | ||
|
||
emoji.get('unicorn') // π¦ | ||
emoji.get(':unicorn:') // π¦ | ||
|
||
emoji.has(':pizza:') // true | ||
emoji.has('π') // true | ||
emoji.has('unknown') // false | ||
|
||
emoji.random() // { name: 'house', emoji: 'π ' } | ||
|
||
emoji.replace('I β€οΈ coffee!', 'love') // 'I love coffee!' | ||
|
||
emoji.search(':uni:') // [ { emoji: 'π¦', name: 'unicorn' }, ... ] | ||
|
||
emoji.strip('I β€οΈ coffee!') // 'I coffee!' | ||
|
||
emoji.unemojify('π for π') // ':pizza: for :dancer:' | ||
|
||
emoji.which('π¦') // 'unicorn' | ||
``` | ||
|
||
Note: There are some emojis that have "-" in their name, for example "t-rex" and refrencing them directly like this `(emoji.t-rex)` won't work. In such cases, use the `emoji.get('t-rex')` syntax instead | ||
## API | ||
|
||
### emoji.emojify(input, options?) | ||
|
||
## Options | ||
Parse all markdown-encoded emojis in a string. | ||
|
||
### onMissing | ||
`emoji.emojify(str, onMissing)` | ||
Parameters: | ||
|
||
As second argument, `emojify` takes an handler to parse unknown emojis. Provide a function to add your own handler: | ||
1. **`input`** (`string`): The input string containing the markdown-encoding emojis. | ||
1. **`options`** _(optional)_: | ||
- **`fallback`** (`string`; default: `""`): The string to fallback to if an emoji was not found. | ||
- **`format`** (`() => (emoji: string, part: string, string: string) => string`; default: `value => value`): Add a middleware layer to modify each matched emoji after parsing. | ||
|
||
```js | ||
var onMissing = function (name) { | ||
return name; | ||
}); | ||
const emoji = require('node-emoji') | ||
|
||
var emojified = emoji.emojify('I :unknown_emoji: :star: :another_one:', onMissing); | ||
// emojified: I unknown_emoji βοΈ another_one | ||
console.log(emoji.emojify('The :unicorn: is a fictitious animal.')) | ||
// 'The π¦ is a fictitious animal.' | ||
``` | ||
|
||
### format | ||
`emoji.emojify(str, onMissing, format)` | ||
### emoji.find(emoji) | ||
|
||
Get the name and character of an emoji. | ||
|
||
Parameters: | ||
|
||
As third argument, `emojify` takes an handler to wrap parsed emojis. Provide a function to place emojis in custom elements, and to apply your custom styling: | ||
1. **`emoji`** (`string`): The emoji to get the data of. | ||
|
||
```js | ||
var format = function (code, name) { | ||
return '<img alt="' + code + '" src="' + name + '.png" />'; | ||
}); | ||
const emoji = require('node-emoji') | ||
|
||
var emojified = emoji.emojify('I :unknown_emoji: :star: :another_one:', null, format); | ||
// emojified: I <img alt="β€οΈ" src="heart.png" /> <img alt="βοΈ" src="coffee.png" /> | ||
console.log(emoji.find('π¦')) | ||
// { name: 'unicorn', emoji: 'π¦' } | ||
``` | ||
|
||
## Adding new emoji | ||
Emoji come from js-emoji (Thanks a lot :thumbsup:). You can get a JSON file with all emoji here: https://raw.githubusercontent.com/omnidan/node-emoji/master/lib/emoji.json | ||
### emoji.get(name) | ||
|
||
To update the list or add custom emoji, clone this repository and put them into `lib/emojifile.js`. | ||
Then run `npm run-script emojiparse` in the project directory or `node emojiparse` in the lib directory. | ||
This should generate the new emoji.json file and output `Done.`. | ||
Get an emoji from an emoji name. | ||
|
||
That's all, you now have more emoji you can use! :clap: | ||
Parameters: | ||
|
||
## Support / Donations | ||
If you want to support node-emoji development, please consider donating (it helps me keeping my projects active and alive!): | ||
1. **`name`** (`string`): The name of the emoji to get. | ||
|
||
* Paypal: [![daniel.bugl@gmail.com](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YBMS9EKTNPZHJ) | ||
* Bitcoin: [1J5eKsrAcPPLv5gPxSjSUkXnbJpkhndFgA](bitcoin:1J5eKsrAcPPLv5gPxSjSUkXnbJpkhndFgA) | ||
|
||
## Special Thanks | ||
```js | ||
const emoji = require('node-emoji') | ||
|
||
... to Anand Chowdhary (@AnandChowdhary) and his company Pabio (https://github.com/pabio) for sponsoring this project via [GitHub Sponsors](https://github.com/sponsors/omnidan)! | ||
console.log(emoji.get('unicorn')) | ||
// 'π¦' | ||
``` | ||
|
||
### emoji.has(emoji) | ||
|
||
Check if this library supports a specific emoji. | ||
|
||
Parameters: | ||
|
||
1. **`emoji`** (`string`): The emoji to check. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.has('π¦')) | ||
// true | ||
``` | ||
|
||
### emoji.random() | ||
|
||
Get a random emoji. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.random()) | ||
// { name: 'unicorn', emoji: 'π¦' } | ||
``` | ||
|
||
### emoji.replace(input, replacement) | ||
|
||
Replace the emojis in a string. | ||
|
||
Parameters: | ||
|
||
- **`input`** (`string`): The input string. | ||
- **`replacement`** (`string | (emoji: string, index: number, string: InputValueType) => string`): The character to replace the emoji with. Can be either a string or a callback that returns a string. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.replace('The π¦ is a fictitious animal.', 'unicorn')) | ||
// 'The unicorn is a fictitious animal.' | ||
``` | ||
|
||
### emoji.search(keyword) | ||
|
||
Search for emojis containing the provided name in their name. | ||
|
||
Parameters: | ||
|
||
1. **`keyword`** (`string`): The keyword to search for. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.search('honey')) | ||
// [ { name: 'honeybee', emoji: 'π' }, { name: 'honey_pot', emoji: 'π―' } ] | ||
``` | ||
|
||
### emoji.strip(input, options?) | ||
|
||
Remove all of the emojis from a string. | ||
|
||
Parameters: | ||
|
||
1. **`input`** (`string`): The input string to strip the emojis from. | ||
1. **`options`** _(optional)_: | ||
|
||
- **`preserveSpaces`** (`boolean`): Whether to keep the extra space after a stripped emoji. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.strip('π¦ The unicorn is a fictitious animal.')) | ||
// 'The unicorn is a fictitious animal.' | ||
|
||
console.log( | ||
emoji.strip('π¦ The unicorn is a fictitious animal.', { | ||
preserveSpaces: true, | ||
}) | ||
) | ||
// ' The unicorn is a fictitious animal.' | ||
``` | ||
|
||
### emoji.unemojify(input) | ||
|
||
Convert all emojis in a string to their markdown-encoded counterparts. | ||
|
||
Parameters: | ||
|
||
1. **`input`** (`string`): The input string containing the emojis. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.unemojify('The π¦ is a fictitious animal.')) | ||
// 'The :unicorn: is a fictitious animal.' | ||
``` | ||
|
||
### emoji.which(emoji) | ||
|
||
Get an emoji name from an emoji. | ||
|
||
Parameters: | ||
|
||
1. **`emoji`** (`string`): The emoji to get the name of. | ||
|
||
```js | ||
const emoji = require('node-emoji') | ||
|
||
console.log(emoji.which('π¦')) | ||
// 'unicorn' | ||
``` | ||
|
||
## License | ||
|
||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fomnidan%2Fnode-emoji.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fomnidan%2Fnode-emoji?ref=badge_large) | ||
|
||
## Sponsorship | ||
|
||
- [GitHub Sponsors](https://github.com/sponsors/omnidan) | ||
- Paypal: [![daniel.bugl@gmail.com](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YBMS9EKTNPZHJ) | ||
- Bitcoin: [1J5eKsrAcPPLv5gPxSjSUkXnbJpkhndFgA](bitcoin:1J5eKsrAcPPLv5gPxSjSUkXnbJpkhndFgA) | ||
|
||
### Special Thanks | ||
|
||
... to Anand Chowdhary (@AnandChowdhary) and his company Pabio (https://github.com/pabio) for sponsoring this project via [GitHub Sponsors](https://github.com/sponsors/omnidan)! |
Oops, something went wrong.