oculus42 / short-uuid

Translate standard UUIDs into shorter formats and back.
MIT License
450 stars 13 forks source link

Add typescript definition file #7

Closed alexturek closed 7 years ago

alexturek commented 7 years ago

Tested with this code (modified from the README example) and run in ts-node

import * as short from 'short-uuid';

const translator = short(); // Defaults to flickrBase58
const decimalTranslator = short("0123456789"); // Provide a specific alphabet for translation
const cookieTranslator = short(short.constants.cookieBase90); // Use a constant for translation

// Generate a shortened v4 UUID
const shortId = translator.new();
console.log(shortId);

// Generate plain UUIDs
short.uuid(); // From the constructor without creating a translator
const regularUUID = translator.uuid(); // Each translator provides the uuid.v4() function

console.log(regularUUID);

// Translate UUIDs
console.log(translator.toUUID(shortId));
console.log(translator.fromUUID(regularUUID));

// See the alphabet used by a translator
console.log(translator.alphabet)

// View the constants
console.log(short.constants.flickrBase58);
console.log(short.constants.cookieBase90);
aturek@aturek-mbpro ~/ts-test> ts-node test.ts
3VKVopMcKshJStybhFzXtb
a610f20d-f03f-45fc-982f-87763285188c
17b3c39a-3832-48be-901d-7354703994fc
mvo5eHmyYxRxH9E9R78tqY
123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+-./:<=>?@[]^_`{|}~
alexturek commented 7 years ago

@oculus42 gentle ping - is there anything I need to add to this PR to get it merged/released?

oculus42 commented 7 years ago

Hey @alexturek I saw the emails come through. You caught me during lunch this time. I would prefer shortUUID to shortUuid as the namespace, for consistency. Does that cause any problems for you?

alexturek commented 7 years ago

Oh, whoops! Yeah sorry, I thought I caught all my casing issues. I'll fix that right up

alexturek commented 7 years ago

@oculus42 Updated