docs(repeat): Add docs for repeat

This commit is contained in:
raon0211 2024-09-03 23:45:19 +09:00
parent 0bb144588e
commit 2dab51b468
7 changed files with 77 additions and 5 deletions

View File

@ -229,6 +229,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'escape', link: '/reference/string/escape' },
{ text: 'unescape', link: '/reference/string/unescape' },
{ text: 'pad', link: '/reference/string/pad' },
{ text: 'repeat (compat)', link: '/reference/compat/string/pad' },
],
},
{

View File

@ -223,6 +223,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'padEnd (compat)', link: '/ja/reference/compat/string/padEnd' },
{ text: 'deburr', link: '/ja/reference/string/deburr' },
{ text: 'pad', link: '/ja/reference/string/pad' },
{ text: 'repeat (compat)', link: '/ja/reference/compat/string/pad' },
],
},
{

View File

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

View File

@ -226,6 +226,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'escape', link: '/zh_hans/reference/string/escape' },
{ text: 'unescape', link: '/zh_hans/reference/string/unescape' },
{ text: 'pad', link: '/zh_hans/reference/string/pad' },
{ text: 'repeat (兼容性)', link: '/zh_hans/reference/compat/string/repeat' },
],
},
{

View File

@ -0,0 +1,33 @@
# repeat
::: info
この関数は互換性のために `es-toolkit/compat` からのみインポートできます。代替可能なネイティブ JavaScript API があるか、まだ十分に最適化されていないためです。
`es-toolkit/compat` からこの関数をインポートすると、[lodash と完全に同じように動作](../../../compatibility.md)します。
:::
指定された回数だけ、与えられた文字列を繰り返して返します。
文字列が空であるか、カウントが0の場合、空の文字列を返します。
## インターフェース
```typescript
function repeat(str: string, n: number): string
```
### パラメータ
- `str` (`string`): 繰り返す文字列。
- `n` (`number`): 繰り返したい回数。
### 戻り値
(`string`): `n`回繰り返された文字列。
## Examples
```javascript
repeat('abc', 0); // ''
repeat('abc', 2); // 'abcabc'
```

View File

@ -6,9 +6,9 @@ This function is only available in `es-toolkit/compat` for compatibility reasons
When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md).
:::
It returns the given string repeated a specified number of times.
Returns the given string repeated a specified number of times.
If the string is empty or the count is 0, it returns an empty string.
If the string is empty or the count is `0`, it returns an empty string.
## Signature
@ -16,14 +16,15 @@ If the string is empty or the count is 0, it returns an empty string.
```typescript
function repeat(str: string, n: number): string
```
## Parameters
### Parameters
- `str` (`string`): The string to repeat.
- `n` (`number`): The number of times you want to repeat.
## Returns
### Returns
The string repeated for the nth time.
(`string`): The string repeated for the nth time.
## Examples

View File

@ -0,0 +1,34 @@
# repeat
::: info
出于兼容性原因,此函数仅在 `es-toolkit/compat` 中提供。它可能具有替代的原生 JavaScript API或者尚未完全优化。
`es-toolkit/compat` 导入时,它的行为与 lodash 完全一致,并提供相同的功能,详情请见 [这里](../../../compatibility.md)。
:::
返回给定字符串重复指定次数后的结果。
如果字符串为空或次数为 0则返回空字符串。
## 签名
```typescript
function repeat(str: string, n: number): string
```
### 参数
- `str` (`string`): 要重复的字符串。
- `n` (`number`): 要重复的次数。
### 返回值
(`string`): 被重复 `n` 次后的字符串。
## 示例
```javascript
repeat('abc', 0); // ''
repeat('abc', 2); // 'abcabc'
```