Function definePattern

  • Defines a new string-struct matching a regular expression.

    Example

    const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu); type EthAddress = Infer; // string

    const CaipChainIdStruct = defineTypedPattern<${string}:${string}>( 'CaipChainId', /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u; ); type CaipChainId = Infer; // ${string}:${string}

    Returns

    A new string-struct that matches the given pattern.

    Type Parameters

    • Pattern extends string = string

      The pattern type, defaults to string.

    Parameters

    • name: string

      Type name.

    • pattern: RegExp

      Regular expression to match.

    Returns Struct<Pattern, null>