utils/node_modules/@rushstack/node-core-library/lib/EnvironmentMap.js.map
2024-02-07 01:33:07 -05:00

1 line
6.3 KiB
Plaintext

{"version":3,"file":"EnvironmentMap.js","sourceRoot":"","sources":["../src/EnvironmentMap.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,sDAA8B;AAC9B,mDAAgD;AAkBhD;;;;GAIG;AACH,MAAa,cAAc;IAYzB,YAAmB,oBAAwD,EAAE;QAX5D,SAAI,GAAmC,IAAI,GAAG,EAAE,CAAC;QAYhE,sGAAsG;QACtG,oGAAoG;QACpG,qGAAqG;QACrG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE;YAC1C,UAAU,EAAE,IAAI;YAChB,GAAG,EAAE;gBACH,MAAM,IAAI,6BAAa,CAAC,mDAAmD,CAAC,CAAC;YAC/E,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,GAAG,iBAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACI,GAAG,CAAC,IAAY,EAAE,KAAa;QACpC,MAAM,GAAG,GAAW,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACnE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAY;QACvB,MAAM,GAAG,GAAW,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACnE,IAAI,CAAC,IAA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C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA9GD,wCA8GC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport process from 'process';\nimport { InternalError } from './InternalError';\n\n/**\n * A process environment variable name and its value. Used by {@link EnvironmentMap}.\n * @public\n */\nexport interface IEnvironmentEntry {\n /**\n * The name of the environment variable.\n */\n name: string;\n\n /**\n * The value of the environment variable.\n */\n value: string;\n}\n\n/**\n * A map data structure that stores process environment variables. On Windows\n * operating system, the variable names are case-insensitive.\n * @public\n */\nexport class EnvironmentMap {\n private readonly _map: Map<string, IEnvironmentEntry> = new Map();\n\n /**\n * Whether the environment variable names are case-sensitive.\n *\n * @remarks\n * On Windows operating system, environment variables are case-insensitive.\n * The map will preserve the variable name casing from the most recent assignment operation.\n */\n public readonly caseSensitive: boolean;\n\n public constructor(environmentObject: Record<string, string | undefined> = {}) {\n // This property helps catch a mistake where an instance of `EnvironmentMap` is accidentally passed to\n // a function that expects a `Record<string, string>` (as would be used with the `process.env` API).\n // The property getter will throw an exception if that function tries to enumerate the object values.\n Object.defineProperty(this, '_sanityCheck', {\n enumerable: true,\n get: function () {\n throw new InternalError('Attempt to read EnvironmentMap class as an object');\n }\n });\n\n this.caseSensitive = process.platform !== 'win32';\n this.mergeFromObject(environmentObject);\n }\n\n /**\n * Clears all entries, resulting in an empty map.\n */\n public clear(): void {\n this._map.clear();\n }\n\n /**\n * Assigns the variable to the specified value. A previous value will be overwritten.\n *\n * @remarks\n * The value can be an empty string. To completely remove the entry, use\n * {@link EnvironmentMap.unset} instead.\n */\n public set(name: string, value: string): void {\n const key: string = this.caseSensitive ? name : name.toUpperCase();\n this._map.set(key, { name: name, value });\n }\n\n /**\n * Removes the key from the map, if present.\n */\n public unset(name: string): void {\n const key: string = this.caseSensitive ? name : name.toUpperCase();\n this._map.delete(key);\n }\n\n /**\n * Returns the value of the specified variable, or `undefined` if the map does not contain that name.\n */\n public get(name: string): string | undefined {\n const key: string = this.caseSensitive ? name : name.toUpperCase();\n const entry: IEnvironmentEntry | undefined = this._map.get(key);\n if (entry === undefined) {\n return undefined;\n }\n return entry.value;\n }\n\n /**\n * Returns the map keys, which are environment variable names.\n */\n public names(): IterableIterator<string> {\n return this._map.keys();\n }\n\n /**\n * Returns the map entries.\n */\n public entries(): IterableIterator<IEnvironmentEntry> {\n return this._map.values();\n }\n\n /**\n * Adds each entry from `environmentMap` to this map.\n */\n public mergeFrom(environmentMap: EnvironmentMap): void {\n for (const entry of environmentMap.entries()) {\n this.set(entry.name, entry.value);\n }\n }\n\n /**\n * Merges entries from a plain JavaScript object, such as would be used with the `process.env` API.\n */\n public mergeFromObject(environmentObject: Record<string, string | undefined> = {}): void {\n for (const [name, value] of Object.entries(environmentObject)) {\n if (value !== undefined) {\n this.set(name, value);\n }\n }\n }\n\n /**\n * Returns the keys as a plain JavaScript object similar to the object returned by the `process.env` API.\n */\n public toObject(): Record<string, string> {\n const result: Record<string, string> = {};\n for (const entry of this.entries()) {\n result[entry.name] = entry.value;\n }\n return result;\n }\n}\n"]}