Skip to content

Commit 3e1ecae

Browse files
authored
refactor(utils): remove unused utils (#1797)
<!-- How to write a good PR title: - Follow [the Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ## Self Checklist - [x] I wrote a PR title in **English** and added an appropriate **label** to the PR. - [x] I wrote the commit message in **English** and to follow [**the Conventional Commits specification**](https://www.conventionalcommits.org/en/v1.0.0/). - [x] I [added the **changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) about the changes that needed to be released. (or didn't have to) - [x] I wrote or updated **documentation** related to the changes. (or didn't have to) - [x] I wrote or updated **tests** related to the changes. (or didn't have to) - [x] I tested the changes in various browsers. (or didn't have to) - Windows: Chrome, Edge, (Optional) Firefox - macOS: Chrome, Edge, Safari, (Optional) Firefox ## Summary <!-- Please brief explanation of the changes made --> - 사용하지 않는 유틸 함수들을 제거합니다. - 마이너: tsconfig build 잘못된 경로 수정 ## Details <!-- Please elaborate description of the changes --> - mergeClassName 함수는 classnames로 대체합니다. ### Breaking change? (Yes/No) <!-- If Yes, please describe the impact and migration path for users --> No
1 parent 987b41d commit 3e1ecae

File tree

6 files changed

+3
-169
lines changed

6 files changed

+3
-169
lines changed

packages/bezier-react/src/components/ListItem/ListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import React, {
55
useState,
66
} from 'react'
77

8+
import classNames from 'classnames'
89
import { v4 as uuid } from 'uuid'
910

1011
import { Typography } from '~/src/foundation'
1112

1213
import useMergeRefs from '~/src/hooks/useMergeRefs'
1314
import { noop } from '~/src/utils/function'
14-
import { mergeClassNames } from '~/src/utils/string'
1515
import {
1616
isEmpty,
1717
isNil,
@@ -98,7 +98,7 @@ forwardedRef: React.Ref<ListItemRef>,
9898
useAdjacentElementBorderRadius(listItemElement, filterActiveItem, isActive)
9999

100100
const mergedClassName = useMemo(() => (
101-
mergeClassNames(className, ((isActive && activeClassName) || undefined))
101+
classNames(className, isActive && activeClassName)
102102
), [
103103
className,
104104
activeClassName,

packages/bezier-react/src/utils/story.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ import { type IconName } from '@channel.io/bezier-icons'
22

33
import {
44
getObjectFromEnum,
5-
getTitle,
65
iconList,
76
} from './story'
87
import { isArray } from './type'
98

109
describe('storyUtils Test >', () => {
11-
describe('getTitle Test >', () => {
12-
it('정상 동작 테스트들', () => {
13-
expect(getTitle('/src/layout/GlobalHeader/')).toBe('layout/GlobalHeader')
14-
expect(getTitle('/foo/bar/ipsum/')).toBe('bar/ipsum')
15-
})
16-
})
17-
1810
describe('iconList Test >', () => {
1911
it('iconList는 리스트이다', () => {
2012
expect(isArray(iconList)).toBe(true)

packages/bezier-react/src/utils/story.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import {
55

66
import { isNaN } from './type'
77

8-
export const getTitle = (baseDir: string) => {
9-
const filePath = baseDir.split('/')
10-
// NOTE: 공백과 src를 제외하고 component/.../lastFolderName 을 return
11-
return filePath.slice(2, filePath.length - 1).join('/')
12-
}
13-
148
export const iconList: IconName[] = Object.keys(icons) as IconName[]
159

1610
interface Enum {

packages/bezier-react/src/utils/string.test.ts

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,9 @@
11
import {
22
camelCase,
3-
isNumberString,
43
kebabCase,
5-
mergeClassNames,
64
toString,
75
} from './string'
86

9-
describe('mergeClassNames()', () => {
10-
test('mergeClassNames() function should returns className string when 1st argument given', () => {
11-
expect(mergeClassNames('foo')).toBe('foo')
12-
})
13-
14-
test('mergeClassNames() function should returns className string when both of 1st and 2nd arguments given', () => {
15-
expect(mergeClassNames('foo', 'bar')).toBe('foo bar')
16-
})
17-
18-
test('mergeClassNames() function should returns className string when both of 1st, 2nd and 3rd or more arguments given', () => {
19-
expect(mergeClassNames('foo', 'bar', 'fooz', 'barz')).toBe('foo bar fooz barz')
20-
})
21-
22-
test('mergeClassNames() function should returns className string when 2nd arguments given and 1st is not', () => {
23-
expect(mergeClassNames(undefined, 'bar')).toBe('bar')
24-
})
25-
26-
test('mergeClassNames() function should returns className string when 2nd arguments given and 1st is empty string', () => {
27-
expect(mergeClassNames('', 'bar')).toBe('bar')
28-
})
29-
30-
test('mergeClassNames() function should returns undefined when not any argument given', () => {
31-
expect(mergeClassNames()).toBe(undefined)
32-
})
33-
34-
test('mergeClassNames() function should returns undefined when given every arguments are empty string', () => {
35-
expect(mergeClassNames('', ' ', undefined, ' ')).toBe(undefined)
36-
})
37-
})
38-
39-
describe('isNumberString()', () => {
40-
test('should returns true when given argument is number', () => {
41-
expect(isNumberString(1)).toBe(true)
42-
expect(isNumberString(100)).toBe(true)
43-
expect(isNumberString(12345678900)).toBe(true)
44-
expect(isNumberString(Number.POSITIVE_INFINITY)).toBe(true)
45-
expect(isNumberString(Number.MAX_VALUE)).toBe(true)
46-
})
47-
48-
test('should returns true when given argument consists of number character', () => {
49-
expect(isNumberString('1')).toBe(true)
50-
expect(isNumberString('1000')).toBe(true)
51-
expect(isNumberString('12345678900')).toBe(true)
52-
})
53-
54-
test('should returns true when given argument consists of number character with a positive or a negative symbol', () => {
55-
expect(isNumberString('-1000')).toBe(true)
56-
expect(isNumberString('+1000')).toBe(true)
57-
expect(isNumberString('--1000')).toBe(false)
58-
expect(isNumberString('++1000')).toBe(false)
59-
expect(isNumberString('+-1000')).toBe(false)
60-
})
61-
62-
test('should returns true when given argument is thousand-comma-formatted string', () => {
63-
expect(isNumberString('1,000,000,000')).toBe(true)
64-
expect(isNumberString('34,104,950,100')).toBe(true)
65-
expect(isNumberString('-34,104,950,100')).toBe(true)
66-
expect(isNumberString('+34,104,950,100')).toBe(true)
67-
expect(isNumberString('1,000,00')).toBe(false)
68-
})
69-
70-
test('should returns true when given argument consists of number character with floating point', () => {
71-
expect(isNumberString('1.000')).toBe(true)
72-
expect(isNumberString('1.123')).toBe(true)
73-
expect(isNumberString('10000.12345')).toBe(true)
74-
expect(isNumberString('-10000.12345')).toBe(true)
75-
expect(isNumberString('+10000.12345')).toBe(true)
76-
})
77-
78-
test('should returns true when given argument is thousand-comma-formatted string with floating point', () => {
79-
expect(isNumberString('34,104,950,100.000')).toBe(true)
80-
expect(isNumberString('34,104,950,100.123')).toBe(true)
81-
expect(isNumberString('-34,104,950,100.123')).toBe(true)
82-
expect(isNumberString('+34,104,950,100.123')).toBe(true)
83-
})
84-
85-
test('should returns false when given argument is neither string nor number', () => {
86-
expect(isNumberString()).toBe(false)
87-
expect(isNumberString(true)).toBe(false)
88-
expect(isNumberString({ value: 123 })).toBe(false)
89-
expect(isNumberString(() => 100)).toBe(false)
90-
expect(isNumberString('abcd')).toBe(false)
91-
expect(isNumberString('34,104,9250,100.123')).toBe(false)
92-
expect(isNumberString('1234-5678')).toBe(false)
93-
})
94-
})
95-
967
describe('toString', () => {
978
test('nullish value to empty string', () => {
989
expect(toString(null)).toBe('')

packages/bezier-react/src/utils/string.ts

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,8 @@
11
import {
22
isArray,
3-
isEmpty,
4-
isNumber,
5-
isString,
63
isSymbol,
74
} from '~/src/utils/type'
85

9-
export function mergeClassNames(className?: string, ...otherClassNames: Array<string | undefined>): string | undefined {
10-
if (!isEmpty(className) || !isEmpty(otherClassNames)) {
11-
const result: string[] = []
12-
const classNames = [className, ...otherClassNames]
13-
classNames.map((cn) => cn?.trim() ?? '').forEach((cn) => result.push(cn))
14-
15-
const joinedResult = result.filter((cn) => !isEmpty(cn)).join(' ')
16-
if (!isEmpty(joinedResult)) { return joinedResult }
17-
}
18-
return undefined
19-
}
20-
21-
const reUnescapedHtml = /[&<>"]/g
22-
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source)
23-
const htmlEscapes = {
24-
'&': '&amp;',
25-
'<': '&lt;',
26-
'>': '&gt;',
27-
'"': '&quot;',
28-
}
29-
30-
export function hasEscapeTags(str: string): boolean {
31-
return reHasUnescapedHtml.test(str)
32-
}
33-
34-
export function escapeTags(str: string): string {
35-
if (!isString(str)) { return str }
36-
37-
if (hasEscapeTags(str)) {
38-
return str.replace(reUnescapedHtml, (chr) => htmlEscapes[chr])
39-
}
40-
41-
return str
42-
}
43-
44-
const htmlUnescapes = {
45-
'&amp;': '&',
46-
'&lt;': '<',
47-
'&gt;': '>',
48-
'&quot;': '"',
49-
}
50-
51-
const reEscapedHtml = /&(?:amp|lt|gt|quot);/g
52-
const reHasEscapedHtml = RegExp(reEscapedHtml.source)
53-
54-
export function unescapeTags(str: string): string {
55-
if (!isString(str)) { return str }
56-
57-
return (
58-
reHasEscapedHtml.test(str) ?
59-
str.replace(reEscapedHtml, (entity) => htmlUnescapes[entity]) : str
60-
)
61-
}
62-
63-
export function isNumberString(value?: any) {
64-
if (isNumber(value)) { return true }
65-
if (isString(value)) { return /^(?:-|\+|)?\d+(?:,\d{3})*(?:\.\d+)?$/.test(value) }
66-
return false
67-
}
68-
696
export function toString(value: unknown): string {
707
if (value == null) { return '' }
718
if (typeof value === 'string') { return value }

packages/bezier-react/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"**/*.stories.tsx",
55
"**/*.test.ts",
66
"**/*.test.tsx",
7-
"./src/utils/testUtils.tsx",
7+
"./src/utils/test.tsx",
88
"./src/utils/story.ts",
99
],
1010
"compilerOptions": {

0 commit comments

Comments
 (0)