mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
docs(deburr): Add docs for deburr
This commit is contained in:
parent
58d1cb2fd4
commit
c7d12a1c80
@ -216,6 +216,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'endsWith (compat)', link: '/ja/reference/compat/string/endsWith' },
|
||||
{ text: 'padStart (compat)', link: '/ja/reference/compat/string/padStart' },
|
||||
{ text: 'padEnd (compat)', link: '/ja/reference/compat/string/padEnd' },
|
||||
{ text: 'deburr', link: '/ja/reference/string/deburr' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -233,6 +233,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'endsWith (호환성)', link: '/ko/reference/compat/string/endsWith' },
|
||||
{ text: 'padStart (호환성)', link: '/ko/reference/compat/string/padStart' },
|
||||
{ text: 'padEnd (호환성)', link: '/ko/reference/compat/string/padEnd' },
|
||||
{ text: 'deburr', link: '/ko/reference/string/deburr' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
28
docs/ja/reference/string/deburr.md
Normal file
28
docs/ja/reference/string/deburr.md
Normal file
@ -0,0 +1,28 @@
|
||||
# deburr
|
||||
|
||||
文字列を変換し、特殊文字やアクセント記号をその ASCII 等価文字に置き換えます。例えば、`"Crème brûlée"`は`"Creme brulee"`になります。
|
||||
|
||||
## インターフェース
|
||||
|
||||
```typescript
|
||||
function deburr(str: string): string;
|
||||
```
|
||||
|
||||
### パラメータ
|
||||
|
||||
- `str` (`string`): デバリングする入力文字列。
|
||||
|
||||
### 戻り値
|
||||
|
||||
(`string`): 特殊文字が ASCII 等価文字に置き換えられたデバリングされた文字列。
|
||||
|
||||
## 例
|
||||
|
||||
```typescript
|
||||
import { deburr } from 'es-toolkit/string';
|
||||
|
||||
deburr('déjà vu'); // 'deja vu'を返します
|
||||
deburr('Æthelred'); // 'Aethelred'を返します
|
||||
deburr('München'); // 'Munchen'を返します
|
||||
deburr('Crème brûlée'); // 'Creme brulee'を返します
|
||||
```
|
28
docs/ko/reference/string/deburr.md
Normal file
28
docs/ko/reference/string/deburr.md
Normal file
@ -0,0 +1,28 @@
|
||||
# deburr
|
||||
|
||||
`Æ`, `ß`, `ü`와 같은 특수문자나 다이어크리틱을 ASCII 문자로 바꿔요. 예를 들어서, `"Crème brûlée"`를 `"Creme brulee"`로 바꿔요.
|
||||
|
||||
## 인터페이스
|
||||
|
||||
```typescript
|
||||
function deburr(str: string): string;
|
||||
```
|
||||
|
||||
### 파라미터
|
||||
|
||||
- `str` (`string`): 특수문자나 다이어크리틱을 포함하는 문자열.
|
||||
|
||||
### 반환 값
|
||||
|
||||
(`string`): 특수문자나 다이어크리틱이 ASCII 문자로 바뀐 문자열.
|
||||
|
||||
## 예시
|
||||
|
||||
```typescript
|
||||
import { deburr } from 'es-toolkit/string';
|
||||
|
||||
deburr('déjà vu'); // 반환 값: 'deja vu'
|
||||
deburr('Æthelred'); // 반환 값: 'Aethelred'
|
||||
deburr('München'); // 반환 값: 'Munchen'
|
||||
deburr('Crème brûlée'); // 반환 값: 'Creme brulee'
|
||||
```
|
@ -1,6 +1,6 @@
|
||||
# deburr
|
||||
|
||||
Deburrs `str` by converting [Latin-1 Supplement](<https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table>) and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) letters to basic Latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
||||
Converts a string by replacing special characters and diacritical marks with their ASCII equivalents. For example, `"Crème brûlée"` becomes `"Creme brulee"`.
|
||||
|
||||
## Signature
|
||||
|
||||
@ -10,11 +10,11 @@ function deburr(str: string): string;
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string to deburr.
|
||||
- `str` (`string`): The input string to be deburred.
|
||||
|
||||
### Returns
|
||||
|
||||
(`string`) The deburred string.
|
||||
(`string`): The deburred string with special characters replaced by their ASCII equivalents.
|
||||
|
||||
## Examples
|
||||
|
||||
@ -22,4 +22,7 @@ function deburr(str: string): string;
|
||||
import { deburr } from 'es-toolkit/string';
|
||||
|
||||
deburr('déjà vu'); // returns 'deja vu'
|
||||
deburr('Æthelred'); // returns 'Aethelred'
|
||||
deburr('München'); // returns 'Munchen'
|
||||
deburr('Crème brûlée'); // returns 'Creme brulee'
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
# deburr
|
||||
|
||||
转换字符串 `str` 中[拉丁语-1补充字母](<https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table>)和[拉丁语扩展字母-A](https://en.wikipedia.org/wiki/Latin_Extended-A)为基本的拉丁字母,并且去除[组合变音标记](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks)。
|
||||
将字符串转换为 ASCII 等效字符,通过替换特殊字符和重音符号。例如,`"Crème brûlée"` 变为 `"Creme brulee"`。
|
||||
|
||||
## 签名
|
||||
|
||||
@ -22,4 +22,7 @@ function deburr(str: string): string;
|
||||
import { deburr } from 'es-toolkit/string';
|
||||
|
||||
deburr('déjà vu'); // 返回 'deja vu'
|
||||
deburr('Æthelred'); // 返回: 'Aethelred'
|
||||
deburr('München'); // 返回: 'Munchen'
|
||||
deburr('Crème brûlée'); // 返回: 'Creme brulee'
|
||||
```
|
||||
|
@ -513,6 +513,12 @@ const deburredLetters = [
|
||||
];
|
||||
|
||||
describe('deburr', () => {
|
||||
it('should convert examples correctly', () => {
|
||||
expect(deburr('Æthelred')).toBe('Aethelred');
|
||||
expect(deburr('München')).toBe('Munchen');
|
||||
expect(deburr('Crème brûlée')).toBe('Creme brulee');
|
||||
});
|
||||
|
||||
it('should convert Latin Unicode letters to basic Latin', () => {
|
||||
const actual = burredLetters.map(deburr);
|
||||
expect(actual).toEqual(deburredLetters);
|
||||
|
@ -31,10 +31,23 @@ const deburrMap: Record<string, string> = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Deburrs `str` by converting [Latin-1 Supplement](<https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table>) and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) letters to basic Latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
||||
* Converts a string by replacing special characters and diacritical marks with their ASCII equivalents.
|
||||
* For example, "Crème brûlée" becomes "Creme brulee".
|
||||
*
|
||||
* @param {string} str The string to deburr.
|
||||
* @returns {string} Returns the deburred string.
|
||||
* @param {string} str - The input string to be deburred.
|
||||
* @returns {string} - The deburred string with special characters replaced by their ASCII equivalents.
|
||||
*
|
||||
* @example
|
||||
* // Basic usage:
|
||||
* deburr('Æthelred') // returns 'Aethelred'
|
||||
*
|
||||
* @example
|
||||
* // Handling diacritical marks:
|
||||
* deburr('München') // returns 'Munchen'
|
||||
*
|
||||
* @example
|
||||
* // Special characters:
|
||||
* deburr('Crème brûlée') // returns 'Creme brulee'
|
||||
*/
|
||||
export function deburr(str: string): string {
|
||||
str = str.normalize('NFD');
|
||||
|
Loading…
Reference in New Issue
Block a user