Files
flipper/src/utils/environmentVariables.tsx
Pascal Hartig 9e423e4bef Migrate environmentVariables
Summary: _typescript_

Reviewed By: jknoxville

Differential Revision: D16709690

fbshipit-source-id: efa0431ab1ab0e2fc81ae4a9155d2f0a3ab9e4c5
2019-08-09 10:47:14 -07:00

26 lines
637 B
TypeScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export function parseFlipperPorts(
envVar: string,
): {insecure: number; secure: number} | undefined {
const components = envVar.split(',');
const ports = components.map(x => parseInt(x, 10));
// Malformed numbers will get parsed to NaN which is not > 0
if (
ports.length === 2 &&
components.every(x => /^[0-9]+$/.test(x)) &&
ports.every(x => x > 0)
) {
return {
insecure: ports[0],
secure: ports[1],
};
}
}