🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

emojideas

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emojideas - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+119
test.js
let assert = require('assert');
let emojilib = require('emojilib');
let Emojideas = require('./index.js');
let emojiName = 'aerial tramway';
let emoji = emojilib.lib[emojiName.replace(' ', '_')];
// => { keywords: [ 'transportation', 'vehicle', 'ski' ],
// char: '🚡',
// fitzpatrick_scale: false,
// category: 'travel_and_places' }
describe('Emojideas', function () {
describe('#suggest', function () {
describe('by default', function () {
let emojideas = new Emojideas();
it('returns an array', function () {
let result = emojideas.suggest();
assert(result instanceof Array);
});
it('searches by name (converted from snake case)', function () {
let result = emojideas.suggest(emojiName);
assert(result.includes(emoji.char));
});
it('searches by keywords', function () {
emoji.keywords.forEach(function (keyword) {
let result = emojideas.suggest(keyword);
assert(result.includes(emoji.char));
});
});
it('is not case sensitive', function () {
let lowerCase = emojideas.suggest(emojiName.toLowerCase());
let upperCase = emojideas.suggest(emojiName.toUpperCase());
assert.deepStrictEqual(lowerCase, upperCase);
});
it('searches by standard Lunr syntax', function () {
let result = emojideas.suggest(`+${ emojiName }~2 -asdf`);
assert(result.includes(emoji.char));
});
});
describe('when excludeCategories Array is set', function () {
let emojideas = new Emojideas({ excludeCategories: [emoji.category] });
it('excludes categories', function () {
let result = emojideas.suggest(emojiName);
assert(!result.includes(emoji.char));
});
});
describe('when fuzzy is set', function () {
describe('to 1', function () {
let emojideas = new Emojideas({ fuzzy: 1 });
it('allows one-character spelling errors', function () {
let result = emojideas.suggest(emojiName.slice(1));
assert(result.includes(emoji.char));
});
});
describe('to 2', function () {
let emojideas = new Emojideas({ fuzzy: 2 });
it('allows two-character spelling errors', function () {
let result = emojideas.suggest(emojiName.slice(2));
assert(result.includes(emoji.char));
});
});
});
describe('when nameBoost is set', function () {
describe('to 0', function () {
let emojideas = new Emojideas({ nameBoost: 0 });
it('excludes name from search', function () {
let result = emojideas.suggest(emojiName);
assert(!result.includes(emoji.char));
});
});
describe('to a high number', function () {
let emojideas = new Emojideas({ nameBoost: 10 });
it('prioritizes name in search', function () {
let result = emojideas.suggest(emojiName);
assert.equal(result[0], emoji.char);
});
});
});
describe('when formatOutput Function is set', function () {
describe('to return fixed value', function () {
let emojideas = new Emojideas({ formatOutput: el => '🚡' });
it('outputs fixed value', function () {
let result = emojideas.suggest('*');
assert(result.length);
assert(result.every(el => el === '🚡'));
})
});
describe('to interact with Lunr properties', function () {
let emojideas = new Emojideas({ formatOutput: el => [el.ref, el.score] });
it('outputs Array of ref and score', function () {
let result = emojideas.suggest(emojiName);
assert(result[0] instanceof Array);
assert.equal(result[0][0], emoji.char);
assert(typeof result[0][1] === 'number');
});
});
});
});
});
+5
-3
{
"name": "emojideas",
"version": "1.0.0",
"version": "1.0.1",
"description": "Suggest Emoji based on name or keyword.",

@@ -10,5 +10,7 @@ "main": "index.js",

},
"devDependencies": {},
"devDependencies": {
"mocha": "^5.2.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},

@@ -15,0 +17,0 @@ "repository": {

# Emojideas
Text-to-emoji suggestion library with a [Lunr](https://github.com/olivernn/lunr.js) and [emojilib](https://github.com/muan/emojilib) backend.
Text-to-emoji suggestion library with a [Lunr](https://github.com/olivernn/lunr.js) and [emojilib](https://github.com/muan/emojilib) backend. Suggestions are based on emoji name and keywords.

@@ -39,6 +39,6 @@ ## Usage

require('emojilib').lib.aerial_tramway;
// => { keywords: [ 'transportation', 'vehicle', 'ski' ],
// char: '🚡',
// fitzpatrick_scale: false,
// category: 'travel_and_places' }
// => { keywords: [ 'transportation', 'vehicle', 'ski' ],
// char: '🚡',
// fitzpatrick_scale: false,
// category: 'travel_and_places' }

@@ -58,2 +58,3 @@ let e = new Emojideas({ excludeCategories: ['travel_and_places'] });

let h = new Emojideas({ formatOutput: el => [el.ref, el.score] });
h.suggest('aerial tramway');
// => [ [ '🚡', 25.417660356531634 ] ]

@@ -65,1 +66,23 @@ ```

All queries are passed directly to the Lunr backend, and can therefore use the [Lunr syntax](https://lunrjs.com/guides/searching.html), except when the `fuzzy` option has been set.
```javascript
require('emojilib').lib.tram;
// => { keywords: [ 'transportation', 'vehicle' ],
// char: '🚊',
// fitzpatrick_scale: false,
// category: 'travel_and_places' }
let e = new Emojideas();
e.suggest('tram');
// => [ '🚊' ]
e.suggest('tram*');
// => [ '🚊', '🚡' ]
e.suggest('aerial tram*');
// => [ '🚡', '🚊' ]
e.suggest('tram* -tram');
// => [ '🚡' ]
```