Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils): MIME 관련 유틸 함수 추가 #127

Merged
merged 6 commits into from
May 15, 2024
Merged

feat(utils): MIME 관련 유틸 함수 추가 #127

merged 6 commits into from
May 15, 2024

Conversation

ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented May 14, 2024

Overview

#126
file과 관련된 유틸 함수를 관리하기 위해 file 폴더 추가했으며, MIME 타입을 얻을 수 있는 관련 유틸 함수를 추가합니다.
덤으로 isString, isMIMEType 함수도 추가하였습니다.

PR Checklist

  • All tests pass.
  • All type checks pass.
  • I have read the Contributing Guide document.
    Contributing Guide

@ssi02014 ssi02014 added documentation 문서 추가 및 수정 feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils labels May 14, 2024
@ssi02014 ssi02014 requested a review from Sangminnn May 14, 2024 12:34
@ssi02014 ssi02014 self-assigned this May 14, 2024
Copy link

changeset-bot bot commented May 14, 2024

🦋 Changeset detected

Latest commit: 0902a62

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modern-kit/utils Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

import { MIMEType, MIME_TYPES } from '../../file/constants';

export const isMIMEType = (type: string): type is MIMEType => {
return MIME_TYPES.some((value) => value === type);
Copy link
Contributor Author

@ssi02014 ssi02014 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

배열을 상수로서 as const로 관리 할 경우 includes 메서드 활용 시 인자의 타입으로 string이면 타입 에러가 발생합니다 따라서 some으로 대체합니다.

💡 #128 PR에서 개선되었습니다

const result = getMIMETypeFromFile(file);
expect(result).toBe('');
});
});
Copy link
Contributor Author

@ssi02014 ssi02014 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMIMETypeFromResponse, getMIMETypeFromUrl은 테스트 코드 작성이 쉽지 않아 우선 테스트 코드를 제외했습니다.

Copy link

codecov bot commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.01%. Comparing base (f4eb1d8) to head (0902a62).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
+ Coverage   92.97%   93.01%   +0.04%     
==========================================
  Files          70       72       +2     
  Lines         626      630       +4     
  Branches      142      142              
==========================================
+ Hits          582      586       +4     
  Misses         37       37              
  Partials        7        7              
Components Coverage Δ
@modern-kit/react 87.31% <ø> (ø)
@modern-kit/utils 100.00% <100.00%> (ø)

@ssi02014 ssi02014 merged commit 54d89df into main May 15, 2024
3 checks passed
@ssi02014 ssi02014 deleted the feat/MIME branch May 15, 2024 07:41
@github-actions github-actions bot mentioned this pull request May 14, 2024
@Sangminnn
Copy link
Collaborator

@ssi02014 고생많으셨습니다! 내용은 별도로 확인해보겠습니다! 👍👍👍

@ssi02014
Copy link
Contributor Author

@Sangminnn 감사합니다 복잡도 있는 코드들은 아니어서 쉽게 파악이 될 것으로 생각됩니다 😄

console.error(
`Failed to get the MIME type from the URL. message: ${err.message}`
);
return '';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반환 타입을 string으로 맞춰주는 것이 사용성에 편할 것으로 판단해 빈 문자열을 반환하는 방향으로 작업하였습니다.

@ssi02014
Copy link
Contributor Author

@Sangminnn #128 해당 PR에서 isMIMEType을 개선하였습니다.
인자로 모든 타입을 받을 수 있게 unknown타입으로 확장하고, 추가된 isString 으로 검증 단계를 거칩니다.

import { isString } from '../isString';
import { MIMEType, MIME_TYPES } from '../../file/constants';

export const isMIMEType = (arg: unknown): arg is MIMEType => {
  return isString(arg) ? MIME_TYPES.some((value) => value === arg) : false;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 문서 추가 및 수정 feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants