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

@se-oss/rand

v1.0.0

Published

A utility library for generating random strings, numbers and UUIDs.

Downloads

30

Readme

rand

A collection of utility functions for generating random strings and numbers in various formats. This library provides easy-to-use functions to create random values for different use cases, including Base10, Base36, Base62 strings, UUIDv4, and random numbers within specified ranges or of specified lengths.

Installation

npm install @se-oss/rand

API

// Generates a random string of a specified length using the provided characters.
declare function random(chars: string, length: number): string;

// Generates a random string of a specified length using Base62 characters (A-Z, a-z, 0-9).
declare function randomBase62(length: number): string;

// Generates a random string of a specified length using Base36 characters (a-z, 0-9).
declare function randomBase36(length: number): string;

// Generates a random string of a specified length using Base10 characters (0-9).
declare function randomBase10(length: number): string;

// Generates a random UUIDv4 string.
declare function randomUuidv4(): string;

// Generates a random number within a specified range or of a specified length.
declare function randomNumber(min: number, max: number): number;
declare function randomNumber(length: number): number;

Examples

Here are some examples of how to use the Random class:

import {
  randomBase62,
  randomBase36,
  randomBase10,
  randomUuidv4,
  randomNumber
} from '@se-oss/random';

// Generate a random Base62 string of length 12
console.log(randomBase62(12)); // Example output: 'A1b2C3d4E5f6'

// Generate a random Base36 string of length 8
console.log(randomBase36(8)); // Example output: '1a2b3c4d'

// Generate a random Base10 string of length 4
console.log(randomBase10(4)); // Example output: '5678'

// Generate a random UUIDv4 string
console.log(randomUuidv4()); // Example output: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'

// Generate a random number between 1 and 10
console.log(randomNumber(1, 10)); // Example output: 5

// Generate a random number of length 16
console.log(randomNumber(16)); // Example output: 8933580352864351

Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.

Thanks again for your support, it is much appreciated!

License

MIT © Shahrad Elahi