retext-emoji
Advanced tools
Comparing version 6.0.0 to 7.0.0
102
index.js
@@ -6,9 +6,11 @@ 'use strict' | ||
var emojiModifier = require('nlcst-emoji-modifier') | ||
var toString = require('nlcst-to-string') | ||
var visit = require('unist-util-visit') | ||
var emoticons = require('emoticon') | ||
var toString = require('nlcst-to-string') | ||
var gemoji = require('gemoji') | ||
var visit = require('unist-util-visit') | ||
module.exports = emoji | ||
var own = {}.hasOwnProperty | ||
var type = 'EmoticonNode' | ||
@@ -22,6 +24,6 @@ | ||
var unicodes = gemoji.unicode | ||
var names = gemoji.name | ||
var emoji2info = {} | ||
var shortcodes = {} | ||
var emoticon2emoji = {} | ||
var gemoji2emoji = {} | ||
@@ -60,19 +62,17 @@ init() | ||
function visitor(node) { | ||
var data = node.data | ||
var value = toString(node) | ||
var emoji = parse(toString(node)) | ||
var info | ||
var data | ||
if (!emoji) return | ||
if (fn) { | ||
fn(node) | ||
node.value = fn(emoji) | ||
} | ||
info = unicodes[value] || shortcodes[value] || emoticons[value] | ||
if (!data) { | ||
data = {} | ||
node.data = data | ||
} | ||
info = emoji2info[emoji] | ||
data = node.data || (node.data = {}) | ||
data.emoji = info.emoji | ||
data.description = info.description | ||
data.names = info.names.concat() | ||
data.description = info.description | ||
data.tags = info.tags.concat() | ||
@@ -82,51 +82,57 @@ } | ||
// Replace a unicode emoji with a short-code. | ||
function toGemoji(node) { | ||
var value = toString(node) | ||
var info = (unicodes[value] || emoticons[value] || {}).shortcode | ||
// Map a value to an emoji. | ||
function parse(value) { | ||
if (own.call(emoji2info, value)) return value | ||
if (own.call(emoticon2emoji, value)) return emoticon2emoji[value] | ||
if (own.call(gemoji2emoji, value)) return gemoji2emoji[value] | ||
} | ||
if (info) { | ||
node.value = info | ||
} | ||
// Change to a GitHub emoji short-code. | ||
function toGemoji(emoji) { | ||
return ':' + emoji2info[emoji].names[0] + ':' | ||
} | ||
// Replace a short-code with a unicode emoji. | ||
function toEmoji(node) { | ||
var value = toString(node) | ||
var info = (shortcodes[value] || emoticons[value] || {}).emoji | ||
if (info) { | ||
node.value = info | ||
} | ||
// Change to an emoji. | ||
function toEmoji(emoji) { | ||
return emoji | ||
} | ||
// Construct dictionaries. | ||
function init() { | ||
var key | ||
var shortcode | ||
var result = {} | ||
var length = emoticons.length | ||
var length = gemoji.length | ||
var index = -1 | ||
var info | ||
var offset | ||
var count | ||
var offset | ||
var subset | ||
var name | ||
var values | ||
var value | ||
for (key in names) { | ||
shortcode = ':' + key + ':' | ||
shortcodes[shortcode] = names[key] | ||
shortcodes[shortcode].shortcode = shortcode | ||
while (++index < length) { | ||
info = gemoji[index] | ||
values = info.names | ||
count = values.length | ||
offset = -1 | ||
emoji2info[info.emoji] = info | ||
while (++offset < count) { | ||
value = values[offset] | ||
gemoji2emoji[':' + value + ':'] = info.emoji | ||
} | ||
} | ||
index = -1 | ||
length = emoticons.length | ||
while (++index < length) { | ||
name = emoticons[index].name | ||
subset = emoticons[index].emoticons | ||
count = subset.length | ||
info = emoticons[index] | ||
values = info.emoticons | ||
count = values.length | ||
offset = -1 | ||
while (++offset < count) { | ||
result[subset[offset]] = names[name] | ||
value = values[offset] | ||
emoticon2emoji[value] = info.emoji | ||
} | ||
} | ||
emoticons = result | ||
} |
{ | ||
"name": "retext-emoji", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "retext plugin to support emoji, gemoji, and emoticons", | ||
@@ -9,2 +9,3 @@ "license": "MIT", | ||
"retext", | ||
"retext-plugin", | ||
"plugin", | ||
@@ -17,2 +18,6 @@ "gemoji", | ||
"bugs": "https://github.com/retextjs/retext-emoji/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
@@ -27,20 +32,20 @@ "contributors": [ | ||
"emoticon": "^3.1.0", | ||
"gemoji": "^4.2.0", | ||
"gemoji": "^5.0.0", | ||
"nlcst-affix-emoticon-modifier": "^1.0.0", | ||
"nlcst-emoji-modifier": "^3.0.0", | ||
"nlcst-emoji-modifier": "^4.0.0", | ||
"nlcst-emoticon-modifier": "^1.0.0", | ||
"nlcst-to-string": "^2.0.0", | ||
"unist-util-visit": "^1.0.0" | ||
"unist-util-visit": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^14.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"retext": "^6.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"retext": "^7.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"unist-builder": "^1.0.4", | ||
"xo": "^0.24.0" | ||
"unist-builder": "^2.0.0", | ||
"xo": "^0.28.0" | ||
}, | ||
@@ -47,0 +52,0 @@ "scripts": { |
@@ -71,2 +71,3 @@ # retext-emoji | ||
interface EmoticonData { | ||
emoji: string | ||
names: [string] | ||
@@ -85,14 +86,2 @@ description: string? | ||
See [`contributing.md` in `retextjs/retext`][contributing] for ways to get | ||
started. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
## License | ||
[MIT][license] © [Titus Wormer][author] | ||
<!-- Definitions --> | ||
See [`contributing.md`][contributing] in [`retextjs/.github`][health] for ways | ||
@@ -134,3 +123,3 @@ to get started. | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
@@ -137,0 +126,0 @@ [chat]: https://spectrum.chat/unified/retext |
106
9512
148
+ Added@types/unist@2.0.11(transitive)
+ Addedemoji-regex@9.2.2(transitive)
+ Addedgemoji@5.0.16.1.0(transitive)
+ Addednlcst-emoji-modifier@4.1.1(transitive)
+ Addedunist-util-is@4.1.0(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedgemoji@4.2.1(transitive)
- Removednlcst-emoji-modifier@3.0.0(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
Updatedgemoji@^5.0.0
Updatednlcst-emoji-modifier@^4.0.0
Updatedunist-util-visit@^2.0.0