Skip to content

Commit

Permalink
Merge pull request #25 from mbti-nf-team/refactor/edit-variable-name
Browse files Browse the repository at this point in the history
refactor(@nft-team/core): 유틸함수 변수명 변경
- `checkNull` -> `removeNullable`
- `checkNumNull` -> `checkNumber`
  • Loading branch information
saseungmin authored Jul 19, 2023
2 parents a235102 + 6d287ed commit 4d9e503
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-bobcats-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nft-team/core": minor
---

refactor(@nft-team/core): 유틸함수 변수명 변경 (`removeNullable`, `checkNumber`)
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
checkEmpty, checkNull, checkNumNull, emptyAThenB, generateArrayOfNumber,
isEmpty, trueOrFalse,
checkEmpty, checkNumber, emptyAThenB, generateArrayOfNumber,
isEmpty, removeNullable, trueOrFalse,
} from './utils';
18 changes: 9 additions & 9 deletions packages/core/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {
checkEmpty,
checkNull,
checkNumNull,
checkNumber,
emptyAThenB,
generateArrayOfNumber,
isEmpty,
removeNullable,
trueOrFalse,
} from './utils';

describe('checkNull', () => {
describe('removeNullable', () => {
context('value가 null일 경우', () => {
context('replacementValue가 존재하지 않는 경우', () => {
it('빈 문자열을 반환해야만 한다', () => {
const result = checkNull(null);
const result = removeNullable(null);

expect(result).toBe('');
});
});

context('replacementValue가 존재하는 경우', () => {
it('대체할 문자열(두 번째 인자)을 반환해야만 한다', () => {
const result = checkNull(undefined, '-');
const result = removeNullable(undefined, '-');

expect(result).toBe('-');
});
Expand All @@ -29,25 +29,25 @@ describe('checkNull', () => {

context('value가 null이 아닌 경우', () => {
it('입력된 값이 반환되어야만 한다', () => {
const result = checkNull('nana');
const result = removeNullable('nana');

expect(result).toBe('nana');
});
});
});

describe('checkNumNull', () => {
describe('checkNumber', () => {
context('value가 null인 경우', () => {
it('0을 반환해야 한다', () => {
const result = checkNumNull(0);
const result = checkNumber(null);

expect(result).toBe(0);
});
});

context('value가 null이 아닌 경우', () => {
it('입력된 값이 반환되어야 한다', () => {
const result = checkNumNull(100);
const result = checkNumber(100);

expect(result).toBe(100);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const checkNull = (value?: string | null, replacementValue?: string): string => {
export const removeNullable = (value?: string | null, replacementValue?: string): string => {
if (value) {
return value;
}
Expand All @@ -10,12 +10,12 @@ export const checkNull = (value?: string | null, replacementValue?: string): str
return '';
};

export const checkNumNull = (value?: number | null): number => {
if (!value) {
return 0;
export const checkNumber = (value?: number | null): number => {
if (typeof value === 'number') {
return value;
}

return value;
return 0;
};

export const emptyAThenB = (b: string, a?: string | null): string => a || b;
Expand Down

0 comments on commit 4d9e503

Please sign in to comment.