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

パッケージ詳細v1.2.2

stringr

Dart用の包括的な文字列操作プラグイン。ラテン語、非ラテン語、およびグラフェムクラスターを問わず操作に対応しています!VocaJsからインスパイアされた機能

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
7.3万
いいね数
20
Pub ポイント
160

パッケージをインストール

flutter pub add stringr

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Stringr は、ラテン語、非ラテン語、およびグラフィームクラスターの処理を正確にサポートする、高度な文字列操作向けの包括的なDartパッケージです。Voca.jsからインスパイアされ、さまざまなスクリプトでのテキスト変換および分析に適した豊富なメソッドを提供します。国際化アプリケーションで堅牢な文字列操作が必要な場合に最適であり、複雑なUnicode文字の正確な処理を保証します。このパッケージは、すべての主要プラットフォームにおけるFlutterアプリにシームレスに統合できます。

用途

  • 国際化テキスト処理
  • テキストの正規化とクリーニング
  • 文字列変換ユーティリティ
  • 多言語コンテンツの取り扱い
  • データ検証およびサニタイズ
  • グラフィームクラスター対応操作

主な機能

  • ラテン語および非ラテン文字のスクリプト対応
  • グラフェムクラスターの認識
  • Voca.js を参考にした API デザイン
  • クロスプラットフォーム互換性
  • Unicode対応の文字列操作
  • テキスト操作のための広範なメソッドセット

適している対象

  • 多言語対応を必要とするアプリ
  • 堅牢な文字列ツールが必要な開発者
  • テキスト解析を含むプロジェクト
  • グローバルなオーディエンスをターゲットにするFlutterアプリ
  • Unicodeを多く含むデータを使用するチーム

注意事項

  • 簡単な文字列タスクにオーバーヘッドを追加する可能性があります
  • Unicode およびグラフムの理解が必要です
  • 基本的な使用方法以外のドキュメントは限られている
  • 高性能なバッチ処理向けに最適化されていません
  • 中程度から複雑な文字列のニーズに最適

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

stringr

pub package codecov License: MIT

A comprehensive string manipulation library for Dart and Flutter. Inspired by VocaJS, stringr provides powerful string operations that work seamlessly with Latin, non-Latin, and Unicode strings.

Features

  • Case Conversion - camelCase, snake_case, kebab-case, Title Case, PascalCase
  • Unicode Support - Full support for non-Latin scripts, diacritics, and grapheme clusters
  • Smart Word Detection - Uses regex patterns instead of simple whitespace splitting
  • Null Safety - Fully null-safe and compatible with Dart 3.0+
  • Zero Dependencies - Only depends on the characters package for grapheme support

Installation

Add to your pubspec.yaml:

dependencies:
  stringr: ^1.2.0

Quick Start

import 'package:stringr/stringr.dart';

void main() {
  // Case conversions
  print('hello world'.toCamelCase);        // helloWorld
  print('hello world'.toSnakeCase);        // hello_world
  print('hello world'.toKebabCase);        // hello-world
  print('hello world'.toPascalCase);       // HelloWorld

  // Smart word extraction
  print('XMLHttpRequest'.camelCase());     // xmlHttpRequest
  print('/path/to/file'.camelCase());      // pathToFile
  print('2infinity&beyond'.words());       // [2, infinity, beyond]
}

Unicode & Non-Latin Support

stringr shines with complex Unicode strings:

// Non-Latin scripts
print('полет птицы'.kebabCase());          // полет-птицы
print('La variété française'.prune(12));   // La variété

// Diacritics and latinization
print('café'.latinize());                  // cafe
print('anglikonų šiurkščios'.latinize());  // anglikonu siurkscios

// Grapheme-aware operations
print('café'.countGrapheme());             // 4 (not 5!)
print('👨‍👩‍👧‍👦'.reverse());                      // 👨‍👩‍👧‍👦 (family emoji stays intact)

API Overview

Case Manipulation
Method Description Example
camelCase() Convert to camelCase 'foo bar' → 'fooBar'
snakeCase() Convert to snake_case 'foo bar' → 'foo_bar'
kebabCase() Convert to kebab-case 'foo bar' → 'foo-bar'
titleCase() Capitalize each word 'foo bar' → 'Foo Bar'
capitalize() Capitalize first char 'foo' → 'Foo'
swapCase() Toggle case 'FoO' → 'fOo'
String Chopping
Method Description Example
truncate(n) Truncate to n chars 'hello world' → 'hello...'
prune(n) Truncate without breaking words 'hello world' → 'hello'
first(n) Get first n chars 'hello' → 'hel'
last(n) Get last n chars 'hello' → 'llo'
slice(start, end) Extract substring 'hello' → 'ell'
Counting
Method Description Example
countGrapheme() Count visible characters 'café' → 4
countOccurrences(s) Count substring occurrences 'banana'.countOccurrences('a') → 3
countWords() Count words 'hello world' → 2
countWhere(fn) Count matching chars Custom predicate
Manipulation
Method Description Example
reverse() Reverse (grapheme-aware) 'hello' → 'olleh'
slugify() URL-friendly slug 'Hello World!' → 'hello-world'
latinize() Remove diacritics 'café' → 'cafe'
insert(s, i) Insert at position 'hllo'.insert('e', 1) → 'hello'
Escaping
Method Description
escapeHtml() Escape HTML entities
unescapeHtml() Unescape HTML entities
escapeRegExp() Escape regex special chars

Why stringr?

Most string libraries fail with complex Unicode. stringr handles:

  • Grapheme clusters: 'café' is 4 characters, not 5
  • Surrogate pairs: Emoji and special symbols work correctly
  • Non-Latin scripts: Cyrillic, Greek, accented Latin, and more
  • Smart word detection: 'XMLHttpRequest' → ['XML', 'Http', 'Request']

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

Project Health

License

MIT License - see LICENSE for details.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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

ランキング