パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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 応答のフォーマット、動的識別子の生成、コードベース全体での一貫した命名規則の維持など、アプリ開発でよく必要な文字列変換タスクを簡素化します。このパッケージは軽量で、すべての主要プラットフォームをサポートしており、強力なテキスト操作が必要なクロスプラットフォームの Flutter アプリに最適です。

用途

  • API応答キーのフォーマット
  • 一貫した変数名の生成
  • ユーザー入力を標準化された形式に変換する
  • URLに適した文字列を作成する
  • 構成キー名の取り扱い
  • コード生成ワークフローの簡素化

主な機能

  • String に変換メソッドを拡張します
  • 複数のキャメルケース形式に対応しています
  • 軽量で統合が簡単
  • クロスプラットフォーム互換性
  • 外部の依存関係なし
  • 洗練された、読みやすい構文

適している対象

  • 文字列フォーマットが必要なFlutter開発者
  • 厳格な命名規則を持つプロジェクト
  • 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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト