1.0.2 • Published 3 years ago

shorten-uuid v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

shorten-uuid

npm bundle size npm downloads license

github build coverage

Shorten UUID to a string of length 24.

The encoded character range is -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz.

The result is applicable to the URL and WeChat QR code.

Installation

NPM

npm install shorten-uuid
import shortenUuid from 'shorten-uuid';

Browser

Direct <script> include

<script src="https://cdn.jsdelivr.net/npm/shorten-uuid"></script>

Usage

const characters = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz' // default value
const { encode, decode } = shortenUuid(characters);

const uuid = '2358e803-12d4-4741-8432-63e9137bd39b';
const encoded = encode(uuid); // -> 1CNDV20AJ3S07Fm5Ed0CvCDQ
decode(encoded); // -> 2358e803-12d4-4741-8432-63e9137bd39b