https://github.com/lucasgdb/generate-strings
Generate random strings, strings with mask and strength passwords with password-strength tester
https://github.com/lucasgdb/generate-strings
backend biome frontend javascript nodejs password password-generator random random-generation string-mask strings-manipulation typescript vitest
Last synced: 2 months ago
JSON representation
Generate random strings, strings with mask and strength passwords with password-strength tester
- Host: GitHub
- URL: https://github.com/lucasgdb/generate-strings
- Owner: lucasgdb
- License: mit
- Created: 2019-01-02T10:23:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-27T05:16:23.000Z (almost 2 years ago)
- Last Synced: 2025-10-26T13:37:31.363Z (8 months ago)
- Topics: backend, biome, frontend, javascript, nodejs, password, password-generator, random, random-generation, string-mask, strings-manipulation, typescript, vitest
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/generate-strings
- Size: 245 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
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.
[](https://travis-ci.com/lucasgdb/generate-strings)
## Installing
### Server-side (NodeJS)
From the command line:
```sh
npm install generate-strings --save
```
or
```sh
yarn add generate-strings
```
or
```sh
pnpm add generate-strings
```
### In-browser
Within your document (each one for the desired function)
```html
```
or
```html
```
## Features
1. Generate random strings:
```ts
',9nlg4^]'
```
2. Generate strings with mask:
```ts
'@#$%-@#$%-@#$%-@#$%' = 'Aa!0-Aa!0-Aa!0-Aa!0'
```
3. Generate passwords with password-strength tester:
```ts
{ 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
```ts
// require the module
const {
generateRandomString,
generateRandomStringWithMask,
generateRandomPassword,
} = require('generate-strings');
console.log(generateRandomString());
console.log(generateRandomStringWithMask());
console.log(generateRandomPassword());
```
### In-browser
```ts
// 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.
```ts
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
```ts
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*
```
```ts
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
```
```ts
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.)