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 67ef63e commit 2d06287
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 75 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
46 changes: 21 additions & 25 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import superheroesJson = require('./superheroes.json');
/**
Superhero names in alphabetical order.
declare const superheroes: {
/**
Superhero names in alphabetical order.
@example
```
import superheroes from 'superheroes';
@example
```
import superheroes = require('superheroes');
superheroes;
//=> ['3-D Man', 'A-Bomb', …]
```
*/
declare const superheroes: readonly string[];

superheroes.all;
//=> ['3-D Man', 'A-Bomb', …]
```
*/
readonly all: Readonly<typeof superheroesJson>;
export default superheroes;

/**
Random superhero name.
/**
Get a random superhero name.
@example
```
import superheroes = require('superheroes');
@example
```
import {randomSuperhero} from 'superheroes';
superheroes.random();
//=> 'Spider-Ham'
```
*/
random(): string;
}

export = superheroes;
randomSuperhero();
//=> 'Spider-Ham'
```
*/
export function randomSuperhero(): 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 superheroes = require('./superheroes.json');
import uniqueRandomArray from 'unique-random-array';
import superheroes from './superheroes.json' with {type: 'json'};

exports.all = superheroes;
exports.random = uniqueRandomArray(superheroes);
export default superheroes;

export const randomSuperhero = uniqueRandomArray(superheroes);
5 changes: 0 additions & 5 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 <[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
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
"description": "Get superhero names",
"license": "MIT",
"repository": "sindresorhus/superheroes",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"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",
Expand All @@ -35,16 +43,10 @@
"comics"
],
"dependencies": {
"unique-random-array": "^2.0.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"
}
}
31 changes: 14 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,43 @@

The list is just a [JSON file](superheroes.json) and can be used anywhere.

**I'm not accepting additional entries to the list.**

## Install

```sh
npm install superheroes
```
$ npm install superheroes
```


## Usage

```js
const superheroes = require('superheroes');
import superheroes from 'superheroes';

superheroes.all;
superheroes;
//=> ['3-D Man', 'A-Bomb', …]

superheroes.random();
//=> 'Spider-Ham'
```


## API

### .all
### superheroes

Type: `string[]`

Superhero names in alphabetical order.

### .random()
### randomSuperhero()

Type: `Function`

Random superhero name.
Get a random superhero name.

```js
import {randomSuperhero} from 'superheroes';

randomSuperhero();
//=> 'Spider-Ham'
```

## Related

Expand All @@ -51,8 +53,3 @@ Random superhero name.
- [pokemon](https://github.com/sindresorhus/pokemon) - Get Pokémon names
- [superb](https://github.com/sindresorhus/superb) - Get superb like words
- [yes-no-words](https://github.com/sindresorhus/yes-no-words) - Get yes/no like words


## License

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

test('main', t => {
t.true(superheroes.all.length > 0);
t.true(superheroes.all.includes('Superman'));
t.truthy(superheroes.random());
t.true(superheroes.length > 0);
t.true(superheroes.includes('Superman'));
t.truthy(randomSuperhero());
});

0 comments on commit 2d06287

Please sign in to comment.