1.0.0 • Published 2 months ago

demo5129 v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

��# gen-unique-ids

gen-unique-ids is a JavaScript utility for generating unique IDs with customizable options. It provides a simple way to create random IDs with varying lengths, including capital letters, small letters, numbers, and symbols.

Installation

import { genUniqueId } from "https://cdn.jsdelivr.net/gh/webdeveloper-sandeep/repository-version-control/gen-unique-ids/version@1.0.3.js";

!WARNING
Must include type="module" in script tag

<script src="script.js" type="module"></script>

2) You can install gen-unique-ids via npm:

install in terminal

npm i gen-unique-ids

use in file

const genUniqueId = require("gen-unique-ids");

how to use

  • if you just call the function

code

genUniqueId();

result

dTe2hJRBK2F1A8ampXJY; //A unique ID of length 20 every time
  • You can pass the length of the ID.

code

genUniqueId(12);
genUniqueId(5);

result

gGUdd272Oq3Y; //A unique ID of length 12 every time
mG3Fg; //A unique ID of length 5 every time
  • You can customize letter symbols and numbers in id by sending an object as an argument

code

const data = {
  length: 14, // Pass the length; by default, it is 20
  symbol: true, // Do you want to add symbols to the unique ID?
  lowercase: true, // Do you want to add lowercase letter to the unique ID?
  uppercase: true, // Do you want to add uppercase letter to the unique ID?
  number: true, // Do you want to add number to the unique ID?
};

genUniqueId(data);

result

2BOE@3fIfWp0u& // Generate a unique ID of length 14 each time, which includes lowercase letters, uppercase letters, numbers, and symbols
  • Create unique IDs like this: 0776UEeE-2442-8Y30-3585-GB4uo8nH

code

const data = {
  length: [8, 4, 4, 4, 8], // you can customise it
};

genUniqueId(data);

result

0776UEeE-2442-8Y30-3585-GB4uo8nH
  • Create unique IDs like this fh03j86h {customSeparator} PchR {customSeparator} TR6qgtkI using custom separator

code

const data = {
  length: [8, 4, 8],
  separate: "+", // By default, it is '-',
};

genUniqueId(data);

result

fh03j86h + PchR + TR6qgtkI;
  • Generate random ID with custom symbols

code

const data = {
  length: 13,
  symbol: "!@#", // If you set it to true by default, it becomes '!@#$%&'
};

genUniqueId(data);

result

u45D@T8N2#Ox4
  • Create unique IDs like this:
    24132-eizspf-7iA (num)-(lowercase)-(any)

code

const data = {
  length: [5, "number", 6, "lowercase", 3], // first 5 digits are only number next 6 digits are only lowercase and last 3 digits can be number , lowercase and uppercase
};

genUniqueId(data);

result

24132-eizspf-77A

!TIP "number" --- for Number "uppercase" --- for Uppercase letter "lowercase" --- for Lowercase letter "letter" --- for both uppercase and lowercase "symbol" --- for symbols

#creater

React Unique IDS

React Unique IDS is a handy tool for React developers. It helps create special IDs for elements in your React apps. You can customize these IDs to suit your needs easily. It's great for managing IDs within React components, making your development process smoother

Installation & Usage

  • To install and set up the library, run:

    npm install react-unique-id
  • import the library

    import reactUniqueId from "react-unique-id";
  • Use it
    reactUniqueId();

Customization

  • To generate a unique ID, simply call the function:

    reactUniqueId();

    Output: A unique ID is generated with a length of 20 characters, containing uppercase letters, lowercase letters, numbers, and symbols.

    "bmYZWC*9DuLNxB@zcd5m";
  • To specify the length of the ID, pass the desired length as an argument:

    reactUniqueId(15);

    Output: A unique ID is generated with a length of 15 characters, containing uppercase letters, lowercase letters, numbers, and symbols.

    "NF7&4q#9F@pJH4o";
  • You can customize the character requirements by passing an object:

    const data = {
      length: 10,
      uppercase: true, // true if you need uppercase letters in the unique ID
      lowercase: false, // true if you need lowercase letters in the unique ID
      symbol: false, // true if you need symbol letters in the unique ID
      number: true, // true if you need number letters in the unique ID
    };
    
    reactUniqueId(data);

    OR

    const data = {
      length: 10,
      lowercase: false, // true if you need lowercase letters in the unique ID
      symbol: false, // true if you need symbol letters in the unique ID
    };
    
    reactUniqueId(data);

    Output: A unique ID is generated based on your customization/requirement.

    "BFU03WETS56B59U";

    !NOTE
    By default, all types are true.

    • To generate an ID of the format 23573527-aT2s%JR6@-YWDBSCYE, you can use the following configuration:

      const data = {
        length: [8, "number", 9, 8, "uppercase"],
        separater: "-",
      };
      
      reactUniqueId(data);

      Output: A unique ID is generated where the first 8 characters are numbers, the next 9 characters can be any type, and the last 8 characters are in uppercase. They are separated using a separator.

      "72324118-71*xW4fHC-ANTITOWI";
1.0.0

2 months ago