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

generate-strings

v3.0.0

Published

Generate random strings, strings with mask and passwords with password-strength tester

Downloads

159

Readme

generate-strings

Generate random strings, strings with mask and strength passwords

generate-strings is a string generator that build random strings, strings with mask and passwords with password-strength tester. It is lightweight, extensible, has no dependencies, typescript support and can be used on the server with NodeJS or in-browser with JS.

Build Status

Installing

Server-side (NodeJS)

From the command line:

npm install generate-strings --save

or

yarn add generate-strings

or

pnpm add generate-strings

In-browser

Within your document (each one for the desired function)

<script src="generateRandomString.min.js"></script>
<script src="generateRandomStringWithMask.min.js"></script>
<script src="generateRandomPassword.min.js"></script>

or

<script src="generateStrings.min.js"></script>

Features

  1. Generate random strings:
',9nlg4^]'
  1. Generate strings with mask:
'@#$%-@#$%-@#$%-@#$%' = 'Aa!0-Aa!0-Aa!0-Aa!0'
  1. Generate passwords with password-strength tester:
{ password: '2dt4hKIPO*=He', strength: 'high' }

Usage

After you've included it into your project, using the module is straightforward:

generateRandomString(options)

generateRandomStringWithMask(options)

generateRandomPassword(options)

Server-side

// require the module
const {
   generateRandomString,
   generateRandomStringWithMask,
   generateRandomPassword,
} = require('generate-strings');

console.log(generateRandomString());
console.log(generateRandomStringWithMask());
console.log(generateRandomPassword());

In-browser

// in the browser, including the script will make the function available.
console.log(generateRandomString());
console.log(generateRandomStringWithMask());
console.log(generateRandomPassword());

Configuring

The module may be configured as follows: OBS: The settings shown below are the defaults.

import { generateRandomString } from 'generate-strings';

// and then:
const randomString = generateRandomString();

Available options for generateRandomString

| Name | Type | Description | Default value | Allowed values | | ------------------- | ------- | ----------------------------------------- | ---------------------------- | ------------------------- | | stringLength | Integer | Size of the string that will be generated | 8 | 0-Number.MAX_SAFE_INTEGER | | upperCase | Boolean | Determines whether it will be generated | true | true, false | | upperCaseCharacters | String | UpperCase letters to be generated | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | 'A-Z' | | lowerCase | Boolean | Determines whether it will be generated | true | true, false | | lowerCaseCharacters | String | LowerCase letters to be generated | 'abcdefghijklmnopqrstuvwxyz' | 'a-z' | | special | Boolean | Determines whether it will be generated | false | true, false | | specialCharacters | String | Special letters to be generated | '!@#$%&*()=[]{}' | All special characters | | number | Boolean | Determines whether it will be generated | true | true, false | | numberCharacters | String | Numbers to be generated | '0123456789' | 0-9 |

Available options for generateRandomStringWithMask

| Name | Type | Description | Default value | Allowed values | | ------------------- | ------ | ------------------------------------------------ | ---------------------------- | ---------------------- | | mask | String | String mask that will be generated | '@#$%-@#$%-@#$%-@#$%' | * | | upperCaseCharacters | String | UpperCase letters to be generated | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | 'A-Z' | | lowerCaseCharacters | String | LowerCase letters to be generated | 'abcdefghijklmnopqrstuvwxyz' | 'a-z' | | specialCharacters | String | Special letters to be generated | '!@#$%&*()=[]{}' | All special characters | | numberCharacters | String | Numbers to be generated | '0123456789' | 0-9 | | upperCaseMask | String | Letter that will be replaced to a upperCase char | '@' | '*' | | lowerCaseMask | String | Letter that will be replaced to a lowerCase char | '#' | '*' | | specialMask | String | Letter that will be replaced to a special char | '$' | '*' | | numberMask | String | Letter that will be replaced to a number | '%' | '*' |

Available options for generateRandomPassword

| Name | Type | Description | Default value | Allowed values | | ------------------- | ------- | ----------------------------------------------- | ---------------------------- | ------------------------------------------------------- | | passwordLength | Integer | Size of the strings that will be generated | 8 | 0-Number.MAX_SAFE_INTEGER | | showStrength | Boolean | Shows the password strength | false | true, false | | excludeEqualChars | Boolean | Excludes characters that are consecutive equals | false | true, false | | firstCharType | String | Determines the type of first character | 'random' | 'random', 'upperCase', 'lowerCase', 'special', 'number' | | upperCase | Boolean | Determines whether it will be generated | true | true, false | | upperCaseCharacters | String | UpperCase letters to be generated | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | 'A-Z' | | lowerCase | Boolean | Determines whether it will be generated | true | true, false | | lowerCaseCharacters | String | LowerCase letters to be generated | 'abcdefghijklmnopqrstuvwxyz' | 'a-z' | | special | Boolean | Determines whether it will be generated | false | true, false | | specialCharacters | String | Special letters to be generated | '!@#$%&*()=[]{}' | All special characters | | number | Boolean | Determines whether it will be generated | true | true, false | | numberCharacters | String | Numbers to be generated | '0123456789' | 0-9 |

Examples

import {
   generateRandomString,
   generateRandomStringProps,
} from 'generate-strings';

const settings: generateRandomStringProps = {
   stringLength: 15,
   special: true,
};

const randomStringWithMask = generateRandomString(settings); // will return a string like: bov$Ia@}Rr8gzU*
import {
   generateRandomStringWithMask,
   generateRandomStringWithMaskProps,
} from 'generate-strings';

const settings: generateRandomStringWithMaskProps = {
   upperCaseMask: '&',
   mask: '####_####%@hotmail.com',
};

const randomStringWithMask = generateRandomStringWithMask(settings); // will return a string like: [email protected]
import {
   generateRandomPassword,
   generateRandomPasswordProps,
} from 'generate-strings';

const settings: generateRandomPasswordProps = {
   passwordLength: 12,
   special: true,
   showStrength: true,
   excludeEqualChars: true,
};

const randomPassword = generateRandomPassword(settings); // will return a object like: { password: 'T2$he{Yk6pvf', strength: 'high' }

Testing

To test the application, run yarn test. You may first need to run yarn to install the required development dependencies. (These dependencies are not required in a production environment, and facilitate only unit testing.)