2.0.2 • Published 10 months ago

unique-id-key v2.0.2

Weekly downloads
31
License
MIT
Repository
github
Last release
10 months ago

unique-id-key

A TypeScript module for generating unique random strings. The module provides methods to create numeric, alphabetic, or alphanumeric strings, and it can generate random API keys separated by a special character after every 4th character.

Installation

Install the package using npm:

npm install unique-id-key

Then, import the module in your project:

import { RandomString, RandomNum, AlphaNum, APIKEY, UUID } from 'unique-id-key';

Methods

RandomString(length: number, caseType?: "uppercase" | "lowercase")

Generates a random alphabetic string. You can specify the length of the string and optionally define if it should be uppercase or lowercase. If caseType is not provided, the result will include both uppercase and lowercase characters.

Parameters:

  • length: The length of the desired string (number).
  • caseType (optional): Specify "uppercase" for all uppercase letters or "lowercase" for all lowercase letters.

Example:

const any_randomString = RandomString(10);
console.log(any_randomString);
// Example output: "erRogWyRtr"

const uppercase_randomString = RandomString(8, "uppercase");
console.log(uppercase_randomString);
// Example output: "MNTVBSQW"

const lowercase_randomString = RandomString(11, "lowercase");
console.log(lowercase_randomString);
// Example output: "tqwicductda"

RandomNum(length: number)

Generates a random numeric string with the specified length.

Parameters:

  • length: The length of the numeric string (number).

Example:

const random_numeric = RandomNum(10);
console.log(random_numeric);
// Example output: "4836593648"

RandomAlphaNum(length: number)

Generates a random alphanumeric string with both letters (uppercase and lowercase) and numbers.

Parameters:

  • length: The length of the alphanumeric string (number).

Example:

const random_alphanum = RandomAlphaNum(10);
console.log(random_alphanum);
// Example output: "gp2WfI7ihd"

APIKEY(length: number, separator: string)

Generates a random API key with a specified length, and inserts a separator after every 4th character.

Parameters:

  • length: The total length of the API key (number).
  • separator: The character to insert after every 4th character (string).

Example:

const api_key_1 = APIKEY(16, "-");
console.log(api_key_1);
// Example output: "5TZS-JLG3-325O-1S5B"

const api_key_2 = APIKEY(12, ".");
console.log(api_key_2);
// Example output: "5hQw.tQ1l.yqgH"

UUID()

Generates a random UUID (Universally Unique Identifier).

Example:

const uuid = UUID();
console.log(uuid);
// Example output: "9f5b5672-9a34-4a6b-a52d-dcdfe1d33cb4"

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago