MCPcopy Index your code
hub / github.com/coder/code-server / useEnv

Function useEnv

test/utils/helpers.ts:55–71  ·  view source on GitHub ↗
(key: string)

Source from the content-addressed store, hash-verified

53 * to set the value and reset the value
54 */
55export function useEnv(key: string): [(nextValue: string | undefined) => string | undefined, () => void] {
56 const initialValue = process.env[key]
57 const setValue = (nextValue: string | undefined) => (process.env[key] = nextValue)
58 // Node automatically converts undefined to string 'undefined'
59 // when assigning an environment variable.
60 // which is why we need to delete it if it's supposed to be undefined
61 // Source: https://stackoverflow.com/a/60147167
62 const resetValue = () => {
63 if (initialValue !== undefined) {
64 process.env[key] = initialValue
65 } else {
66 delete process.env[key]
67 }
68 }
69
70 return [setValue, resetValue]
71}
72
73/**
74 * Helper function to get a random port.

Callers 2

helpers.test.tsFile · 0.90
cli.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected