Skip to content

Commit

Permalink
Require Node.js 18 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 30, 2024
1 parent c2653de commit ba8a429
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 85 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 8
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
11 changes: 6 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const yesNoWords = require('.');
import meow from 'meow';
import yesNoWords from './index.js';

const cli = meow(`
Examples
Expand All @@ -16,7 +15,9 @@ const cli = meow(`
Options
--all Get all words instead of a random word
--type Type of word: yes|no|all [Default: all]
`);
`, {
importMeta: import.meta,
});

const type = cli.flags.type || 'all';
const type = cli.flags.type ?? 'all';
console.log(cli.flags.all ? yesNoWords[type].join('\n') : yesNoWords[`${type}Random`]());
23 changes: 10 additions & 13 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
import yes = require('./yes.json');
import no = require('./no.json');

declare const yesNoWords: {
/**
Yes like words.
@example
```
import yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';
yesNoWords.yes;
//=> ['Absolutely', 'Ack', …]
```
*/
readonly yes: Readonly<typeof yes>;
readonly yes: readonly string[];

/**
No like words.
@example
```
import yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';
yesNoWords.no;
//=> ['Absolutely not', 'Ahhh nah', …]
```
*/
readonly no: Readonly<typeof no>;
readonly no: readonly string[];

/**
Both yes and no like words.
@example
```
import yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';
yesNoWords.all;
//=> ['Absolutely', 'Absolutely not', 'Ack', …]
```
*/
readonly all: Readonly<typeof yes> & Readonly<typeof no>;
readonly all: readonly string[];

/**
Random yes like words.
@example
```
import yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';
yesNoWords.yesRandom();
//=> 'Yisss'
Expand All @@ -59,7 +56,7 @@ declare const yesNoWords: {
@example
```
import yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';
yesNoWords.noRandom();
//=> 'Forget it'
Expand All @@ -72,7 +69,7 @@ declare const yesNoWords: {
@example
```
import yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';
yesNoWords.allRandom();
//=> 'NEIN NEIN NEIN'
Expand All @@ -81,4 +78,4 @@ declare const yesNoWords: {
allRandom(): string;
};

export = yesNoWords;
export default yesNoWords;
29 changes: 16 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use strict';
const uniqueRandomArray = require('unique-random-array');
const yes = require('./yes.json');
const no = require('./no.json');

const all = yes.concat(no).sort();

exports.yes = yes;
exports.no = no;
exports.all = all;
exports.yesRandom = uniqueRandomArray(yes);
exports.noRandom = uniqueRandomArray(no);
exports.allRandom = uniqueRandomArray(all);
import uniqueRandomArray from 'unique-random-array';
import yesWords from './yes-words.json' with {type: 'json'};
import noWords from './no-words.json' with {type: 'json'};

const allWords = yesWords.concat(noWords).sort();

const yesNoWords = {};

yesNoWords.yes = yesWords;
yesNoWords.no = noWords;
yesNoWords.all = allWords;
yesNoWords.yesRandom = uniqueRandomArray(yesWords);
yesNoWords.noRandom = uniqueRandomArray(noWords);
yesNoWords.allRandom = uniqueRandomArray(allWords);

export default yesNoWords;
9 changes: 0 additions & 9 deletions index.test-d.ts

This file was deleted.

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 <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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
File renamed without changes.
34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@
"description": "Get yes/no-like words",
"license": "MIT",
"repository": "sindresorhus/yes-no-words",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"bin": {
"yes-no": "cli.js"
"yes-no": "./cli.js"
},
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=8"
"node": ">=18.20"
},
"scripts": {
"test": "xo && ava && tsd"
"//test": "xo && ava",
"test": "ava"
},
"files": [
"index.js",
"index.d.ts",
"cli.js",
"yes.json",
"no.json"
"yes-words.json",
"no-words.json"
],
"keywords": [
"cli-app",
Expand All @@ -43,17 +51,11 @@
"answer"
],
"dependencies": {
"meow": "^5.0.0",
"unique-random-array": "^2.0.0"
"meow": "^13.2.0",
"unique-random-array": "^3.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"tsd": {
"compilerOptions": {
"resolveJsonModule": true
}
"ava": "^6.1.2",
"xo": "^0.58.0"
}
}
32 changes: 11 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,63 @@

*The lists are just JSON files and can be used anywhere.*


## Install

```sh
npm install yes-no-words
```
$ npm install yes-no-words
```


## Usage

```js
const yesNoWords = require('yes-no-words');
import yesNoWords from 'yes-no-words';

yesNoWords.yesRandom();
//=> 'Yisss'
```


## API

### .yes
### `.yes`

Type: `string[]`

Yes like words.

### .no
### `.no`

Type: `string[]`

No like words.

### .all
### `.all`

Type: `string[]`

Both yes and no like words.

### .yesRandom()
### `.yesRandom()`

Type: `Function`

Random yes like words.

### .noRandom()
### `.noRandom()`

Type: `Function`

Random no like words.

### .allRandom()
### `.allRandom()`

Type: `Function`

Random yes or no like words.


## CLI

```
$ npm install --global yes-no-words
```sh
npm install --global yes-no-words
```

```
Expand All @@ -86,7 +82,6 @@ $ yes-no --help
--type Type of word: yes|no|all [Default: all]
```


## Related

- [cat-names](https://github.com/sindresorhus/cat-names) - Get popular cat names
Expand All @@ -95,8 +90,3 @@ $ yes-no --help
- [superheroes](https://github.com/sindresorhus/superheroes) - Get superhero names
- [supervillains](https://github.com/sindresorhus/supervillains) - Get supervillain names
- [superb](https://github.com/sindresorhus/superb) - Get superb like words


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import yesNoWords from '.';
import yesNoWords from './index.js';

test('main', t => {
t.true(yesNoWords.yes.length > 0);
Expand Down
File renamed without changes.

0 comments on commit ba8a429

Please sign in to comment.