26 lines
578 B
TypeScript
Executable File
26 lines
578 B
TypeScript
Executable File
import path from "path";
|
|
|
|
export class Env {
|
|
constructor(private target: Record<string, string | undefined>) {}
|
|
|
|
set(key: string, value: string) {
|
|
this.target[key] = value;
|
|
}
|
|
|
|
get(key: string) {
|
|
return this.target[key];
|
|
}
|
|
|
|
addPath(value: string, key: string = "PATH") {
|
|
if (!this.target[key]) {
|
|
this.target[key] = value;
|
|
} else if (this.target[key].split(path.delimiter).indexOf(value) === -1) {
|
|
this.target[key] = [this.target[key], value].join(path.delimiter);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const env = new Env(process.env);
|
|
|
|
export default env;
|