Skip to content

Commit 6e4f4f9

Browse files
author
hirsch88
committed
Move env helper functions to the utils file
1 parent 6584867 commit 6e4f4f9

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

src/env.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import * as dotenv from 'dotenv';
33
import * as pkg from '../package.json';
4+
import { toBool, toNumber, normalizePort, getOsEnv } from './lib/env';
45

56
/**
67
* Load .env file or for tests the .env.test file.
@@ -72,26 +73,3 @@ export const env = {
7273
password: getOsEnv('MONITOR_PASSWORD'),
7374
},
7475
};
75-
76-
function getOsEnv(key: string): string {
77-
return process.env[key] as string;
78-
}
79-
80-
function toNumber(value: string): number {
81-
return parseInt(value, 10);
82-
}
83-
84-
function toBool(value: string): boolean {
85-
return value === 'true';
86-
}
87-
88-
function normalizePort(port: string): number | string | boolean {
89-
const parsedPort = parseInt(port, 10);
90-
if (isNaN(parsedPort)) { // named pipe
91-
return port;
92-
}
93-
if (parsedPort >= 0) { // port number
94-
return parsedPort;
95-
}
96-
return false;
97-
}

src/lib/env/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './utils';

src/lib/env/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export function getOsEnv(key: string): string {
2+
return process.env[key] as string;
3+
}
4+
5+
export function toNumber(value: string): number {
6+
return parseInt(value, 10);
7+
}
8+
9+
export function toBool(value: string): boolean {
10+
return value === 'true';
11+
}
12+
13+
export function normalizePort(port: string): number | string | boolean {
14+
const parsedPort = parseInt(port, 10);
15+
if (isNaN(parsedPort)) { // named pipe
16+
return port;
17+
}
18+
if (parsedPort >= 0) { // port number
19+
return parsedPort;
20+
}
21+
return false;
22+
}

0 commit comments

Comments
 (0)