npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

custom-random-id

v1.0.1

Published

A highly customizable JavaScript library that generates random IDs based on the required format. It uses the {{id_specification}} format to generate the kind of ID with varying length number or string or alpha-numeric string

Downloads

148

Readme

custom-random-id

A highly customizable JavaScript library that generates random IDs based on the required format. It uses the {{id_specification}} format to generate the kind of ID with varying length number or string or alpha-numeric string

Solves the problem of writing custom algorithms of generating random IDs of numbers or strings or alpha-numeric string. You can even generate a random phone number like +1-541-754-3010 or random anything in your desired format!

Installation

npm install custom-random-id

  • Small in size.
  • Fast. Better performance than most of the other ID generators.
  • URL safe characters. it uses only URL safe characters as it uses only numbers or capital letters or uuids to generate the IDs.
  • Client & Server. Can be used in client side and server side JavaScript applications.

Usage

const { IdGenerator } = require("custom-random-id");
// To generate a 5 digit random number
const ID = new IdGenerator("{{ number_5 }}");
let id = ID.getFinalExpression();
console.log(id); // => 56412

// To generate a 10 character random string
const ID = new IdGenerator("{{ string_10 }}");
let id = ID.getFinalExpression(); // => HYIOMNTRSJ

// To generate a 8 character random alpha numeric
const ID = new IdGenerator("{{ alpha_number_10 }}");
let id = ID.getFinalExpression(); // => JU78BH98

// To generate a uuid
const ID = new IdGenerator("{{ uuid }}");
let id = ID.getFinalExpression(); // => 5bc787b8-00ac-49ea-a970-2fca9ec737af

Format

Format: "{{ type_count }}" where type and count are 2 separate entities. The whole expression has to be provided in string format only. Eg: "{{ number_10 }}"

  • type

    • string: Generates a string of the specified length.
    • number: Generates a number (integer) of a specified length.
    • alpha_number: Generates an alpha-numeric string (string of numbers and characters in caps) of a specified length.
    • uuid: Generates an uuid.
  • count: An integer number for the number of digits/characters to be present in the generated string.

Examples:
"{{ string_10 }}";
// output: VVMTINCMBC
"{{ string_50 }}";
// output: OTXITFCVIPNFTIERWXPOURNUSMDOFPCAUHJBIVZFWPEQWTMMPW
"{{ string_1 }}";
// output: K
// Single random Char
"{{ number_15 }}";
// output: 234112942672429
"{{ number_1 }}";
// output: 4
// This can be used to get a single random number
"{{ alpha_number_10 }}";
// output: KHT5N52J36
// To get a string having upper case characters and integer numbers
"{{ alpha_number_10 }}";
// output: KHT5N52J36
// To get a string having upper case characters and integer numbers
"{{ uuid }}";
// output: 43a629cf-661b-4d4c-b66e-16e6714f8732
// To get an unique string every time.

Creative Usage

Unlock your creativity by using the custom-random-id generator to generate strings of any required format by using multiple expressions in a string.

Generate an American Phone number
"+1 {{number_3}}-{{number_3}}-{{number_4}}";
// output: +1 941-626-2929
Generate phone numbers starting with only '7'
"+1 7{{number_2}}-{{number_3}}-{{number_4}}";
// output: +1 785-587-6616
Generate a string with 5 characters in the start and 5 numbers in the end
"{{string_5}}{{number_5}}";
// output: LPDZW86423
Generate a string like a gun name
"AK-{{number_2}}";
// output: AK-35
// output: AK-87
// output: AK-47
// .. etc
Generate a string with alternating character, number of length 5
"{{string_1}}{{number_1}}{{string_1}}{{number_1}}{{string_1}}";
// output: X9K5L
// output: E6S4W
Or any random combination like
"{{uuid}}---{{number_5}}---{{string_10}}";
// output: c1ed245a-18cb-4e8b-ad2f-db67f8fa4e09---68864---ULXCAKACQE