import process from 'process' ; import { InternalError } from './InternalError' ; /**
 * A process environment variable name and its value.  Used by  EnvironmentMap .
 *  public export interface IEnvironmentEntry { /**
     * The name of the environment variable.
     */ name : string ; /**
     * The value of the environment variable.
     */ value : string ; } public export class EnvironmentMap { private readonly _map : Map < string , IEnvironmentEntry > = new Map ( ) ; remarks public readonly caseSensitive : boolean ; public constructor ( environmentObject = { } ) { Object . defineProperty ( this , '_sanityCheck' , { enumerable : true , get : function ( ) { throw new InternalError ( 'Attempt to read EnvironmentMap class as an object' ) ; } } ) ; this . caseSensitive = process . platform !== 'win32' ; this . mergeFromObject ( environmentObject ) ; } /**
     * Clears all entries, resulting in an empty map.
     */ public clear ( ) { this . _map . clear ( ) ; } remarks The value can be an empty string.  To completely remove the entry, use
     *  EnvironmentMap . unset instead.
      public set ( name , value ) { const key = this . caseSensitive ? name : name . toUpperCase ( ) ; this . _map . set ( key , { name : name , value } ) ; } /**
     * Removes the key from the map, if present.
     */ public unset ( name ) { const key = this . caseSensitive ? name : name . toUpperCase ( ) ; this . _map . delete ( key ) ; } /**
     * Returns the value of the specified variable, or `undefined` if the map does not contain that name.
     */ public get ( name ) { const key = this . caseSensitive ? name : name . toUpperCase ( ) ; const entry = this . _map . get ( key ) ; if ( entry === undefined ) { return undefined ; } return entry . value ; } /**
     * Returns the map keys, which are environment variable names.
     */ public names ( ) { return this . _map . keys ( ) ; } /**
     * Returns the map entries.
     */ public entries ( ) { return this . _map . values ( ) ; } /**
     * Adds each entry from `environmentMap` to this map.
     */ public mergeFrom ( environmentMap ) { for ( const entry of environmentMap . entries ( ) ) { this . set ( entry . name , entry . value ) ; } } /**
     * Merges entries from a plain JavaScript object, such as would be used with the `process.env` API.
     */ public mergeFromObject ( environmentObject = { } ) { for ( const [ name , value ] of Object . entries ( environmentObject ) ) { if ( value !== undefined ) { this . set ( name , value ) ; } } } /**
     * Returns the keys as a plain JavaScript object similar to the object returned by the `process.env` API.
     */ public toObject ( ) { const result = { } ; for ( const entry of this . entries ( ) ) { result [ entry . name ] = entry . value ; } return result ; } }