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

パッケージ詳細v0.1.2

shortid

ShortId は短く、順序付けされていない、URLに適した一意のIDを作成します。URL短縮サービスやMongoDB、RedisのIDなどに最適です。(JSからの移植)

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
24万
いいね数
21
Pub ポイント
150

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

flutter pub add shortid

パッケージ概要

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

ShortId は、URL ショートナー、MongoDB や Redis などのデータベース、およびコンパクトで安全な ID を必要とするその他のシステムに適した、短く、非連続的で URL 友好的な一意の識別子を生成します。人気のある JavaScript ライブラリの Dart 版として設計されており、一意性を保証し、予測可能なパターンを回避します。このパッケージは軽量で、すべての主要プラットフォームと互換性があり、連続的または長い識別子に依存せずに信頼できる ID の生成が必要なクロスプラットフォームアプリケーションに適しています。

用途

  • URL短縮サービス
  • データベースのプライマリキー
  • セッショントークンの生成
  • キャッシュキーの作成
  • セキュアな識別子の生成

主な機能

  • 短いランダム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);

カテゴリー

ソースリポジトリ

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