Files
webshell/src/shell/wush/Environment.ts
2026-05-21 13:47:27 +02:00

41 lines
1.1 KiB
TypeScript

/**
* Wush environment manager
* Manages environment variables, aliases etc.
*/
export class Environment {
private variables: Record<string, string> = {}
private aliases: Record<string, string> = {}
SetVariable(name: string, value: any | null): void {
if (value === null) {
// remove the variable if value is null
delete this.variables[name]
} else this.variables[name] = String(value)
}
GetVariable(name: string): string | null {
return this.variables[name] ?? null
}
SetAlias(name: string, value: string | null): void {
if (value === null) {
// remove the alias if value is null
delete this.aliases[name]
} else this.aliases[name] = value
}
GetAlias(name: string): string | null {
return this.aliases[name] ?? null
}
GetAliasesByValue(value: string): string[] | null {
const keys: string[] = []
for (const key in this.aliases)
if (this.aliases[key] === value)
keys.push(key)
return keys.length === 0 ? null : keys
}
}