2.1.0 • Published 3 years ago

generate-strings v2.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

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

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

NameTypeDescriptionDefault valueAllowed values
stringLengthIntegerSize of the string that will be generated80-Number.MAX_SAFE_INTEGER
upperCaseBooleanDetermines whether it will be generatedtruetrue, false
upperCaseCharactersStringUpperCase letters to be generated'ABCDEFGHIJKLMNOPQRSTUVWXYZ''A-Z'
lowerCaseBooleanDetermines whether it will be generatedtruetrue, false
lowerCaseCharactersStringLowerCase letters to be generated'abcdefghijklmnopqrstuvwxyz''a-z'
specialBooleanDetermines whether it will be generatedfalsetrue, false
specialCharactersStringSpecial letters to be generated'!@#$%&*()=[]{}'All special characters
numberBooleanDetermines whether it will be generatedtruetrue, false
numberCharactersStringNumbers to be generated'0123456789'0-9

Available options for generateRandomStringWithMask

NameTypeDescriptionDefault valueAllowed values
maskStringString mask that will be generated'@#$%-@#$%-@#$%-@#$%'*
upperCaseCharactersStringUpperCase letters to be generated'ABCDEFGHIJKLMNOPQRSTUVWXYZ''A-Z'
lowerCaseCharactersStringLowerCase letters to be generated'abcdefghijklmnopqrstuvwxyz''a-z'
specialCharactersStringSpecial letters to be generated'!@#$%&*()=[]{}'All special characters
numberCharactersStringNumbers to be generated'0123456789'0-9
upperCaseMaskStringLetter that will be replaced to a upperCase char'@''*'
lowerCaseMaskStringLetter that will be replaced to a lowerCase char'#''*'
specialMaskStringLetter that will be replaced to a special char'$''*'
numberMaskStringLetter that will be replaced to a number'%''*'

Available options for generateRandomPassword

NameTypeDescriptionDefault valueAllowed values
passwordLengthIntegerSize of the strings that will be generated80-Number.MAX_SAFE_INTEGER
showStrengthBooleanShows the password strengthfalsetrue, false
excludeEqualCharsBooleanExcludes characters that are consecutive equalsfalsetrue, false
firstCharTypeStringDetermines the type of first character'random''random', 'upperCase', 'lowerCase', 'special', 'number'
upperCaseBooleanDetermines whether it will be generatedtruetrue, false
upperCaseCharactersStringUpperCase letters to be generated'ABCDEFGHIJKLMNOPQRSTUVWXYZ''A-Z'
lowerCaseBooleanDetermines whether it will be generatedtruetrue, false
lowerCaseCharactersStringLowerCase letters to be generated'abcdefghijklmnopqrstuvwxyz''a-z'
specialBooleanDetermines whether it will be generatedfalsetrue, false
specialCharactersStringSpecial letters to be generated'!@#$%&*()=[]{}'All special characters
numberBooleanDetermines whether it will be generatedtruetrue, false
numberCharactersStringNumbers 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: ekts_raqm1@hotmail.com
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.)

2.0.2

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago