Giter Site home page Giter Site logo

eru123 / usid Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 21 KB

Yet another Short and Unique ID Generator. Random ID, UUID, UID and SID Generator.

License: Apache License 2.0

JavaScript 44.98% TypeScript 55.02%
uuid id uid sid short unique unique-id short-id

usid's Introduction

usid

Create random, unique or index based ID

Installation on Nodejs

# NPM
npm i usid

# Yarn
yarn add usid

Usage

Initialization with TypeScript Deno

import {
    uid,
    createIndex, 
    DEFAULT_CHARSET,
    rand
} from "https://deno.land/x/usid/mod.ts";

Initialization with Nodejs

const {
    uid,
    createIndex, 
    DEFAULT_CHARSET,
    rand
} = require('usid');

Index based ID

// imagine that x is a database connector
let x = 0;

const options = {
    get: () => x,
    set: (value) => x = value,
    charset: DEFAULT_CHARSET, // optional,
    min: 3, // optional, default is 0
}

const getID = createIndex(options);
for (let i = 0; i < 3; i++) console.log(getID());

// Output:
// aab
// aac
// aad

Random ID

Generate random ID with fixed length

const len = 5; // optional, default is 3
console.log(rand(len, DEFAULT_CHARSET)); // default charset is optional
// Output: random 5 characters based on DEFAULT_CHARSET

Unique ID

Generate unique ID with fixed length

const output_length = 24; // optional, default is 24
const base_decimal_length = 18; // optional, default is 18

console.log(uid(output_length, base_decimal_length, DEFAULT_CHARSET)); // default charset is optional
// Output: outputs 24 characters based on DEFAULT_CHARSET

LICENSE

Apache-2.0@eru123

usid's People

Contributors

eru123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.