Skip to content

Commit

Permalink
fix: rename mapIfExist to mapIfExists
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Apr 10, 2023
1 parent 9d03bc8 commit 2d1c8e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions __tests__/unit/env.picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ describe('EnvPicker', () => {
});
});

describe('mapIfExist', () => {
describe('mapIfExists', () => {
it('maps state if it exists', () => {
expect(new EnvPicker('123' as string | undefined, 'test').mapIfExist(Number).value()).toBe(123);
expect(new EnvPicker(undefined as string | undefined, 'test').default('123').mapIfExist(Number).value()).toBe(
expect(new EnvPicker('123' as string | undefined, 'test').mapIfExists(Number).value()).toBe(123);
expect(new EnvPicker(undefined as string | undefined, 'test').default('123').mapIfExists(Number).value()).toBe(
123,
);
expect(new EnvPicker('false', 'test').default('123').mapIfExist(JSON.parse).value()).toBe(false);
expect(new EnvPicker('false', 'test').default('123').mapIfExists(JSON.parse).value()).toBe(false);

expect(new EnvPicker(undefined as string | undefined, 'test').mapIfExist((state) => !!state).value()).toBe(
expect(new EnvPicker(undefined as string | undefined, 'test').mapIfExists((state) => !!state).value()).toBe(
undefined,
);
expect(new EnvPicker(null as string | null, 'test').mapIfExist((state) => !!state).value()).toBe(null);
expect(new EnvPicker(null as string | null, 'test').mapIfExists((state) => !!state).value()).toBe(null);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/env/env.picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class EnvPicker<S> {
return this as unknown as EnvPicker<R>;
}

public mapIfExist<R>(mapper: (state: NonNullable<S>) => R) {
public mapIfExists<R>(mapper: (state: NonNullable<S>) => R) {
if (this.state !== null && this.state !== undefined) {
this.state = mapper(this.state as NonNullable<S>) as unknown as S;
}
Expand Down

0 comments on commit 2d1c8e4

Please sign in to comment.