Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Translate standard UUIDs into shorter formats and back.

License

NotificationsYou must be signed in to change notification settings

oculus42/short-uuid

Repository files navigation

npmCode ClimateTest Coverage

Generate and translate standard UUIDs into shorter - or justdifferent - formats and back.

v5.2.0

5.2.0 addsvalidate method to check short IDs. Requested by@U-4-E-A5.1.0 adds translation support for theuuid25 (Base36) formatwith theuuid25Base36 constant.

Major Changes in 5.0.0

  • 🛑 5.0.0 drops support for Node 10 and 12.

Quick Start

constshort=require('short-uuid');// Quick start with flickrBase58 formatshort.generate();// '73WakrfVbNJBaAmhQtEeDv'

Details

short-uuid starts with RFC4122 v4-compliant UUIDs and translates theminto other, usually shorter formats. It also provides translatorsto convert back and forth from RFC compliant UUIDs to the shorter formats,and validate the IDs.

As of 4.0.0, formats return consistent-length values unless specifically requested.This is done by padding the start with the first ([0]) character in the alphabet.Previous versions can translate padded formats back to UUID.

constshort=require('short-uuid');// Generate a flickrBase58 short ID from without creating a translatorconstshortId=short.generate();consttranslator=short();// Defaults to flickrBase58constdecimalTranslator=short("0123456789");// Provide a specific alphabet for translationconstcookieTranslator=short(short.constants.cookieBase90);// Use a constant for translation// Generate a shortened v4 UUIDtranslator.new();// mhvXdrZT4jP5T8vBxuvm75translator.generate();// An alias for new.// Translate UUIDs to and from the shortened formattranslator.toUUID(shortId);// a44521d0-0fb8-4ade-8002-3385545c3318translator.fromUUID(regularUUID);// mhvXdrZT4jP5T8vBxuvm75// Check if a string is a valid ID (length and alphabet)translator.validate(shortId);// true// Check if a string is valid *AND* translates to a valid UUIDtranslator.validate(shortId,true);// truetranslator.validate('0000000000000000000000',true)// false// See the alphabet used by a translatortranslator.alphabet;// The maximum length a translated uuid will be with its alphabet.// if consistentLength is set (on by default), so ids will be this length.translator.maxLength;// View the constantsshort.constants.cookieBase90;// Safe for HTTP cookies values for smaller IDs.short.constants.flickrBase58;// Avoids similar characters (0/O, 1/I/l, etc.)short.constants.uuid25Base36;// The uuid25 (string length 25) format// Generate plain UUIDs// - From the library without creating a translatorshort.uuid();// fd5c084c-ff7c-4651-9a52-37096242d81c// - Each translator provides the uuid.v4() function, tootranslator.uuid();// 3023b0f5-ec55-4e75-9cd8-104700698052

Options

short-uuid 4.0.0 added support for options when creating a translator.This may support additional configuration in the future.

constshort=require('short-uuid');// By default shortened values are now padded for consistent length.// If you want to produce variable lengths, like in 3.1.1consttranslator=short(short.constants.flickrBase58,{consistentLength:false,});// Generate a shortened v4 UUIDtranslator.new();// mhvXdrZT4jP5T8vBxuvm75
  • consistentLength - Controls padding on shortened values. Default istrue.

Support

short-uuid5.xand later is tested on Node 14.x and later.

short-uuid4.xwas tested on Node 8.x to 18.x

short-uuid3.xand lower was confirmed to work on Node 6.x to 12.x,and offered a precompiled browser library proposedbyvoronianski.

Notes

short-uuid provides RFC4122 v4-compliant UUIDs,thanks touuid.

TypeScript definitions are included, thanks toalexturek.

Previous Release Note Highlights

5.0.0 drops support for Node 12 and below.4.1.0 adds a maxLength value to translators for reference4.0.1 adds consistent length translation and throws an error if provided an invalid alphabet.3.1.1 removed Node 4.x tests. Last included Browserify distribution.2.3.4 corrects the behavior for UUIDs with uppercase letters. Last version to build on Node 0.x.

Please seeRevisions for information on previous versions.

About

Translate standard UUIDs into shorter formats and back.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors9


[8]ページ先頭

©2009-2025 Movatter.jp