Skip to content

Commit

Permalink
Rename to getEnvVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Oct 24, 2024
1 parent e0f520e commit ac3b847
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/circuit-ui/components/Display/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { forwardRef, type HTMLAttributes } from 'react';
import { clsx } from '../../styles/clsx.js';
import { CircuitError } from '../../util/errors.js';
import { deprecate } from '../../util/logger.js';
import { getEnv } from '../../util/env.js';
import { getEnvVariable } from '../../util/env.js';

import classes from './Display.module.css';

Expand Down Expand Up @@ -76,7 +76,7 @@ export const Display = forwardRef<HTMLHeadingElement, DisplayProps>(
if (
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!getEnv('UNSAFE_DISABLE_ELEMENT_ERRORS') &&
!getEnvVariable('UNSAFE_DISABLE_ELEMENT_ERRORS') &&
!as
) {
throw new CircuitError('Display', 'The `as` prop is required.');
Expand Down
4 changes: 2 additions & 2 deletions packages/circuit-ui/components/Headline/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { forwardRef, type HTMLAttributes } from 'react';
import { clsx } from '../../styles/clsx.js';
import { CircuitError } from '../../util/errors.js';
import { deprecate } from '../../util/logger.js';
import { getEnv } from '../../util/env.js';
import { getEnvVariable } from '../../util/env.js';

import classes from './Headline.module.css';

Expand Down Expand Up @@ -69,7 +69,7 @@ export const Headline = forwardRef<HTMLHeadingElement, HeadlineProps>(
if (
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!getEnv('UNSAFE_DISABLE_ELEMENT_ERRORS') &&
!getEnvVariable('UNSAFE_DISABLE_ELEMENT_ERRORS') &&
!as
) {
throw new CircuitError('Headline', 'The `as` prop is required.');
Expand Down
12 changes: 6 additions & 6 deletions packages/circuit-ui/util/env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

import { beforeEach, describe, expect, it } from 'vitest';

import { getEnv } from './env.js';
import { getEnvVariable } from './env.js';

describe('env', () => {
describe('getEnvironment', () => {
describe('getEnvVariable', () => {
const originalProcess = process;

beforeEach(() => {
Expand All @@ -28,24 +28,24 @@ describe('env', () => {

it('should return the environment variable`', () => {
process.env.FOO = 'foo';
const actual = getEnv('FOO');
const actual = getEnvVariable('FOO');
expect(actual).toBe('foo');
});

it('should return undefined if the environment variable is not defined', () => {
const actual = getEnv('FOO');
const actual = getEnvVariable('FOO');
expect(actual).toBeUndefined();
});

it('should return undefined if `process` is not defined', () => {
// @ts-expect-error We're testing for this error
process = undefined;
const actual = getEnv('FOO');
const actual = getEnvVariable('FOO');
expect(actual).toBeUndefined();
});

it('should throw an error when used for `NODE_ENV`', () => {
const actual = () => getEnv('NODE_ENV');
const actual = () => getEnvVariable('NODE_ENV');
expect(actual).toThrowError();
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/circuit-ui/util/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

export function getEnv(name: string) {
export function getEnvVariable(name: string) {
if (name === 'NODE_ENV') {
// Some bundlers have special logic for `process.env.NODE_ENV` which
// relies on it being written as a continuous string. Destructuring or
Expand Down

0 comments on commit ac3b847

Please sign in to comment.