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

rand-gen

v1.0.3

Published

Generates a random set of characters.

Downloads

210

Readme

rand-gen

Random character generator that builds a random string. The string produced can include upper and lowercase letters numbers and special characters.

Version: 1.0.3

Installation

  1. install npm
  2. npm install rand-gen

Getting Started

To use rand-gen require it into your file and call .gen().

var randGen = require('rand-gen');

var myFunction = function () {
    var randStr = randGen().gen();
    console.log(randStr);       // random string of 15 characters.
};

The above function will produce a random string that can include all letters a-z lower and uppercase, numbers 0-9, and special characters.

Options

  • length - Default length is 15 can be changed.
  • uppercase - Default is set to true, your random string cannot include uppercase letters set to false.
  • lowercase - Default is set to true, your random string cannot include lowercase letters set to false.
  • numbers - Default is set to true, your random string cannot include numbers set to false.
  • spChars - Default is set to true, your random string cannot include special characters set to false.
  • include - If there is a character or a set of characters, you need you include them as a single string or array of individual characters.
  • exclude - If you need to exclude a character or a set of characters pass them as a single string or array of individual characters.

Options Usages

var randGen = require('rand-gen');

var myFunction1 = function () {
    var randStr = randGen({
        length: 10
    }.gen();
    console.log(randStr);       // random string of 10 characters.
};

var myFunction2 = function () {
    var randStr = randGen({
        length: 20,
        spChars: false,
        numbers: false,
    }.gen();
    console.log(randStr);       // random string of 20 characters that will not have special characters or numbers.
};

var myFunction3 = function () {
    var randStr = randGen({
        length: 20,
        include: "ȦÖ",
        numbers: false,
        spChars: false
    }.gen();
    console.log(randStr);       // random string of 20 characters that will not have special characters or numbers but includes Ȧ and Ö into the pool.
};

var myFunction4 = function () {
    var randStr = randGen({
        include: "ȦÖ",
        exclude: ["A", "0"]
    }.gen();
    console.log(randStr);       // random string of 15 that includes Ȧ and Ö into the pool but removes A and 0 as options.
};

Functions

To go with the optionals that can be passed in you can call individual functions that is not .gen() to get random characters.

Alphabet Functions

The alphabet function are:

randGen().alphabet();
randGen().alpha.lowercase();
randGen().alpha.uppercase();
  • randGen().alphabet(); - Returns a string that can include upper and lower case letters.
  • randGen().alpha.lowercase(); - Returns a string that only includes lowercase letters.
  • randGen().alpha.uppercase(); - Returns a string that only includes uppercase letters.

Number Function

The .number() will generate a string of numbers it can also return a base 10 integer if you pass true into the function.

Acceptable parameter

  • Boolean - Passing a boolean value of true will return a base 10 integer instead of a string.
  • Number or String - You may pass a number or a string representation of a number between 2 and 36 will return a string number in that base.
randGen().number(); // Will be a string of a base 10 numbers like "012345678901234"
randGen().number(true); // Will return an integer number like 123456789012345
randGen().number(16); // Will return a hexadecimal number like "123456789abcdef"

Special Characters Function

The .spChars() will generate a string of special characters. The pool of special characters is this: "!@#$%^&*()_-+=;:{}[]"'<>,./|~`?".

randGen().spChars();

noDups Function

If the .noDups() function is called, no two of the same characters will be in the resulting string. Be sure your length does not exceed the amount of total characters in the pool. By default there are 96 characters so don't make your length 97.

randGen().noDups(); // Returns something like "asdfg1bD6m%0Vq3"

Single Character Function

.char() will return a single random character that could be any lower or uppercase letter, any number or any special character.

randGen().char();

License MIT

MIT License

Copyright (c) 2016 Sean McCrory

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.