FaasJS
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security

Documents / @faasjs/utils / generateId

Function: generateId()

generateId(prefix?, length?): string

Generate a random identifier with an optional prefix.

Parameters

prefix?

string = ''

Prefix prepended to the generated identifier.

length?

number = 18

Length of the generated identifier excluding prefix. Must be between 8 and 18.

Returns

string

Generated identifier string.

Throws

When length is outside the supported 8 to 18 range.

Example

import { generateId } from '@faasjs/utils'

const id = generateId('prefix-')

id.startsWith('prefix-') // true