nlcst-emoji-modifier
Advanced tools
Comparing version 0.2.0 to 1.0.0
@@ -1721,2 +1721,2 @@ { | ||
] | ||
} | ||
} |
131
index.js
@@ -1,29 +0,27 @@ | ||
'use strict'; | ||
/** | ||
* Dependencies. | ||
* @author Titus Wormer | ||
* @copyright 2014-2015 Titus Wormer | ||
* @license MIT | ||
* @module nlcst:emoji-modifier | ||
* @fileoverview Emoji in NLCST. | ||
*/ | ||
var emoji, | ||
nlcstToString; | ||
'use strict'; | ||
emoji = require('./data/emoji.json'); | ||
nlcstToString = require('nlcst-to-string'); | ||
/* eslint-env commonjs */ | ||
/** | ||
* Cached methods. | ||
/* | ||
* Dependencies. | ||
*/ | ||
var has; | ||
var toString = require('nlcst-to-string'); | ||
var modifier = require('unist-util-modify-children'); | ||
var emoji = require('./data/emoji.json'); | ||
has = Object.prototype.hasOwnProperty; | ||
/** | ||
/* | ||
* Constants: node types. | ||
*/ | ||
var EMOTICON_NODE; | ||
var EMOTICON_NODE = 'EmoticonNode'; | ||
EMOTICON_NODE = 'EmoticonNode'; | ||
/** | ||
@@ -42,6 +40,4 @@ * Constants: magic numbers. | ||
var MAX_GEMOJI_PART_COUNT; | ||
var MAX_GEMOJI_PART_COUNT = 12; | ||
MAX_GEMOJI_PART_COUNT = 12; | ||
/** | ||
@@ -51,17 +47,12 @@ * Constants for emoji. | ||
var index, | ||
names, | ||
shortcodes, | ||
unicodes, | ||
unicodeKeys; | ||
var names = emoji.names; | ||
var unicodeKeys = emoji.unicode; | ||
var shortcodes = {}; | ||
var unicodes = {}; | ||
var index; | ||
names = emoji.names; | ||
unicodeKeys = emoji.unicode; | ||
/** | ||
/* | ||
* Quick access to short-codes. | ||
*/ | ||
unicodes = {}; | ||
index = -1; | ||
@@ -73,4 +64,2 @@ | ||
shortcodes = {}; | ||
index = -1; | ||
@@ -86,22 +75,19 @@ | ||
* | ||
* @param {CSTNode} child | ||
* @param {number} index | ||
* @param {CSTNode} parent | ||
* @return {undefined|number} - Either void, or the | ||
* next index to iterate over. | ||
* @param {CSTNode} child - Node to check. | ||
* @param {number} index - Position of `child` in `parent`. | ||
* @param {CSTNode} parent - Parent of `node`. | ||
* @return {number?} - Either void, or the next index to | ||
* iterate over. | ||
*/ | ||
function mergeEmoji(child, index, parent) { | ||
var siblings, | ||
siblingIndex, | ||
node, | ||
nodes, | ||
value; | ||
var siblings = parent.children; | ||
var siblingIndex; | ||
var node; | ||
var nodes; | ||
var value; | ||
siblings = parent.children; | ||
if (child.type === 'WordNode') { | ||
value = nlcstToString(child); | ||
value = toString(child); | ||
/** | ||
/* | ||
* Sometimes a unicode emoji is marked as a | ||
@@ -111,3 +97,3 @@ * word. Mark it as an `EmoticonNode`. | ||
if (has.call(unicodes, value)) { | ||
if (unicodes[value] === true) { | ||
siblings[index] = { | ||
@@ -118,3 +104,3 @@ 'type': EMOTICON_NODE, | ||
} else { | ||
/** | ||
/* | ||
* Sometimes a unicode emoji is split in two. | ||
@@ -127,8 +113,5 @@ * Remove the last and add its value to | ||
if ( | ||
node && | ||
has.call(unicodes, nlcstToString(node) + value) | ||
) { | ||
if (node && unicodes[toString(node) + value] === true) { | ||
node.type = EMOTICON_NODE; | ||
node.value = nlcstToString(node) + value; | ||
node.value = toString(node) + value; | ||
@@ -140,5 +123,5 @@ siblings.splice(index, 1); | ||
} | ||
} else if (has.call(unicodes, nlcstToString(child))) { | ||
} else if (unicodes[toString(child)] === true) { | ||
child.type = EMOTICON_NODE; | ||
} else if (nlcstToString(child) === ':') { | ||
} else if (toString(child) === ':') { | ||
nodes = []; | ||
@@ -160,3 +143,3 @@ siblingIndex = index; | ||
if (nlcstToString(node) === ':') { | ||
if (toString(node) === ':') { | ||
break; | ||
@@ -172,7 +155,5 @@ } | ||
value = nlcstToString({ | ||
'children': nodes | ||
}); | ||
value = toString(nodes); | ||
if (!has.call(shortcodes, value)) { | ||
if (shortcodes[value] !== true) { | ||
return; | ||
@@ -190,28 +171,6 @@ } | ||
var emojiModifier; | ||
function attach(parser) { | ||
if (!parser || !parser.parse) { | ||
throw new Error( | ||
'`parser` is not a valid parser for ' + | ||
'`attach(parser)`. Make sure something ' + | ||
'like `parse-latin` is passed.' | ||
); | ||
} | ||
/** | ||
* Make sure to not re-attach the modifier. | ||
*/ | ||
if (!emojiModifier) { | ||
emojiModifier = parser.constructor.modifier(mergeEmoji); | ||
} | ||
parser.useFirst('tokenizeSentence', emojiModifier); | ||
} | ||
/** | ||
* Expose `attach`. | ||
/* | ||
* Expose. | ||
*/ | ||
module.exports = attach; | ||
module.exports = modifier(mergeEmoji); |
{ | ||
"name": "nlcst-emoji-modifier", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Emoji in NLCST", | ||
@@ -11,33 +11,45 @@ "license": "MIT", | ||
"dependencies": { | ||
"gemoji": "^0.2.0", | ||
"nlcst-to-string": "^0.1.0" | ||
"nlcst-to-string": "^1.0.0", | ||
"unist-util-modify-children": "^1.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wooorm/nlcst-emoji-modifier.git" | ||
}, | ||
"repository": "wooorm/nlcst-emoji-modifier", | ||
"author": "Titus Wormer <tituswormer@gmail.com>", | ||
"files": [ | ||
"data/emoji.json", | ||
"index.js" | ||
], | ||
"devDependencies": { | ||
"eslint": "^0.10.0", | ||
"browserify": "^11.0.0", | ||
"eslint": "^1.0.0", | ||
"esmangle": "^1.0.0", | ||
"gemoji": "^1.0.0", | ||
"istanbul": "^0.3.0", | ||
"jscs": "^1.0.0", | ||
"matcha": "^0.6.0", | ||
"jscs": "^2.0.0", | ||
"jscs-jsdoc": "^1.0.0", | ||
"mdast": "^1.0.0", | ||
"mdast-comment-config": "^1.0.0", | ||
"mdast-github": "^1.0.0", | ||
"mdast-lint": "^1.0.0", | ||
"mdast-slug": "^1.0.0", | ||
"mdast-validate-links": "^1.0.0", | ||
"mocha": "^2.0.0", | ||
"parse-english": "^0.4.0" | ||
"parse-english": "^1.0.0", | ||
"retext": "^1.0.0-rc.3", | ||
"unist-util-visit": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/_mocha --reporter spec --check-leaks -u exports test.js", | ||
"test-travis": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --check-leaks -u exports test.js", | ||
"coverage": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -- test.js", | ||
"lint": "npm run lint-api && npm run lint-test && npm run lint-benchmark && npm run lint-script && npm run lint-style", | ||
"lint-api": "node_modules/.bin/eslint index.js --rule 'consistent-return: false'", | ||
"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 build-data.js --reporter=inline", | ||
"make": "npm run lint && npm run coverage", | ||
"benchmark": "node_modules/.bin/matcha benchmark.js", | ||
"build": "node build-data.js", | ||
"prepublish": "npm run build" | ||
"test-api": "mocha --check-leaks test/index.js", | ||
"test-coverage": "istanbul cover _mocha -- test/index.js", | ||
"test-travis": "npm run test-coverage", | ||
"test": "npm run test-api", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"make": "npm run lint && npm run test-coverage", | ||
"bundle": "browserify index.js --no-builtins -s nlcstEmojiModifier > nlcst-emoji-modifier.js", | ||
"postbundle": "esmangle nlcst-emoji-modifier.js > nlcst-emoji-modifier.min.js", | ||
"build-data": "node script/build-data.js", | ||
"build-md": "mdast . --quiet", | ||
"build": "npm run build-data && npm run bundle && npm run build-md" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6
1
36094
17
1850
175
1
+ Addedarray-iterate@1.1.4(transitive)
+ Addednlcst-to-string@1.1.0(transitive)
+ Addedunist-util-modify-children@1.1.6(transitive)
- Removedgemoji@^0.2.0
- Removedgemoji@0.2.2(transitive)
- Removednlcst-to-string@0.1.5(transitive)
Updatednlcst-to-string@^1.0.0