ts-utils
  • Getting Started
  • Contributing
  • Testing
  • Functions
    • Array Methods
      • isArr
      • isArrEmpty
      • pushUniqueValue
      • pushOrUpdate
    • Date Methods
      • toNow
      • formatDate
      • fromNow
    • Number Methods
      • toFixed
      • parseNumber
      • parseFormat
      • addUnit
      • addSeparators
      • formatNumber
      • ensureNumber
      • numberEmptyState
    • Object Methods
      • parseJSON
      • deepClone
      • parseNumValues
      • removeEmptyKeys
      • sanitizeQuery
      • removeKeys
      • renameKey
      • renameKeys
      • sortByKeyLength
      • querylize
      • parseNumericObj
      • reserveKeys
      • hasKeysAndValues
    • String Methods
      • randomStr
      • toUpperCase
      • toLowerCase
      • toFullUrl
      • initials
      • generateUuid
Powered by GitBook
On this page
  • randomStr(options)
  • Arguments
  • Returns
  • Example
  • Usage
  • Notes

Was this helpful?

  1. Functions
  2. String Methods

randomStr

randomStr(options)

Generates a random string based on specified options. If no options are provided, it uses the default options defined in defaultOptions. This function is useful for generating random strings with customizable length, character sets, and case.

Arguments

  • options (Partial): Custom options for generating the random string. Defaults to defaultOptions if not provided.

Returns

  • string: A randomly generated string based on the provided options.

Example

typescript
import { randomStr } from 'check-engineering/ts-utils';

const randomPassword = randomStr({
  length: 16,
  special: true,
  case: "upper",
}); // => "ABCD1234!@#$EFGH"

Usage

typescript
import { randomStr } from 'check-engineering/ts-utils';

const randomId = randomStr(); // => "a1b2c3d4e5f6g7h8"

Notes

  • The randomStr function allows you to generate random strings with customizable options.

  • It uses the defaultOptions object as the default configuration, which includes options for alphabet, numbers, length, special characters, and case.

  • You can provide a partial object of defaultOptions to override specific options and customize the generated string.

  • This function is particularly useful for generating unique identifiers, passwords, or any other scenario where a random string is required.

PreviousString MethodsNexttoUpperCase

Last updated 11 months ago

Was this helpful?