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 2618857 commit ee54179
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 72 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: 20 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import supervillainsJson = require('./supervillains.json');
/**
Supervillain names in alphabetical order.
declare const supervillains: {
/**
Supervillain names in alphabetical order.
@example
```
import supervillains from 'supervillains';
@example
```
const supervillains = require('supervillains');
supervillains;
//=> ['Abattoir', 'Able Crown', …]
```
*/
declare const supervillains: readonly string[];

supervillains.all;
//=> ['Abattoir', 'Able Crown', …]
```
*/
readonly all: Readonly<typeof supervillainsJson>;
/**
Get a random supervillain name.
/**
Random supervillain name.
@example
```
import {randomSupervillain} from 'supervillains';
@example
```
const supervillains = require('supervillains');
supervillains.random();
//=> 'Mud Pack'
```
*/
random(): Readonly<typeof supervillainsJson>[number];
};

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

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

export const randomSupervillain = uniqueRandomArray(supervillains);
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 <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
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
"description": "Get supervillain names",
"license": "MIT",
"repository": "sindresorhus/supervillains",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"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 @@ -36,21 +44,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
}
},
"xo": {
"rules": {
"import/extensions": "off"
}
"ava": "^6.1.2",
"xo": "^0.58.0"
}
}
20 changes: 12 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,32 @@ npm install supervillains
## Usage

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

supervillains.all;
supervillains;
//=> ['Abattoir', 'Able Crown', …]

supervillains.random();
//=> 'Mud Pack'
```

## API

### .all
### supervillains

Type: `string[]`

Supervillain names in alphabetical order.

### .random()
### randomSupervillain()

Type: `Function`

Random supervillain name.
Get a random supervillain name.

```js
import {randomSupervillain} from 'supervillains';

randomSupervillain();
//=> 'Mud Pack'
```

## Related

Expand Down
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 supervillains from '.';
import supervillains, {randomSupervillain} from './index.js';

test('main', t => {
t.true(supervillains.all.length > 0);
t.true(supervillains.all.includes('Mud Pack'));
t.truthy(supervillains.random());
t.true(supervillains.length > 0);
t.true(supervillains.includes('Mud Pack'));
t.truthy(randomSupervillain());
});

0 comments on commit ee54179

Please sign in to comment.