New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nlcst-emoji-modifier

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nlcst-emoji-modifier - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

144

index.js
'use strict';
/* Dependencies. */
var has = require('has');
var toString = require('nlcst-to-string');

@@ -9,6 +7,6 @@ var modifier = require('unist-util-modify-children');

/* Expose. */
module.exports = modifier(mergeEmoji);
/* Node types. */
var own = {}.hasOwnProperty;
var EMOTICON_NODE = 'EmoticonNode';

@@ -28,3 +26,2 @@

/* Constants. */
var shortcodes = [];

@@ -43,6 +40,6 @@ var unicodes = gemoji.unicode;

var siblings = parent.children;
var value = toString(child);
var siblingIndex;
var node;
var nodes;
var value;
var subvalue;

@@ -57,9 +54,15 @@ var left;

var replace;
var startIndex;
var nextSibling;
var nextNextSibling;
var possibleEmoji;
var maxSiblingIndex;
var loopIndex;
var lastSibling;
var lastSiblingIndex;
if (child.type === 'WordNode') {
value = toString(child);
/* Sometimes a unicode emoji is marked as a
* word. Mark it as an `EmoticonNode`. */
if (has(unicodes, value)) {
/* 1️⃣ — sometimes a unicode emoji is marked as a word. Mark it as
* an `EmoticonNode`. */
if (own.call(unicodes, value)) {
node = {type: EMOTICON_NODE, value: value};

@@ -73,8 +76,7 @@

} else {
/* Sometimes a unicode emoji is split in two.
* Remove the last and add its value to
* the first. */
/* ❤️ — Sometimes a unicode emoji is split in two. Remove the last
* and add its value to the first. */
node = siblings[index - 1];
if (node && has(unicodes, toString(node) + value)) {
if (node && own.call(unicodes, toString(node) + value)) {
node.type = EMOTICON_NODE;

@@ -92,9 +94,108 @@ node.value = toString(node) + value;

}
} else if (has(unicodes, toString(child))) {
} else if (own.call(unicodes, value)) {
child.type = EMOTICON_NODE;
} else if (toString(child).charAt(0) === ':') {
startIndex = index + 1;
nextSibling = siblings[startIndex];
if (nextSibling.type === 'WordNode') {
/* 🏌 — Normal emoji. */
if (!isVarianceSelector(nextSibling)) {
return;
}
possibleEmoji = value + toString(nextSibling);
maxSiblingIndex = siblings.length;
loopIndex = startIndex + 1;
while (
loopIndex < maxSiblingIndex &&
(loopIndex - startIndex) < 5 &&
siblings[loopIndex].type !== 'WordNode'
) {
possibleEmoji += toString(siblings[loopIndex]);
loopIndex++;
}
lastSibling = siblings[loopIndex];
if (lastSibling && lastSibling.type === 'WordNode') {
possibleEmoji += toString(lastSibling);
}
/* 🏌️‍♀️ — Emoji with variance selector. */
if (own.call(unicodes, possibleEmoji)) {
child.value = possibleEmoji;
if (child.position && lastSibling.position) {
child.position.end = lastSibling.position.end;
}
siblings.splice(index + 1, loopIndex - index);
return index + 1;
}
/* 👨‍❤️‍💋‍👨 — combined emoji. */
} else if (nextSibling.type === 'SymbolNode') {
possibleEmoji = value + toString(nextSibling);
maxSiblingIndex = siblings.length;
loopIndex = startIndex + 1;
while (
loopIndex < maxSiblingIndex && (loopIndex - startIndex) < 5 &&
(
siblings[loopIndex].type === 'SymbolNode' ||
(siblings[loopIndex].type === 'WordNode' && isVarianceSelector(siblings[loopIndex]))
)
) {
possibleEmoji += toString(siblings[loopIndex]);
loopIndex++;
}
if (own.call(unicodes, possibleEmoji)) {
child.value = possibleEmoji;
lastSiblingIndex = loopIndex - 1;
lastSibling = siblings[lastSiblingIndex];
if (child.position && lastSibling.position) {
child.position.end = lastSibling.position.end;
}
siblings.splice(index + 1, lastSiblingIndex - index);
return index + 1;
}
}
/* 🤽‍♀ — Combined emoji starting in a symbol. */
} else if (child.type === 'SymbolNode') {
nextSibling = siblings[index + 1];
nextNextSibling = siblings[index + 2];
if (
(nextSibling.type === 'SymbolNode' || nextSibling.type === 'WordNode') &&
nextNextSibling && nextNextSibling.type === 'SymbolNode'
) {
possibleEmoji = value + toString(nextSibling) + toString(nextNextSibling);
if (own.call(unicodes, possibleEmoji)) {
child.type = EMOTICON_NODE;
child.value = possibleEmoji;
if (child.position && nextNextSibling.position) {
child.position.end = nextNextSibling.position.end;
}
siblings.splice(index + 1, 2);
return index + 1;
}
}
/* :+1: — Gemoji shortcodes. */
} else if (value.charAt(0) === ':') {
nodes = [];
siblingIndex = index;
subvalue = toString(child);
left = right = leftMatch = rightMatch = null;
subvalue = value;
left = null;
right = null;
leftMatch = null;
rightMatch = null;

@@ -224,1 +325,6 @@ if (subvalue.length === 1) {

}
function isVarianceSelector(node) {
var code = toString(node).charCodeAt(0);
return code > 65023 && code < 65040;
}

39

package.json
{
"name": "nlcst-emoji-modifier",
"version": "1.1.0",
"version": "2.0.0",
"description": "Emoji in NLCST",

@@ -10,26 +10,30 @@ "license": "MIT",

],
"repository": "syntax-tree/nlcst-emoji-modifier",
"bugs": "https://github.com/syntax-tree/nlcst-emoji-modifier/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"Hugo Dozois <hugo.dozois@gmail.com>"
],
"files": [
"data/emoji.json",
"index.js"
],
"dependencies": {
"gemoji": "^2.0.1",
"has": "^1.0.1",
"gemoji": "^4.2.0",
"nlcst-to-string": "^2.0.0",
"unist-util-modify-children": "^1.0.0"
},
"repository": "wooorm/nlcst-emoji-modifier",
"author": "Titus Wormer <tituswormer@gmail.com>",
"files": [
"data/emoji.json",
"index.js"
],
"devDependencies": {
"browserify": "^13.0.0",
"browserify": "^14.0.0",
"esmangle": "^1.0.0",
"is-hidden": "^1.1.0",
"negate": "^1.0.0",
"nyc": "^9.0.1",
"parse-english": "^3.0.0",
"remark-cli": "^2.1.0",
"remark-preset-wooorm": "^1.0.0",
"nyc": "^11.2.0",
"parse-english": "^4.1.0",
"remark-cli": "^4.0.0",
"remark-preset-wooorm": "^3.0.0",
"tape": "^4.6.2",
"unist-util-remove-position": "^1.1.0",
"xo": "^0.17.1"
"xo": "^0.18.2"
},

@@ -54,2 +58,3 @@ "scripts": {

"space": true,
"esnext": false,
"rules": {

@@ -64,4 +69,6 @@ "complexity": "off",

"remarkConfig": {
"presets": "wooorm"
"plugins": [
"preset-wooorm"
]
}
}

@@ -33,19 +33,22 @@ # nlcst-emoji-modifier [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

└─ ParagraphNode[1]
└─ SentenceNode[10]
├─ WordNode[1]
│ └─ TextNode: 'Who'
├─ WhiteSpaceNode: ' '
└─ SentenceNode[11]
├─ WordNode[3]
│ ├─ TextNode: 'doesn'
│ ├─ PunctuationNode: '’'
│ └─ TextNode: 't'
├─ WhiteSpaceNode: ' '
│ ├─ TextNode: "It"
│ ├─ PunctuationNode: "'"
│ └─ TextNode: "s"
├─ WhiteSpaceNode: " "
├─ WordNode[1]
│ └─ TextNode: 'like'
├─ WhiteSpaceNode: ' '
│ └─ TextNode: "raining"
├─ WhiteSpaceNode: " "
├─ EmoticonNode: ":cat:"
├─ WordNode[1]
│ └─ TextNode: 'Gemoji'
├─ WhiteSpaceNode: ' '
├─ EmoticonNode: ':+1:'
└─ PunctuationNode: '?'
│ └─ TextNode: "s"
├─ WhiteSpaceNode: " "
├─ WordNode[1]
│ └─ TextNode: "and"
├─ WhiteSpaceNode: " "
├─ EmoticonNode: ":dog:"
└─ WordNode[2]
├─ TextNode: "s"
└─ PunctuationNode: "."
```

@@ -55,9 +58,9 @@

### `emoji(sentence)`
### `emoji(paragraph)`
Merge affix emoticons into the previous sentence.
Merge emoji and gemoji into a new `EmoticonNode`.
###### Parameters
* `paragraph` ([`NLCSTSentenceNode`][sentence]).
* `paragraph` ([`NLCSTParagraphNode`][paragraph]).

@@ -70,9 +73,9 @@ ## License

[travis-badge]: https://img.shields.io/travis/wooorm/nlcst-emoji-modifier.svg
[travis-badge]: https://img.shields.io/travis/syntax-tree/nlcst-emoji-modifier.svg
[travis]: https://travis-ci.org/wooorm/nlcst-emoji-modifier
[travis]: https://travis-ci.org/syntax-tree/nlcst-emoji-modifier
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/nlcst-emoji-modifier.svg
[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/nlcst-emoji-modifier.svg
[codecov]: https://codecov.io/github/wooorm/nlcst-emoji-modifier
[codecov]: https://codecov.io/github/syntax-tree/nlcst-emoji-modifier

@@ -87,2 +90,2 @@ [npm]: https://docs.npmjs.com/cli/install

[sentence]: https://github.com/wooorm/nlcst#paragraphnode
[paragraph]: https://github.com/syntax-tree/nlcst#paragraph
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc