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

@nakarmi23/random-string-generator

v1.0.5

Published

The stringGenerator function is a simple and flexible utility that generates a random string based on specified character type options. You can control the length of the string and choose to include or exclude lowercase letters, uppercase letters, numbers

Downloads

177

Readme

Random String generator

Introduction

The stringGenerator function is a simple and flexible utility that generates a random string based on specified character type options. You can control the length of the string and choose to include or exclude lowercase letters, uppercase letters, numbers, and symbols.

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. API Reference

Features

  • Customizable Length: Specify the length of the generated string.
  • Flexible Character Options: Choose to include or exclude lowercase letters, uppercase letters, numbers, and symbols.
  • Default Settings: If no options are provided, the function will generate a string with all character types.

Installation

Package Manager

Using npm:

npm install @nakarmi23/random-string-generator

Using yarn:

yarn add @nakarmi23/random-string-generator

Using pnpm:

pnpm add @nakarmi23/random-string-generator

Once the package is installed, you can import the library using import or require approach:

import stringGenerator from '@nakarmi23/random-string-generator';

or

const {stringGenerator} = require('@nakarmi23/random-string-generator');

Usage

Generating a Default String

By default, the stringGenerator function generates a string of 20 characters, including lowercase letters, uppercase letters, numbers, and symbols.

const randomString = stringGenerator();
console.log(randomString); // Example output: 'aB3#cD4@eF5%gH6^'

Customizing the String Length and Character Types

You can customize the length of the string and specify which types of characters to include:

// Generate a string with 10 characters, including only uppercase letters and numbers.
const randomString = stringGenerator(10, { lowercase: false, symbol: false });
console.log(randomString); // Example output: 'A9B8C7D6E5'

Error Handling

If you disable all character options, the function will throw an error, as at least one option must be enabled:

try {
  const randomString = stringGenerator(10, { lowercase: false, uppercase: false, number: false, symbol: false });
} catch (error) {
  console.error(error.message); // Output: 'At least one option must be enabled'
}

API Reference

stringGenerator(length = 20, options)

Generates a random string based on the provided parameters.

  • Parameter:
    • length (number, optional): The length of the generated string. Defaults to 20.
    • options (object, optional): An object specifying which character types to include:
      • lowercase (boolean, optional): Include lowercase letters (a-z). Defaults to true.
      • uppercase (boolean, optional): Include uppercase letters (A-Z). Defaults to true.
      • number (boolean, optional): Include numbers (0-9). Defaults to true.
      • symbol (boolean, optional): Include symbols (e.g., @, #, $, etc.). Defaults to true.
    • returns: A randomly generated string of the specified length and character types.
    • throws: If all options are disabled, an error is thrown to indicate that at least one option must be enabled.