Skip to content

Commit

Permalink
fix(utils): formatValueWithSymbol 자연스러운 역할 이해를 위해 네이밍 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 committed Jan 12, 2025
1 parent e15fc87 commit b391d16
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 480 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-forks-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-kit/utils': patch
---

fix(utils): formatValueWithSymbol 자연스러운 역할 이해를 위해 네이밍 변경 - @ssi02014
103 changes: 0 additions & 103 deletions docs/docs/utils/formatter/formatNumberWithCurrency.md

This file was deleted.

67 changes: 67 additions & 0 deletions docs/docs/utils/formatter/formatValueWithSymbol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# formatValueWithSymbol

주어진 `숫자` 또는 `문자열`에 주어진 `기호`를 추가하는 함수입니다.

- 기호는 `prefix` 또는 `suffix` 위치에 추가할 수 있습니다.
- `음수` 값의 경우 기호 앞에 `-`가 추가됩니다.
- 기호와 값 사이에 `공백`을 추가할 수 있습니다.

<br />

## Code
[🔗 실제 구현 코드 확인](https://github.com/modern-agile-team/modern-kit/blob/main/packages/utils/src/formatter/formatValueWithSymbol/index.ts)

## Interface
```ts title="typescript"
interface FormatValueWithSymbolOptions {
symbol?: string;
position?: 'prefix' | 'suffix';
space?: boolean;
}
```
```ts title="typescript"
function formatValueWithSymbol(
value: number | string,
options?: FormatValueWithSymbolOptions
): string;
```

## Usage
```ts title="typescript"
import { formatValueWithSymbol } from '@modern-kit/utils';

// 통화 기호 추가 (기본 값: '')
formatValueWithSymbol(1000) // '1000'
formatValueWithSymbol(1000, { symbol: '' }) // '1000원'

// 통호 기호 위치 변경 (기본값: 'suffix')
formatValueWithSymbol(1000, { symbol: '$', position: 'prefix' }) // '$1000'
formatValueWithSymbol(1000, { symbol: '', position: 'suffix' }) // '1000원'

// 공백 추가 (기본값: false)
formatValueWithSymbol(1000, { symbol: '$', position: 'prefix', space: false }) // '$1000'
formatValueWithSymbol(1000, { symbol: '$', position: 'prefix', space: true }) // '$ 1000'
```

<br />

### 응용
```ts title="typescript"
import {
formatValueWithSymbol,
formatNumberWithCommas,
formatNumberWithUnits
} from '@modern-kit/utils';

const KRW_UNITS = [
{ unit: '', value: 1_000_000_000_000 },
{ unit: '', value: 100_000_000 },
{ unit: '', value: 10_000 },
] as const;

const numberWithCommas = formatNumberWithCommas(1234567); // 1,234,567
const numberWithKRWUnits = formatNumberWithUnits(1230000, { units: KRW_UNITS }); // 123만

formatValueWithSymbol(numberWithKRWUnits, { symbol: '' }) // '123만원'
formatValueWithSymbol(numberWithCommas, { symbol: '' }) // '1,234,567원'
```

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b391d16

Please sign in to comment.