패키지, 저장소 및 앱 카테고리 검색

패키지 상세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가 필요한 웹 및 모바일 앱
  • 데이터베이스 통합을 갖춘 백엔드 서비스
  • 보안성 있고 추측할 수 없는 식별자가 필요한 응용 프로그램
  • 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);

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트