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 a95dcdf commit 336f223
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 91 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 catNames = require('.');
import meow from 'meow';
import {catNames, randomCatName} from './index.js';

const cli = meow(`
Examples
Expand All @@ -15,6 +14,8 @@ const cli = meow(`
Options
--all Get all names instead of a random name
`);
`, {
importMeta: import.meta,
});

console.log(cli.flags.all ? catNames.all.join('\n') : catNames.random());
console.log(cli.flags.all ? catNames.join('\n') : randomCatName());
46 changes: 20 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import catNamesJson = require('./cat-names.json');
/**
Top 100 cat names in alphabetical order.
declare const catNames: {
/**
Top 100 cat names in alphabetical order.
@example
```
import {catNames} from 'cat-names';
@example
```
import catNames = require('cat-names');
catNames;
//=> ['Abby', 'Angel', …]
```
*/
export const catNames: readonly string[];

catNames.all;
//=> ['Abby', 'Angel', …]
```
*/
readonly all: Readonly<typeof catNamesJson>;
/**
Get a random cat name.
/**
Random cat name.
@example
```
import {randomCatName} from 'cat-names';
@example
```
import catNames = require('cat-names');
catNames.random();
//=> 'Max'
```
*/
random(): string;
};

export = catNames;
randomCatName();
//=> 'Max'
```
*/
export function randomCatName(): string;
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const uniqueRandomArray = require('unique-random-array');
const catNames = require('./cat-names.json');
import uniqueRandomArray from 'unique-random-array';
import catNames from './cat-names.json' with {type: 'json'};

exports.all = catNames;
exports.random = uniqueRandomArray(catNames);
export {catNames};

export const randomCatName = uniqueRandomArray(catNames);
6 changes: 3 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import catNames = require('.');
import {catNames, randomCatName} from './index.js';

expectType<readonly string[]>(catNames.all);
expectType<string>(catNames.random());
expectType<readonly string[]>(catNames);
expectType<string>(randomCatName());
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
36 changes: 17 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
"description": "Get popular cat names",
"license": "MIT",
"repository": "sindresorhus/cat-names",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"bin": "cli.js",
"type": "module",
"bin": "./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 && tsd",
"test": "ava && tsd"
},
"files": [
"index.js",
Expand Down Expand Up @@ -42,22 +50,12 @@
"male"
],
"dependencies": {
"meow": "^6.1.1",
"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
}
},
"xo": {
"rules": {
"import/extensions": "off"
}
"ava": "^6.1.2",
"tsd": "^0.31.0",
"xo": "^0.58.0"
}
}
30 changes: 10 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,42 @@ The name list is just a [JSON file](cat-names.json) and can be used anywhere.

*I'm not accepting PRs for additional names.*


## Install

```sh
npm install cat-names
```
$ npm install cat-names
```


## Usage

```js
const catNames = require('cat-names');
import {catNames, randomCatName} from 'cat-names';

catNames.all;
catNames;
//=> ['Abby', 'Angel', …]

catNames.random();
randomCatName();
//=> 'Max'
```


## API

### .all
### catNames

Type: `string[]`

Top 100 cat names in alphabetical order.

### .random()
### randomCatName()

Type: `Function`

Random cat name.

Get a random cat name.

## CLI

```
$ npm install --global cat-names
```sh
npm install --global cat-names
```

```
Expand All @@ -66,7 +62,6 @@ $ cat-names --help
--all Get all names instead of a random name
```


## Related

- [dog-names](https://github.com/sindresorhus/dog-names) - Get popular dog names
Expand All @@ -76,8 +71,3 @@ $ cat-names --help
- [supervillains](https://github.com/sindresorhus/supervillains) - Get supervillain names
- [random-tree-names](https://github.com/pguth/random-tree-names) - Get tree names
- [yes-no-words](https://github.com/sindresorhus/yes-no-words) - Get yes/no like words


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava';
import catNames from '.';
import {catNames, randomCatName} from './index.js';

test('main', t => {
t.true(catNames.all.length > 0);
t.truthy(catNames.random());
t.not(catNames.random(), catNames.random());
t.is(catNames.all[0], 'Abby');
t.is(catNames.all[1], 'Angel');
t.true(catNames.length > 0);
t.truthy(randomCatName());
t.not(randomCatName(), randomCatName());
t.is(catNames[0], 'Abby');
t.is(catNames[1], 'Angel');
});

0 comments on commit 336f223

Please sign in to comment.