Socket
Socket
Sign inDemoInstall

remark-emoji

Package Overview
Dependencies
5
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

30

index_test.js

@@ -21,2 +21,15 @@ const assert = require('assert');

function processPad(contents) {
const compiler = remark().use(github).use(headings).use(slug).use(emoji, {padSpaceAfter: true});
return new Promise((resolve, reject) => {
compiler.process(contents, (err, result) => {
if (err) {
return reject(err);
}
resolve(result.contents);
});
});
}
describe('remark-emoji', () => {

@@ -59,2 +72,19 @@ it('replaces emojis in text', () => {

});
it('can handle an emoji including 2 underscores', () => {
return process(':heavy_check_mark:').then(r => assert.equal(r, '✔️\n'));
});
it('adds an white space after emoji when padSpaceAfter is set to true', () => {
const cases = {
':dog: is dog': '🐶 is dog\n',
'dog is :dog:': 'dog is 🐶 \n',
':dog: is not :cat:': '🐶 is not 🐱 \n',
':triumph:': '😤 \n'
};
return Promise.all(
Object.keys(cases).map(c => processPad(c).then(r => assert.equal(r, cases[c])))
);
});
});

16

index.js

@@ -6,8 +6,20 @@ const visit = require('unist-util-visit');

function plugin() {
function plugin(_, settings) {
const pad = !!(settings || {}).padSpaceAfter;
function getEmoji(match) {
const got = emoji.get(match);
if (!pad || got === match) {
return got;
}
return got + ' ';
}
function transformer(tree) {
visit(tree, 'text', node => {
node.value = node.value.replace(RE_EMOJI, m => emoji.get(m));
node.value = node.value.replace(RE_EMOJI, getEmoji);
});
}
return transformer;

@@ -14,0 +26,0 @@ }

2

package.json
{
"name": "remark-emoji",
"version": "1.0.0",
"version": "1.1.0",
"description": "Emoji transformer plugin for Remark",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,13 +9,25 @@ remark-emoji

```
remark().use(emoji [, options]);
```
```javascript
const remark = require('remark');
const emoji = require('emoji');
const emoji = require('remark-emoji');
const doc = 'Emojis in this text will be relpaces: :dog: :+1:';
const doc = 'Emojis in this text will be replaced: :dog: :+1:';
console.log(remark().use(emoji).process(doc).contents);
// => Emojis in this text will be relpaces: 🐶 👍
// => Emojis in this text will be replaced: 🐶 👍
```
## Options
### `options.padSpaceAfter`
Setting to `true` means that an extra whitespace is added after emoji.
This is useful when browser handle emojis with half character length and following character is hidden.
Default value is `false`.
## License
Distributed under [the MIT License](LICENSE).
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc