# str-to-num()

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

문자 값을 숫자 값으로 변경해야 할 때 사용합니다.

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

`str-to-num()` 함수에 변경할 숫자형 문자 값을 전달합니다.

> str-to-num($str-numbe&#x72;**:string**, $max-numbe&#x72;**:number**) → **number**

```javascript
@debug str-to-num('20'); // 20 반환
```

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

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

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

```javascript
@use 'sass:map';

@function str-to-num($str-number, $max-number: 100) {
  $numbers: ();

  @for $n from 1 through $max-number {
    $numbers: map.set($numbers, $n + '', $n);
  }

  @if map-has-key($numbers, $str-number) {
    @return map.get($numbers, $str-number);
  } @else {
    @error 'str-to-num() 함수는 #{$max-number} 이하의 숫자형 문자 값만 처리 가능합니다.';
  }
}
```

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)
* [map.set()](https://sass-lang.com/documentation/modules/map#set)
* [map.get()](https://sass-lang.com/documentation/modules/map#get)
* [map.has-key()](https://sass-lang.com/documentation/modules/map#has-key)


---

# 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-to-num.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.
