搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

slugify

將字串轉換為 slug。適用於 URL、檔名、ID 等。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
8.6萬
喜歡數
50
Pub 分數
135

安裝套件

flutter pub add slugify

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Dart 套件,透過移除特殊字元、空白與重音符號,將字串轉換為 URL 友好的斜線格式,並進行標準化處理。非常適合用於產生 URL、檔案名稱、資料庫 ID 等情境下的乾淨識別碼。此套件支援 Android、iOS、Web、macOS、Windows 與 Linux 多個平台,確保跨環境行為一致。輕量級且可透過 Flutter 的 pub 套件管理器輕鬆整合。

適用情境

  • 產生SEO友好的URL
  • 從標題建立檔名
  • 產生唯一 ID
  • 標準化使用者輸入
  • 構建導航路徑
  • 簡化資料儲存鍵

主要特色

  • 移除特殊字元和重音符號
  • 將空格轉換為連字符
  • 支援國際字元
  • 大小寫規範化
  • 可擴展的自訂選項
  • 跨平台相容性

適合對象

  • Web 與行動應用程式開發人員
  • 內容管理系統
  • 靜態網站產生器
  • API 後端服務
  • 面向使用者的表單輸入
  • 資料處理管道

使用建議

  • 可能需要手動處理重複項
  • 它本身無法保證唯一性
  • 僅限字串轉換
  • 除了轉義之外,沒有內建的清理功能
  • 依賴外部庫以實現進階功能
  • 不適合用於加密雜湊

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

slugify

Converts any String to a slug. Useful for URLs, filenames, IDs, and more.

Features

  • Multi-language support
  • Removes unfriendly characters
  • Approximates replacements for characters not in the Latin alphabet
  • Configurable options
  • Null safe with Dart 2.12

Usage

import 'package:slugify/slugify.dart';

// Use with default options.
var slug = slugify('Hello, World! Foo Bar');
print(slug); // hello-world-foo-bar

// Use with custom options.
var slug2 = slugify('Hello, World! Foo Bar', lowercase: false, delimiter: '🙂');
print(slug2) // Hello🙂World🙂Foo🙂Bar
Options
Name Type Default Description
delimiter String "-" Separator between words
lowercase bool true Convert text to lowercase

所屬分類

原始碼儲存庫

使用此套件的專案