From 052a350ca1f7c0d4ad4af0b1887991000fd626dd Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 23 Feb 2020 01:43:27 +0700 Subject: [PATCH] Require Node.js 10 --- .gitattributes | 3 +-- .travis.yml | 3 ++- cli.js | 22 +++++----------- index.js | 9 +++---- license | 2 +- package.json | 33 +++++++++++++----------- readme.md | 13 ++-------- test.js | 6 ++--- ui.js | 70 ++++++++++++++++++++++++-------------------------- 9 files changed, 72 insertions(+), 89 deletions(-) diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.travis.yml b/.travis.yml index b3be97a..94ab01f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: node_js node_js: - - '8' + - '12' + - '10' diff --git a/cli.js b/cli.js index e1aeac8..62c52e2 100755 --- a/cli.js +++ b/cli.js @@ -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) { diff --git a/index.js b/index.js index c8319d0..054eb86 100644 --- a/index.js +++ b/index.js @@ -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); }; diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (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: diff --git a/package.json b/package.json index d4ea515..1220238 100644 --- a/package.json +++ b/package.json @@ -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": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, "bin": "cli.js", "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "xo && ava" @@ -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" } } } diff --git a/readme.md b/readme.md index 9ce88fc..5b6298c 100644 --- a/readme.md +++ b/readme.md @@ -5,12 +5,11 @@ Uses the API from this great article on [Emoji & Deep Learning](http://getdango.com/emoji-and-deep-learning.html).
-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 @@ -18,7 +17,6 @@ $ 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 ``` @@ -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) diff --git a/test.js b/test.js index 11ca944..7abb0e0 100644 --- a/test.js +++ b/test.js @@ -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, '🦄'); }); diff --git a/ui.js b/ui.js index 37d355e..4a8fc79 100644 --- a/ui.js +++ b/ui.js @@ -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); @@ -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 = () => ( @@ -63,14 +66,6 @@ const Emoji = ({emoji, skinNumber}) => ( ); -const SelectedIndicator = ({selectedIndex}) => ( - - - ↑ - - -); - const CopiedMessage = ({emoji}) => ( {`${emoji} has been copied to the clipboard`} @@ -78,12 +73,16 @@ const CopiedMessage = ({emoji}) => ( ); const Search = ({query, emojis, skinNumber, selectedIndex, onChangeQuery}) => { - const list = emojis.map(emoji => ( - ( + + bgCyan={index === selectedIndex} + > + + )); return ( @@ -93,12 +92,9 @@ const Search = ({query, emojis, skinNumber, selectedIndex, onChangeQuery}) => { placeholder="Relevant emojis will appear when you start writing" onChange={onChangeQuery} /> - - + {list} - - {emojis.length > 0 && } ); }; @@ -106,7 +102,7 @@ const Search = ({query, emojis, skinNumber, selectedIndex, onChangeQuery}) => { class Emoj extends React.PureComponent { constructor(props) { super(props); - autoBind(this); + autoBindReact(this); this.state = { stage: STAGE_CHECKING, @@ -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) { @@ -263,12 +259,14 @@ class Emoj extends React.PureComponent { } } -const EmojWithStdin = props => ( - - {({stdin, setRawMode}) => ( - +module.exports = props => ( + + {({exit}) => ( + + {({stdin, setRawMode}) => ( + + )} + )} - + ); - -module.exports = EmojWithStdin;