패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.2.0

change_case

camelCase, PascalCase, Capital Case, snake_case, param-case, CONSTANT_CASE 및 기타 누락된 메서드를 위한 String 확장.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
18.1만
좋아요
71
Pub 점수
160

패키지 설치

flutter pub add change_case

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

change_case 패키지는 Dart의 String 클래스에 camelCase, PascalCase, snake_case, param-case, CONSTANT_CASE 등의 다양한 케이스 형식 간에 텍스트를 변환할 수 있는 편리한 메서드를 추가합니다. API 응답 포맷팅, 동적 식별자 생성, 코드베이스 전반에서 일관된 이름 규칙 유지와 같은 앱 개발에서 자주 필요한 문자열 변환 작업을 단순화합니다. 이 패키지는 가볍고 모든 주요 플랫폼을 지원하므로, 강력한 텍스트 조작 기능이 필요한 크로스플랫폼 플러터 애플리케이션에 이상적입니다.

사용 사례

  • API 응답 키 형식 지정
  • 일관된 변수 이름 생성
  • 사용자 입력을 표준 형식으로 변환하기
  • URL 친화적인 문자열 만들기
  • 구성 키 이름 처리
  • 코드 생성 워크플로우 간소화

주요 기능

  • String에 변환 메서드를 확장합니다
  • 다양한 대소문자 형식을 지원합니다
  • 경량이며 통합이 쉬움
  • 크로스 플랫폼 호환성
  • 외부 종속성 없음
  • 깨끗하고 읽기 쉬운 구문

적합한 대상

  • 문자열 포맷팅이 필요한 플러터 개발자
  • 엄격한 이름 지정 규칙을 가진 프로젝트
  • API 데이터 처리 파이프라인
  • 코드 생성 도구
  • URL 또는 식별자 정규화가 필요한 앱

고려 사항

  • 복잡한 언어 규칙을 처리하지 않습니다
  • 사전 정의된 대소문자 패턴에 한정됨
  • 고급 텍스트 처리에 적합하지 않습니다
  • 경계 사례에 대한 수동 처리가 필요합니다
  • 잘못된 입력에 대한 내장 검증 없음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Change Case

style: very good analysis License: MIT codecov style: effective dart

Transform a string between camelCase, PascalCase, Capital Case, snake_case, param-case, CONSTANT_CASE and others.


Core

These functions come with package:change_case

toCamelCase

Transform into a string with the separator denoted by the next word capitalized.

'test string'.toCamelCase(); // 'testString'
toCapitalCase

Transform into a space separated string with each word capitalized.

'test string'.toCapitalCase(); // 'Test String'
toConstantCase

Transform into upper case string with an underscore between words.

'test string'.toConstantCase(); // 'TEST_STRING'
toDotCase

Transform into a lower case string with a period between words.

'test string'.toDotCase(); // 'test.string'
toHeaderCase

Transform into a dash separated string of capitalized words.

'test string'.toHeaderCase(); // 'Test-String'
toNoCase

Transform into a lower cased string with spaces between words.

'testString'.toNoCase(); // 'test string'
toParamCase

Transform into a lower cased string with dashes between words.

'test string'.toParamCase(); // 'test-string'
toPascalCase

Transform into a string of capitalized words without separators.

'test string'.toPascalCase(); // 'TestString'
toPathCase

Transform into a lower case string with slashes between words.

'test string'.toPathCase(); // 'test/string'

// provide a separator override default '/'
'test string'.toPathCase(r'\'); // 'test\string'

toSentenceCase

Transform into a lower case with spaces between words, then capitalize the string.

'testString'.toSentenceCase(); // 'Test string'
toSnakeCase

Transform into a lower case string with underscores between words.

'test string'.toSnakeCase(); // 'test_string'

Other Case Utilities

toTitleCase

Transform a string into title case following English rules.

'a simple test'.toTitleCase(); // 'A Simple Test'
toSwapCase

Transform a string by swapping every character from upper to lower case, or lower to upper case.

'Test String'.toSwapCase(); // 'tEST sTRING'
isLowerCase

Returns true if the string is lower case only.

'test string'.isLowerCase(); // true
isUpperCase

Returns true if the string is upper case only.

'test string'.isUpperCase(); // false
toLowerFirstCase

Transforms the string with the first character in lower cased.

'TEST'.toLowerFirstCase(); // 'tEST'
toUpperFirstCase

Transforms the string with the first character in upper cased.

'test'.toUpperFirstCase(); // 'Test'
toSpongeCase

Transform into a string with random capitalization applied.

'Test String'.toSpongeCase(); // 'tEst stRINg'

Configuration

package:change_case has a configuration file, ChangeCaseConfig, that you can use to update splitPatterns, stripPatterns, and the placeholder which will be applied to most function listed above.

I don't suggest changing these unless you know what you are doing 😁

Patterns

Change case uses RegExp to split & replace characters of the string. While they are great at what they do, you may want to update or add new patterns.

These patterns can be updated by using the ChangeCaseConfig.setUp(splitPatterns: [...], stripPatterns: [...])

The default patterns are:

Note: (?:•)* is used to match any "•" (placeholder) character.

  • Split

    • ChangeCaseConfig.lowerOrNumToUpperPattern

      // matches lowercase or numeric char to uppercase char
      RegExp('([a-z0-9])(?:•)*([A-Z])')
      
    • ChangeCaseConfig.lowerOrNumToUpperPattern

      // matches uppercase char to uppercase followed by lowercase char
      RegExp('([A-Z])(?:•)*([A-Z][a-z])')
      
  • Strip

    • ChangeCaseConfig.upperToLowerPattern

      // matches any non-alphanumeric char
      RegExp('[^A-Z0-9]+', caseSensitive: false)
      
    • ChangeCaseConfig.lowerToNumOrUpperPattern (Not included in default, but can be used to add or replace)

      // matches lowercase char to numeric or uppercase char
      // changes the behavior to `word2019 -> word 2019` and `minifyURLs -> minify urls`
      RegExp('([a-z])([A-Z0-9])')
      

Placeholder

can be configured with ChangeCaseConfig.setUp(placeholder: ...)

The placeholder is a string that is added and used as a reference to configure each case.

The default placeholder is "•"

For example:

final string = 'test stringCase';
print(string.toCamelCase()); // expected: 'testStringCase'

// runs splitPatterns, returns "test string•Case"
// runs stripPatterns, returns "test•string•Case"
// runs camel case logic, returns "testStringCase"

This string needs to be a unique character that is not used in the string.

Related

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트