open-nomad/ui/app/utils/format-host.js
2023-04-10 15:36:59 +00:00

19 lines
322 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import isIp from 'is-ip';
export default function formatHost(address, port) {
if (!address || !port) {
return undefined;
}
if (isIp.v6(address)) {
return `[${address}]:${port}`;
} else {
return `${address}:${port}`;
}
}