Skip to content

Commit

Permalink
Remove number argument
Browse files Browse the repository at this point in the history
Use `getPort({port: <number>})` instead.
  • Loading branch information
sindresorhus committed Jul 24, 2018
1 parent 405abaf commit 1ee643a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions index.js
Expand Up @@ -14,12 +14,6 @@ const isAvailable = options => new Promise((resolve, reject) => {
});

const getPort = (options = {}) => new Promise((resolve, reject) => {
// For backwards compatibility with number-only input
// TODO: Remove this in the next major version
if (typeof options === 'number') {
options = {port: options};
}

if (typeof options.port === 'number') {
options.port = [options.port];
}
Expand All @@ -34,5 +28,5 @@ const getPort = (options = {}) => new Promise((resolve, reject) => {
});

module.exports = options => options ?
getPort(options).catch(() => getPort(0)) :
getPort(0);
getPort(options).catch(() => getPort({port: 0})) :
getPort({port: 0});
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -16,7 +16,7 @@ test('port can be bound when promise resolves', async t => {

test('preferred port', async t => {
const desiredPort = 8080;
const port = await m(desiredPort);
const port = await m({port: desiredPort});

t.is(port, desiredPort);
});
Expand All @@ -28,7 +28,7 @@ test('preferred port unavailable', async t => {
const server = net.createServer();
await pify(server.listen.bind(server))(desiredPort);

const port = await m(desiredPort);
const port = await m({port: desiredPort});
t.is(typeof port, 'number');
t.true(port > 0);
t.not(port, desiredPort);
Expand Down

0 comments on commit 1ee643a

Please sign in to comment.