# str-repeat()

## 용도 <a href="#use" id="use"></a>

문자를 특정 횟수만큼 반복해서 출력할 때 사용합니다.

## 사용법 <a href="#usage" id="usage"></a>

`str-repeat()` 함수에 반복할 숫자, 반복할 문자를 전달합니다.

> str-repeat($coun&#x74;**:number**, $tex&#x74;**:string**) → **string**

```javascript
@debug str-split(".img, .button", ","); // ".img" ".button" 반환
```

| 매개변수(parameter) | 유형(type) | 필수(required) | 기본 값(default) |
| :-------------: | :------: | :----------: | :-----------: |
|      $count     |  number  |      ✔︎      |               |
|      $text      |  string  |      ✔︎      |               |

## 로직 <a href="#logic" id="logic"></a>

`str-repeat()` 유틸리티는 다음의 로직에 의해 작성되었습니다.&#x20;

```javascript
@function str-repeat($count: null, $text: null) {
  // 전달 인자 유효성 검사
  @if type-of($count) != 'number' {
    @error 'str-repeat() 믹스인은 첫번째 인자로 숫자 값만 전달 받을 수 있습니다.';
  }
  @if type-of($text) != 'string' {
    @error 'str-repeat() 믹스인은 두번째 인자로 문자 값만 전달 받을 수 있습니다.';
  }

  // 반복 텍스트 변수
  $repeat-text: '';

  // 반복 횟수만큼 문자 반복 접합 처리
  @for $i from 1 through $count {
    $repeat-text: str-insert($repeat-text, '#{$text} ', 1);
  }

  // 끝 공백 제거
  @return str-slice($repeat-text, 1, -2);
}
```

1. 전달 받은 인자 값을 검사하여 요구되는 유형이 아닌 경우 오류 메시지 출력
2. 전달 받은 반복 횟수 만큼 전달 받은 텍스트를 반복해서 접합
3. 마지막 공백을 제거한 텍스트 반환

## 참고 <a href="#reference" id="reference"></a>

유틸리티 함수 로직에 사용된 Sass 빌트인 모듈은 다음과 같습니다.

* [@function](https://sass-lang.com/documentation/at-rules/function)
* [@if / @else](https://sass-lang.com/documentation/at-rules/control/if)
* [@error](https://sass-lang.com/documentation/at-rules/error)
* [@for](https://sass-lang.com/documentation/at-rules/control/for)
* [type-of()](https://sass-lang.com/documentation/modules/meta#type-of)
* [str-insert()](https://sass-lang.com/documentation/modules/string#insert)
* [str-slice()](https://sass-lang.com/documentation/modules/string#slice)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yamoo9.gitbook.io/scss-mixins/utilities/string/str-repeat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
