retext-emoji
Advanced tools
Comparing version 5.0.0 to 5.0.1
158
index.js
@@ -1,126 +0,128 @@ | ||
'use strict'; | ||
'use strict' | ||
var affixEmoticonModifier = require('nlcst-affix-emoticon-modifier'); | ||
var emoticonModifier = require('nlcst-emoticon-modifier'); | ||
var emojiModifier = require('nlcst-emoji-modifier'); | ||
var emoticons = require('emoticon'); | ||
var toString = require('nlcst-to-string'); | ||
var gemoji = require('gemoji'); | ||
var visit = require('unist-util-visit'); | ||
var affixEmoticonModifier = require('nlcst-affix-emoticon-modifier') | ||
var emoticonModifier = require('nlcst-emoticon-modifier') | ||
var emojiModifier = require('nlcst-emoji-modifier') | ||
var emoticons = require('emoticon') | ||
var toString = require('nlcst-to-string') | ||
var gemoji = require('gemoji') | ||
var visit = require('unist-util-visit') | ||
module.exports = emoji; | ||
module.exports = emoji | ||
var EMOTICON_NODE = 'EmoticonNode'; | ||
var type = 'EmoticonNode' | ||
/* Map of visitors. */ | ||
// Map of visitors. | ||
var fns = { | ||
encode: toEmoji, | ||
decode: toGemoji | ||
}; | ||
} | ||
var unicodes = gemoji.unicode; | ||
var names = gemoji.name; | ||
var unicodes = gemoji.unicode | ||
var names = gemoji.name | ||
var shortcodes = {}; | ||
var shortcodes = {} | ||
(function () { | ||
var key; | ||
var shortcode; | ||
var result = {}; | ||
var length = emoticons.length; | ||
var index = -1; | ||
var count; | ||
var offset; | ||
var subset; | ||
var name; | ||
init() | ||
for (key in names) { | ||
shortcode = ':' + key + ':'; | ||
shortcodes[shortcode] = names[key]; | ||
shortcodes[shortcode].shortcode = shortcode; | ||
} | ||
while (++index < length) { | ||
name = emoticons[index].name; | ||
subset = emoticons[index].emoticons; | ||
count = subset.length; | ||
offset = -1; | ||
while (++offset < count) { | ||
result[subset[offset]] = names[name]; | ||
} | ||
} | ||
emoticons = result; | ||
})(); | ||
/* Attacher. */ | ||
function emoji(options) { | ||
var Parser = this.Parser; | ||
var proto = Parser.prototype; | ||
var convert = (options || {}).convert; | ||
var fn; | ||
var Parser = this.Parser | ||
var proto = Parser.prototype | ||
var convert = (options || {}).convert | ||
var fn | ||
proto.useFirst('tokenizeSentence', emoticonModifier); | ||
proto.useFirst('tokenizeSentence', emojiModifier); | ||
proto.useFirst('tokenizeParagraph', affixEmoticonModifier); | ||
proto.useFirst('tokenizeSentence', emoticonModifier) | ||
proto.useFirst('tokenizeSentence', emojiModifier) | ||
proto.useFirst('tokenizeParagraph', affixEmoticonModifier) | ||
if (convert !== null && convert !== undefined) { | ||
fn = fns[convert]; | ||
fn = fns[convert] | ||
if (!fn) { | ||
throw new TypeError( | ||
'Illegal invocation: `' + convert + | ||
'` is not a valid value for ' + | ||
'`options.convert` in `retext#use(emoji, options)`' | ||
); | ||
'Illegal invocation: `' + | ||
convert + | ||
'` is not a valid value for ' + | ||
'`options.convert` in `retext#use(emoji, options)`' | ||
) | ||
} | ||
} | ||
return transformer; | ||
return transformer | ||
function transformer(node) { | ||
visit(node, EMOTICON_NODE, visitor); | ||
visit(node, type, visitor) | ||
} | ||
function visitor(node) { | ||
var data = node.data; | ||
var value = toString(node); | ||
var info; | ||
var data = node.data | ||
var value = toString(node) | ||
var info | ||
if (fn) { | ||
fn(node); | ||
fn(node) | ||
} | ||
info = unicodes[value] || shortcodes[value] || emoticons[value]; | ||
info = unicodes[value] || shortcodes[value] || emoticons[value] | ||
if (!data) { | ||
data = {}; | ||
node.data = data; | ||
data = {} | ||
node.data = data | ||
} | ||
data.names = info.names.concat(); | ||
data.description = info.description; | ||
data.tags = info.tags.concat(); | ||
data.names = info.names.concat() | ||
data.description = info.description | ||
data.tags = info.tags.concat() | ||
} | ||
} | ||
/* Replace a unicode emoji with a short-code. */ | ||
// Replace a unicode emoji with a short-code. | ||
function toGemoji(node) { | ||
var value = toString(node); | ||
var info = (unicodes[value] || emoticons[value] || {}).shortcode; | ||
var value = toString(node) | ||
var info = (unicodes[value] || emoticons[value] || {}).shortcode | ||
if (info) { | ||
node.value = info; | ||
node.value = info | ||
} | ||
} | ||
/* Replace a short-code with a unicode emoji. */ | ||
// Replace a short-code with a unicode emoji. | ||
function toEmoji(node) { | ||
var value = toString(node); | ||
var info = (shortcodes[value] || emoticons[value] || {}).emoji; | ||
var value = toString(node) | ||
var info = (shortcodes[value] || emoticons[value] || {}).emoji | ||
if (info) { | ||
node.value = info; | ||
node.value = info | ||
} | ||
} | ||
function init() { | ||
var key | ||
var shortcode | ||
var result = {} | ||
var length = emoticons.length | ||
var index = -1 | ||
var count | ||
var offset | ||
var subset | ||
var name | ||
for (key in names) { | ||
shortcode = ':' + key + ':' | ||
shortcodes[shortcode] = names[key] | ||
shortcodes[shortcode].shortcode = shortcode | ||
} | ||
while (++index < length) { | ||
name = emoticons[index].name | ||
subset = emoticons[index].emoticons | ||
count = subset.length | ||
offset = -1 | ||
while (++offset < count) { | ||
result[subset[offset]] = names[name] | ||
} | ||
} | ||
emoticons = result | ||
} |
{ | ||
"name": "retext-emoji", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Emoji, gemoji, and emoticons with retext", | ||
@@ -12,7 +12,7 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/retext-emoji", | ||
"bugs": "https://github.com/wooorm/retext-emoji/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"repository": "retextjs/retext-emoji", | ||
"bugs": "https://github.com/retextjs/retext-emoji/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
], | ||
@@ -32,20 +32,20 @@ "files": [ | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^4.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"browserify": "^16.0.0", | ||
"nyc": "^13.0.0", | ||
"prettier": "^1.14.3", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"retext": "^5.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.18.0" | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.23.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"build-bundle": "browserify index.js --bare -s retextEmoji > retext-emoji.js", | ||
"build-mangle": "esmangle retext-emoji.js > retext-emoji.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s retextEmoji > retext-emoji.js", | ||
"build-mangle": "browserify . -s retextEmoji -p tinyify > retext-emoji.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
@@ -58,4 +58,12 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
@@ -70,4 +78,6 @@ "rules": { | ||
"remarkConfig": { | ||
"plugins": ["preset-wooorm"] | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# retext-emoji [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
# retext-emoji [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Chat][chat-badge]][chat] | ||
@@ -16,10 +16,10 @@ Emoji, gemoji, and emoticons in [**retext**][retext]. | ||
```javascript | ||
var retext = require('retext'); | ||
var emoji = require('retext-emoji'); | ||
var retext = require('retext') | ||
var emoji = require('retext-emoji') | ||
var file = retext() | ||
.use(emoji, {convert: 'encode'}) | ||
.processSync('I’m going to bed. :zzz:'); | ||
.processSync('I’m going to bed. :zzz:') | ||
console.log(String(file)); | ||
console.log(String(file)) | ||
``` | ||
@@ -55,3 +55,4 @@ | ||
`retext-emoji` adds a new node to [NLCST][]: `Emoticon` ([Symbol][]). | ||
`retext-emoji` adds a new node to [nlcst][]: | ||
**Emoticon** ([**Literal**][literal]). | ||
@@ -63,10 +64,10 @@ Whether emoji (`❤️`), emoticon (`<3`), or gemoji (`:heart:`), all are | ||
interface Emoticon < Symbol { | ||
type: "EmoticonNode"; | ||
data: EmoticonData; | ||
type: "EmoticonNode" | ||
data: EmoticonData | ||
} | ||
interface EmoticonData { | ||
names: [string]; | ||
description: string | null; | ||
tags: [string]; | ||
names: [string][] | ||
description: string? | ||
tags: [string] | ||
} | ||
@@ -80,2 +81,10 @@ ``` | ||
## Contribute | ||
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 | ||
@@ -87,21 +96,29 @@ | ||
[travis-badge]: https://img.shields.io/travis/wooorm/retext-emoji.svg | ||
[build-badge]: https://img.shields.io/travis/retextjs/retext-emoji.svg | ||
[travis]: https://travis-ci.org/wooorm/retext-emoji | ||
[build]: https://travis-ci.org/retextjs/retext-emoji | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/retext-emoji.svg | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/retextjs/retext-emoji.svg | ||
[codecov]: https://codecov.io/github/wooorm/retext-emoji | ||
[coverage]: https://codecov.io/github/retextjs/retext-emoji | ||
[downloads-badge]: https://img.shields.io/npm/dm/retext-emoji.svg | ||
[downloads]: https://www.npmjs.com/package/retext-emoji | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat]: https://spectrum.chat/unified/retext | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[license]: LICENSE | ||
[license]: license | ||
[author]: http://wooorm.com | ||
[author]: https://wooorm.com | ||
[retext]: https://github.com/wooorm/retext | ||
[retext]: https://github.com/retextjs/retext | ||
[nlcst]: https://github.com/wooorm/nlcst | ||
[nlcst]: https://github.com/syntax-tree/nlcst | ||
[symbol]: https://github.com/wooorm/nlcst#symbol | ||
[literal]: https://github.com/syntax-tree/nlcst#literal | ||
@@ -111,1 +128,5 @@ [gemoji]: https://github.com/wooorm/gemoji/#supported-gemoji | ||
[emoticon]: https://github.com/wooorm/emoticon/#supported-emoticon | ||
[contributing]: https://github.com/retextjs/retext/blob/master/contributing.md | ||
[coc]: https://github.com/retextjs/retext/blob/master/code-of-conduct.md |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
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
8569
101
127
9