Allow documentation of strings that should match a pattern similar to enum of strings
Author: AncientSwordRageCreated Nov 25, 2021Updated Mar 9, 2026
Similar to jsdoc/issues/629 I'd like to be able to specify a regex pattern a string should match:
/**
* @param {('gif'|/jp(e?)g/)} imageType - Type of the image
*/
function foo(imageType){};I'm not expecting anything to be enforced, but some parsing to make sense of the regex without displaying it as a literal string enum.
Here're another few examples:
/**
* note the lowercase flag
* @param {/[0-9A-F]+/i} hexDigitString - string representation of a hexadecimal digit
*/
function foo(hexDigitString){};And real wishlist idea:
/**
* @patternDef hexString
* @pattern /[0-9A-F]+/
*/
/**
* compose patterns
* this one matches ^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$
* @param {/{hexString}{8}-{hexString}{4}-4{hexString}{3}-[89AB]{hexString}{3}-{hexString}{12}/} uuid - string representation uuidv4
*/
function foo(hexDigitString){};Is this a possible new feature?
Source: jsdoc/jsdoc