docs(escape, unescape): Add docs for escape & unescape
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run

This commit is contained in:
raon0211 2024-09-03 23:53:24 +09:00
parent 2dab51b468
commit 4fea8d2a00
11 changed files with 123 additions and 4 deletions

View File

@ -222,6 +222,8 @@ function sidebar(): DefaultTheme.Sidebar {
{ 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' },
{ text: 'escape', link: '/ja/reference/string/escape' },
{ text: 'unescape', link: '/ja/reference/string/unescape' },
{ text: 'pad', link: '/ja/reference/string/pad' },
{ text: 'repeat (compat)', link: '/ja/reference/compat/string/pad' },
],

View File

@ -239,6 +239,8 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'padStart (호환성)', link: '/ko/reference/compat/string/padStart' },
{ text: 'padEnd (호환성)', link: '/ko/reference/compat/string/padEnd' },
{ text: 'deburr', link: '/ko/reference/string/deburr' },
{ text: 'escape', link: '/ko/reference/string/escape' },
{ text: 'unescape', link: '/ko/reference/string/unescape' },
{ text: 'pad', link: '/ko/reference/string/pad' },
{ text: 'repeat (호환성)', link: '/ko/reference/compat/string/pad' },
],

View File

@ -0,0 +1,28 @@
# escape
`"&"`、`"<"`、`">"`、`'"'`、および "\`" のような文字列を、HTMLで安全に使用できるエンティティ文字列に変換します。例えば、`"<"` は `"&lt;"` に変換されます。
## インターフェース
```typescript
function escape(str: string): string;
```
### パラメータ
- `str` (`string`): HTMLで安全に使用するために変換する文字列。
### 戻り値
(`string`): 変換された文字列。
## 例
```typescript
import { escape } from 'es-toolkit/string';
escape('This is a <div> element.'); // returns 'This is a &lt;div&gt; element.'
escape('This is a "quote"'); // returns 'This is a &quot;quote&quot;'
escape("This is a 'quote'"); // returns 'This is a &#39;quote&#39;'
escape('This is a & symbol'); // returns 'This is a &amp; symbol'
```

View File

@ -0,0 +1,28 @@
# unescape
`"&amp;"`、`"&lt;"`、`"&gt;"`、`"&quot;"`、および `"&#39;"` のようなHTMLエンティティ文字列を元の文字列に戻します。これは[escape](./escape.md)の逆の操作です。
## インターフェース
```typescript
function unescape(str: string): string;
```
### パラメータ
- `str` (`string`): 変換する文字列。
### 戻り値
(`string`): 変換された文字列。
## 例
```typescript
import { unescape } from 'es-toolkit/string';
unescape('This is a &lt;div&gt; element.'); // returns 'This is a <div> element.'
unescape('This is a &quot;quote&quot;'); // returns 'This is a "quote"'
unescape('This is a &#39;quote&#39;'); // returns 'This is a 'quote''
unescape('This is a &amp; symbol'); // returns 'This is a & symbol'
```

View File

@ -0,0 +1,28 @@
# escape
`"&"`, `"<"`, `">"`, `'"'`, and `"'"` 같은 문자열을 HTML에 쓰기 안전한 엔티티 문자열로 바꿔요. 예를 들어서, `"<"``"&lt;"`가 돼요.
## 인터페이스
```typescript
function escape(str: string): string;
```
### 파라미터
- `str` (`string`): HTML에서 쓰기 안전하게 바꿀 문자열.
### 반환 값
(`string`): 변환된 문자열.
## 예시
```typescript
import { escape } from 'es-toolkit/string';
escape('This is a <div> element.'); // returns 'This is a &lt;div&gt; element.'
escape('This is a "quote"'); // returns 'This is a &quot;quote&quot;'
escape("This is a 'quote'"); // returns 'This is a &#39;quote&#39;'
escape('This is a & symbol'); // returns 'This is a &amp; symbol'
```

View File

@ -0,0 +1,28 @@
# unescape
`&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;` 같은 HTML 엔티티 문자열을 원래 문자열로 바꿔요. [`escape`](./escape.md)의 반대 연산이에요.
## 인터페이스
```typescript
function unescape(str: string): string;
```
### 파라미터
- `str` (`string`): 변환할 문자열.
### 반환 값
(`string`): 변환된 문자열.
## 예시
```typescript
import { unescape } from 'es-toolkit/string';
unescape('This is a &lt;div&gt; element.'); // returns 'This is a <div> element.'
unescape('This is a &quot;quote&quot;'); // returns 'This is a "quote"'
unescape('This is a &#39;quote&#39;'); // returns 'This is a 'quote''
unescape('This is a &amp; symbol'); // returns 'This is a & symbol'
```

View File

@ -1,6 +1,6 @@
# escape
Converts the characters "&", "<", ">", '"', and "'" in `str` to their corresponding HTML entities.
Converts the characters "&", "<", ">", '"', and "'" in `str` to their corresponding HTML entities. For example, `"<"` becomes `"&lt;"`.
## Signature

View File

@ -1,6 +1,6 @@
# unescape
The inverse of [`escape`](./escape.md); this method converts the HTML entities `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `str` to their corresponding characters.
Converts the HTML entities `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `str` to their corresponding characters. It is the inverse of [`escape`](./escape.md).
## Signature

View File

@ -1,6 +1,7 @@
# escape
`str` 中的 "&", "<", ">", '"', "'", 和 "`" 字符转换为 HTML 实体字符。
`str` 中的 "&", "<", ">", '"', "'", 和 "\`" 字符转换为 HTML 实体字符。例如,`"<"` 会被转换为 `"&lt;"`
## 签名

View File

@ -8,6 +8,7 @@ const htmlEscapes: Record<string, string> = {
/**
* Converts the characters "&", "<", ">", '"', and "'" in `str` to their corresponding HTML entities.
* For example, "<" becomes "&lt;".
*
* @param {string} str The string to escape.
* @returns {string} Returns the escaped string.

View File

@ -7,7 +7,8 @@ const htmlUnescapes: Record<string, string> = {
};
/**
* The inverse of `escape`. This method converts the HTML entities `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `str` to their corresponding characters.
* Converts the HTML entities `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `str` to their corresponding characters.
* It is the inverse of `escape`.
*
* @param {string} str The string to unescape.
* @returns {string} Returns the unescaped string.