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

套件詳情v0.1.2

shortid

ShortId 建立短的、非順序的、URL 友好的唯一 ID。非常適合用於 URL 縮圖工具、MongoDB 和 Redis ID 等情境。(來自 JS 的移植)

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
24萬
喜歡數
21
Pub 分數
150

安裝套件

flutter pub add shortid

套件介紹

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

ShortId 產生短小、非順序且適合 URL 的唯一識別碼,非常適合用於 URL 縮寫工具、MongoDB 和 Redis 等資料庫,以及其它需要緊湊安全 ID 的系統。此套件是廣受歡迎的 JavaScript 庫的 Dart 版本,確保唯一性並避免可預測的模式。該套件輕量且相容所有主要平台,適用於需要可靠 ID 產生而不依賴順序或長識別碼的跨平台應用。

適用情境

  • 網址縮短服務
  • 資料庫主鍵
  • 會話令牌生成
  • 快取金鑰建立
  • 安全標識符生成

主要特色

  • 產生短隨機ID
  • URL安全字元
  • 非順序且不可預測
  • 跨平台支援
  • 輕巧且快速
  • JavaScript 庫的 Dart 版本

適合對象

  • 需要緊緻 ID 的 Web 和行動應用
  • 後端服務與資料庫整合
  • 需要安全且無法猜測的識別碼的應用程式
  • 使用 MongoDB 或 Redis 的項目
  • 熟悉 JavaScript ShortId 的開發者

使用建議

  • 不適合高安全性使用場景的加密安全
  • ID 在沒有額外檢查的情況下無法保證全域唯一
  • 取決於隨機數生成的品質
  • 限制為16個字元的預設長度
  • 無內建碰撞檢測

原始 README

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

ShortId creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Redis ids, and any other id users might see.

  • By default 7-14 url-friendly characters: A-Z, a-z, 0-9, _-
  • Supports custom seeds, custom alphabet.
  • Can generate any number of ids without duplicates, even millions per day.
  • Good replacement for Mongo ID/Mongoose ID.
  • Includes tests.

ShortId does not generate cryptographically secure ids, so don't rely on it to make IDs which are impossible to guess.

Usage
import 'package:shortid/shortid.dart';

print(shortid.generate());
// PPBqWA9

shortid.generate()

Returns string non-sequential unique id.

Example

users.insert({
  _id: shortid.generate(),
  name: '...',
  email: '...'
});

shortid.characters(string)

Default: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'

Returns new alphabet as a string

Recommendation: If you don't like _ or -, you can to set new characters to use.

Optional

Change the characters used.

You must provide a string of all 64 unique characters. Order is not important.

The default characters provided were selected because they are url safe.

Example

// use $ and @ instead of - and _
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@');
// any 64 unicode characters work, but I wouldn't recommend this.
shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');

shortid.seed(integer)

Default: 1

Recommendation: You typically won't want to change this.

Optional

Choose a unique value that will seed the random number generator so users won't be able to figure out the pattern of the unique ids. Call it just once in your application before using shortId and always use the same value in your application.

Most developers won't need to use this, it's mainly for testing ShortId.

If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.

Example

shortid.seed(1000);

所屬分類

原始碼儲存庫

使用此套件的專案