Files
flipper/src/utils/environmentVariables.js
Pascal Hartig 1101306249 Move FLIPPER_PORTS error handling out of function
Summary:
The function itself can easily be pure. Let's have the side-effects
(lookup of env variable and error handling) outside of it. Also
prevents spam in the test log (which I intend to make a test failure
going forwards).

Current output:
{F149794656}

Reviewed By: jknoxville

Differential Revision: D13894995

fbshipit-source-id: dacf51f8b35cb427740f9566ef993ffc6b2c3906
2019-01-31 03:16:55 -08:00

26 lines
626 B
JavaScript

/**
* 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} {
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],
};
}
}