Giter VIP home page Giter VIP logo

lucasgdb / generate-strings Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 251 KB

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

Home Page: https://www.npmjs.com/package/generate-strings

License: MIT License

JavaScript 4.80% TypeScript 95.20%
frontend backend nodejs javascript password-generator random-generation strings-manipulation string-mask password random

generate-strings's Introduction

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.)

generate-strings's People

Contributors

lucasgdb avatar vkatatab avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

vkatatab

generate-strings's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.