Git Product home page Git Product logo

uq-id's Introduction

uq-id

npm bundle size npm

A lightweight random id generator

Install

npm i uq-id

Usage

const {
  shortId,
  epochId,
  complexId,
  generateId,
  uniqueIdFactory,
} = require("uq-id");

// generate a short id, kept simple
// params
// size: int, max allowed is 10
shortId();
output: "yr7k6";

// generate a custom id based on input size and chartset (url friendly by default)
// params
// size - int, default 10
// charset - string of characters, defaults to a...z,A...Z,0...9
generateId();
output: "aSzxMCbOo6v";

// generate uniqueId, history of ids is maintained in memory (closure)
// params
// retryLimit - int, default 5
// returns a generateId function with uniqueness wrapper
const genUniqueId = uniqueIdFactory();
// this function has the same interface as generateId above
// returns null if a random id could not be generated within retry limit
genUniqueId();
output: "dVGsGQLNVQ";

// generate a complex id (not url friendly)
// chartset containts a...z,A...Z,0...9 and symbols
// params
// size - int, default 10
complexId();
output: "q5yTPo&oPUd";

// generate an epoch based id, using epoch + short id
// params
// size: int, default 5, max allowed is 10
// (indicates size of tailend string and not the output)
epochId();
output: "1587843550015-dxp6r";

// custom use cases
// generate an otp like id
generateId(4, "0123456789");
output: "6776";

That's all folks.

uq-id's People

Contributors

kailash-sankar avatar

Watchers

James Cloos avatar  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.