nlcst-emoji-modifier
Advanced tools
Comparing version 0.1.0 to 0.2.0
56
index.js
@@ -180,54 +180,4 @@ 'use strict'; | ||
/** | ||
* Move emoticons following a terminal marker (thus in | ||
* the next sentence) to the previous sentence. | ||
* | ||
* @param {NLCSTNode} child | ||
* @param {number} index | ||
* @param {NLCSTParagraphNode} parent | ||
* @return {undefined|number} | ||
*/ | ||
var emojiModifier; | ||
function mergeAffixEmoji(child, index, parent) { | ||
var children, | ||
prev, | ||
position, | ||
node; | ||
children = child.children; | ||
if ( | ||
children && | ||
children.length && | ||
index !== 0 | ||
) { | ||
position = -1; | ||
while (children[++position]) { | ||
node = children[position]; | ||
if (node.type === EMOTICON_NODE) { | ||
prev = parent.children[index - 1]; | ||
prev.children = prev.children.concat( | ||
children.slice(0, position + 1) | ||
); | ||
child.children = children.slice(position + 1); | ||
/** | ||
* Next, iterate over the node again. | ||
*/ | ||
return index; | ||
} else if (node.type !== 'WhiteSpaceNode') { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
var emojiModifier, | ||
affixEmojiModifier; | ||
function attach(parser) { | ||
@@ -243,3 +193,3 @@ if (!parser || !parser.parse) { | ||
/** | ||
* Make sure to not re-attach the modifiers. | ||
* Make sure to not re-attach the modifier. | ||
*/ | ||
@@ -249,7 +199,5 @@ | ||
emojiModifier = parser.constructor.modifier(mergeEmoji); | ||
affixEmojiModifier = parser.constructor.modifier(mergeAffixEmoji); | ||
} | ||
parser.useFirst('tokenizeSentence', emojiModifier); | ||
parser.useFirst('tokenizeParagraph', affixEmojiModifier); | ||
} | ||
@@ -256,0 +204,0 @@ |
{ | ||
"name": "nlcst-emoji-modifier", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Emoji in NLCST", | ||
@@ -20,3 +20,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^0.9.0", | ||
"eslint": "^0.10.0", | ||
"istanbul": "^0.3.0", | ||
@@ -26,3 +26,3 @@ "jscs": "^1.0.0", | ||
"mocha": "^2.0.0", | ||
"parse-english": "^0.4.0-rc.2" | ||
"parse-english": "^0.4.0" | ||
}, | ||
@@ -35,11 +35,11 @@ "scripts": { | ||
"lint-api": "node_modules/.bin/eslint index.js --rule 'consistent-return: false'", | ||
"lint-script": "node_modules/.bin/eslint build-emoji.js", | ||
"lint-script": "node_modules/.bin/eslint build-data.js", | ||
"lint-test": "node_modules/.bin/eslint test.js --env mocha", | ||
"lint-benchmark": "node_modules/.bin/eslint benchmark.js --global suite,set,bench", | ||
"lint-style": "node_modules/.bin/jscs index.js test.js benchmark.js --reporter=inline", | ||
"lint-style": "node_modules/.bin/jscs index.js test.js benchmark.js build-data.js --reporter=inline", | ||
"make": "npm run lint && npm run coverage", | ||
"benchmark": "node_modules/.bin/matcha benchmark.js", | ||
"build": "node build-emoji.js", | ||
"build": "node build-data.js", | ||
"prepublish": "npm run build" | ||
} | ||
} |
@@ -36,3 +36,3 @@ # nlcst-emoji-modifier [![Build Status](https://img.shields.io/travis/wooorm/nlcst-emoji-modifier.svg?style=flat)](https://travis-ci.org/wooorm/nlcst-emoji-modifier) [![Coverage Status](https://img.shields.io/coveralls/wooorm/nlcst-emoji-modifier.svg?style=flat)](https://coveralls.io/r/wooorm/nlcst-emoji-modifier?branch=master) | ||
english.parse('Who doesn’t like Gemoji? :+1: You? 💩').children[0].children; | ||
english.parse('Who doesn’t like Gemoji :+1:? You? 💩').children[0].children; | ||
``` | ||
@@ -104,6 +104,2 @@ | ||
{ | ||
"type": "PunctuationNode", | ||
"value": "?" | ||
}, | ||
{ | ||
"type": "WhiteSpaceNode", | ||
@@ -115,2 +111,6 @@ "value": " " | ||
"value": ":+1:" | ||
}, | ||
{ | ||
"type": "PunctuationNode", | ||
"value": "?" | ||
} | ||
@@ -154,12 +154,12 @@ ] | ||
On a MacBook Air, **parse-english** performs about 27% slower on content filled with (g)emoji, and a 18% slower on content without (g)emoji, when using this modifier. | ||
On a MacBook Air, **parse-english** performs about 27% slower on content filled with (g)emoji, and a 17% slower on content without (g)emoji, when using this modifier. | ||
``` | ||
parse w/ modifier | ||
1,303 op/s » A paragraph (5 sentences, 100 words, 5 emoji, 5 gemoji) | ||
1,653 op/s » A paragraph (5 sentences, 100 words, no emoji, no gemoji) | ||
1,299 op/s » A paragraph (5 sentences, 100 words, 5 emoji, 5 gemoji) | ||
1,647 op/s » A paragraph (5 sentences, 100 words, no emoji, no gemoji) | ||
parse w/o modifier | ||
1,784 op/s » A paragraph (5 sentences, 100 words, 5 emoji, 5 gemoji) | ||
2,038 op/s » A paragraph (5 sentences, 100 words, no emoji, no gemoji) | ||
1,775 op/s » A paragraph (5 sentences, 100 words, 5 emoji, 5 gemoji) | ||
1,974 op/s » A paragraph (5 sentences, 100 words, no emoji, no gemoji) | ||
``` | ||
@@ -169,3 +169,5 @@ | ||
- [nlcst](https://github.com/wooorm/parse-nlcst) | ||
- [nlcst](https://github.com/wooorm/nlcst) | ||
- [nlcst-emoticon-modifier](https://github.com/wooorm/nlcst-emoticon-modifier) | ||
- [nlcst-affix-emoticon-modifier](https://github.com/wooorm/nlcst-affix-emoticon-modifier) | ||
- [parse-latin](https://github.com/wooorm/parse-latin) | ||
@@ -179,2 +181,2 @@ - [parse-dutch](https://github.com/wooorm/parse-dutch) | ||
MIT © Titus Wormer | ||
MIT © [Titus Wormer](http://wooorm.com) |
177
36395
1876