Code Monkey home page Code Monkey logo

short-unique-id's Introduction

Short Unique ID Generator

With ES6 imports, Node.js, and browser support

This is a straight up manual transpilation to ES6 of the short-uid npm package by Ankit Kuwadekar.

Why?

The above linked repository has gone stale, no updates in the past 3 years (as of updating this README).

If used in a ES6 environment it fails to follow good import standards.

Even so, the functionality is still useful. So here we are.

Instantiation (Server-side)

Install using npm:

npm install --save short-unique-id

ES6:

// Import
import ShortUniqueId from 'short-unique-id';

// Instantiate
const uid = new ShortUniqueId();

Node.js:

// Import
var ShortUniqueId = require('short-unique-id');

// Instantiate
var uid = new ShortUniqueId();

Instantiation (Client-side)

Browser:

<!-- Import -->
<script src="https://rawgit.com/jeanlescure/short-unique-id/master/dist/short-unique-id.min.js"></script>

<!-- Instantiate -->
<script>
  var uid = new ShortUniqueId();
</script>

Usage

Once instantiated you can use one of two functions:

// Generate Random Unique ID of a specific length
uid.randomUUID(6); // zUvMF8
uid.randomUUID(8); // 4308OPWZ
uid.randomUUID(13); // o0Sf6rfoPOrz5

// Generate Sequential Unique ID based on internal dictionary and counter
uid.sequentialUUID(); // v
uid.sequentialUUID(); // 0
uid.sequentialUUID(); // Y

Development

Tests run using Jasmine:

npm test

This will update the short-unique-id.js file under ./lib, which will then be imported by the spec and tested.

Find lint using airbnb for eslint:

npm run lint

Build

In order to publish the latest changes you must build the distribution files:

npm run build

This will update the short-unique-id.js file under ./lib, which will then be minified as the short-unique-id.min.js file under the ./dist directory.

short-unique-id's People

Contributors

jeanlescure avatar jeffturcotte avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.