str-extract-count-keyword()

카운트, 키워드 추출 유틸리티 함수

용도

키워드와 카운트 횟수를 포함하는 문자를 분석해 카운트, 키워드를 맵으로 반환 받아야 할 경우 사용합니다.

예시 : "header x3" → (count: 3, keyword: "header")

사용법

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

str-extract-count-keyword($text:string) → map

@debug str-extract-count-keyword("main x3"); // (count: 3, keyword: 'main') 반환

매개변수(parameter)

유형(type)

필수(required)

기본 값(default)

$text

string

✔︎

로직

str-extract-count-keyword() 유틸리티는 다음의 로직에 의해 작성되었습니다.

@function str-extract-count-keyword($text: null) {
  $index: str-index($text, 'x');

  @if $index {
    $keyword: str-replace(str-slice($text, 1, $index - 1), ' ');
    $count: str-slice($text, $index + 1);
    @return (count: str-to-num($count), keyword: $keyword);
  } @else {
    @return $text;
  }
}
  1. 전달 받은 인자 값에서 x 값의 인덱스 추출

  2. 인덱스 값이 존재할 경우, 키워드 및 카운트 값을 추출해 맵으로 반환

  3. 인덱스 값이 존재하지 않을 경우, 전달 받은 텍스트 그대로 반환

참고

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

유틸리티 함수 로직에 사용된 자체 제작 모듈은 다음과 같습니다.

Last updated