Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 22, 2020
1 parent 165c7a4 commit 052a350
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 89 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: node_js
node_js:
- '8'
- '12'
- '10'
22 changes: 7 additions & 15 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,18 @@ if (cli.flags.skinTone !== undefined) {

const skinNumber = config.get('skinNumber');

const main = () => {
let unmount; // eslint-disable-line prefer-const

const onError = () => {
unmount();
process.exit(1);
};

const onExit = () => {
unmount();
process.exit();
};
const main = async () => {
let app; // eslint-disable-line prefer-const

const onSelectEmoji = emoji => {
clipboardy.writeSync(emoji);
onExit();
app.unmount();
};

// Uses `React.createElement` instead of JSX to avoid transpiling this file
unmount = render(React.createElement(ui, {skinNumber, onSelectEmoji, onError, onExit}));
// Uses `React.createElement` instead of JSX to avoid transpiling this file.
app = render(React.createElement(ui, {skinNumber, onSelectEmoji}));

await app.waitUntilExit();
};

if (cli.input.length > 0) {
Expand Down
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
const got = require('got');

module.exports = async input => {
const response = await got('emoji.getdango.com/api/emoji', {
json: true,
query: {
const {results} = await got('http://emoji.getdango.com/api/emoji', {
searchParams: {
q: input
}
});
}).json();

return response.body.results.map(x => x.text);
return results.map(result => result.text);
};
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
33 changes: 18 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"description": "Find relevant emoji from text on the command-line",
"license": "MIT",
"repository": "sindresorhus/emoj",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -36,31 +37,33 @@
"networks"
],
"dependencies": {
"auto-bind": "^1.1.0",
"clipboardy": "^1.1.4",
"conf": "^1.0.0",
"got": "^7.1.0",
"import-jsx": "^1.2.0",
"ink": "^2.0.0-2",
"ink-text-input": "^3.0.0-0",
"auto-bind": "^4.0.0",
"clipboardy": "^2.2.0",
"conf": "^6.2.1",
"got": "^10.6.0",
"import-jsx": "^3.1.0",
"ink": "^2.7.1",
"ink-text-input": "^3.2.2",
"lodash.debounce": "^4.0.6",
"mem": "^1.1.0",
"meow": "^3.7.0",
"mem": "^6.0.1",
"meow": "^6.0.1",
"react": "^16.5.2",
"skin-tone": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"eslint-config-xo-react": "^0.13.0",
"ava": "^1.4.0",
"eslint-config-xo-react": "^0.23.0",
"eslint-plugin-react": "^7.1.0",
"xo": "^0.18.2"
"eslint-plugin-react-hooks": "^2.4.0",
"xo": "^0.26.1"
},
"xo": {
"extends": [
"xo-react"
],
"rules": {
"react/prop-types": 0
"react/prop-types": "off",
"react/state-in-constructor": "off"
}
}
}
13 changes: 2 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
<img src="screenshot.gif" width="660">

Uses the API from this great article on [Emoji & Deep Learning](http://getdango.com/emoji-and-deep-learning.html).<br>
Check out the [Dango app](http://getdango.com) if you want something like this on your phone.

Check out the [Dango app](https://getdango.com) if you want something like this on your phone.

## Install

Ensure you have [Node.js](https://nodejs.org) version 8 or higher installed. Then run the following:
Ensure you have [Node.js](https://nodejs.org) version 10 or higher installed. Then run the following:

```
$ npm install --global emoj
```

Works best on macOS and Linux. Older Linux distributions don't support color emoji in the terminal, but newer ones (like Ubuntu 18.04 and Fedora 28) do. On Linux, I would recommend installing [Emoji One](https://github.com/eosrei/emojione-color-font#install-on-linux) for full emoji coverage. [Doesn't really work on Windows.](https://github.com/sindresorhus/emoj/issues/5)


## Usage

```
Expand All @@ -39,13 +37,6 @@ $ emoj --help
Use the up/down keys during live search to change the skin tone
```


## Related

- [alfred-emoj](https://github.com/sindresorhus/alfred-emoj) - Alfred plugin
- [inquirer-emoji](https://github.com/tannerntannern/inquirer-emoji) - Prompt plugin for `inquirer`


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import m from '.';
import emoj from '.';

test(async t => {
const [unicornEmoji] = await m('unicorn');
test('main', async t => {
const [unicornEmoji] = await emoj('unicorn');
t.is(unicornEmoji, '🦄');
});
70 changes: 34 additions & 36 deletions ui.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';
const dns = require('dns');
const React = require('react');
const {Box, Color, Text, StdinContext} = require('ink');
const {Box, Color, Text, AppContext, StdinContext} = require('ink');
const TextInput = require('ink-text-input').default;
const debounce = require('lodash.debounce');
const skinTone = require('skin-tone');
const autoBind = require('auto-bind');
const autoBindReact = require('auto-bind/react');
const mem = require('mem');
const emoj = require('.');

// Limit it to 7 results so not to overwhelm the user
// This also reduces the chance of showing unrelated emojis
const fetch = mem(str => emoj(str).then(arr => arr.slice(0, 7)));
const fetch = mem(async string => {
const array = await emoj(string);
return array.slice(0, 7);
});

const debouncer = debounce(cb => cb(), 200);

Expand All @@ -21,12 +24,12 @@ const STAGE_SEARCH = 2;
const STAGE_COPIED = 3;

// TODO: Move these to https://github.com/sindresorhus/ansi-escapes
const ARROW_UP = '\u001b[A';
const ARROW_DOWN = '\u001b[B';
const ARROW_LEFT = '\u001b[D';
const ARROW_RIGHT = '\u001b[C';
const ESC = '\u001b';
const CTRL_C = '\x03';
const ARROW_UP = '\u001B[A';
const ARROW_DOWN = '\u001B[B';
const ARROW_LEFT = '\u001B[D';
const ARROW_RIGHT = '\u001B[C';
const ESC = '\u001B';
const CTRL_C = '\u0003';
const RETURN = '\r';

const OfflineMessage = () => (
Expand Down Expand Up @@ -63,27 +66,23 @@ const Emoji = ({emoji, skinNumber}) => (
</Box>
);

const SelectedIndicator = ({selectedIndex}) => (
<Box marginLeft={selectedIndex * 4}>
<Color cyan>
</Color>
</Box>
);

const CopiedMessage = ({emoji}) => (
<Color green>
{`${emoji} has been copied to the clipboard`}
</Color>
);

const Search = ({query, emojis, skinNumber, selectedIndex, onChangeQuery}) => {
const list = emojis.map(emoji => (
<Emoji
const list = emojis.map((emoji, index) => (
<Color
key={emoji}
emoji={emoji}
skinNumber={skinNumber}
/>
bgCyan={index === selectedIndex}
>
<Emoji
emoji={emoji}
skinNumber={skinNumber}
/>
</Color>
));

return (
Expand All @@ -93,20 +92,17 @@ const Search = ({query, emojis, skinNumber, selectedIndex, onChangeQuery}) => {
placeholder="Relevant emojis will appear when you start writing"
onChange={onChangeQuery}
/>

<Box>
<Box paddingTop={1}>
{list}
</Box>

{emojis.length > 0 && <SelectedIndicator selectedIndex={selectedIndex}/>}
</Box>
);
};

class Emoj extends React.PureComponent {
constructor(props) {
super(props);
autoBind(this);
autoBindReact(this);

this.state = {
stage: STAGE_CHECKING,
Expand Down Expand Up @@ -146,8 +142,8 @@ class Emoj extends React.PureComponent {
}

componentDidMount() {
dns.lookup('emoji.getdango.com', err => {
const stage = err && err.code === 'ENOTFOUND' ? STAGE_OFFLINE : STAGE_SEARCH;
dns.lookup('emoji.getdango.com', error => {
const stage = error && error.code === 'ENOTFOUND' ? STAGE_OFFLINE : STAGE_SEARCH;

this.setState({stage}, () => {
if (stage === STAGE_OFFLINE) {
Expand Down Expand Up @@ -263,12 +259,14 @@ class Emoj extends React.PureComponent {
}
}

const EmojWithStdin = props => (
<StdinContext.Consumer>
{({stdin, setRawMode}) => (
<Emoj stdin={stdin} setRawMode={setRawMode} {...props}/>
module.exports = props => (
<AppContext.Consumer>
{({exit}) => (
<StdinContext.Consumer>
{({stdin, setRawMode}) => (
<Emoj stdin={stdin} setRawMode={setRawMode} onExit={exit} {...props}/>
)}
</StdinContext.Consumer>
)}
</StdinContext.Consumer>
</AppContext.Consumer>
);

module.exports = EmojWithStdin;

0 comments on commit 052a350

Please sign in to comment.