shorten-uuid

Shorten UUID to a string of length 24 witch applicable to the URL and WeChat QR code.

Usage no npm install needed!

<script type="module">
  import shortenUuid from 'https://cdn.skypack.dev/shorten-uuid';
</script>

README

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