vc-authn-oidc icon indicating copy to clipboard operation
vc-authn-oidc copied to clipboard

Add User Definable Variable Substitution

Open Gavinok opened this issue 1 year ago • 1 comments

This PR resolves #649

I have documented and added a user definable way to add new variable substitutions. A simple API for defining regex based variable matching. Here is a simple example usage.

def sub_days_plus_one(days: str) -> int:
    """Strings like '$sub_days_plus_one_4' will be replaced with the
    final number incremented by one. In this case 5.
    $sub_days_plus_one_4 -> 5
    $sub_days_plus_one_10 -> 11"""
    return int(days) + 1


variable_substitution_map.add_variable_substitution(
    r"\$sub_days_plus_one_(\d+)", sub_days_plus_one
)
variable_substitution_map["$sub_days_plus_one_1"] # -> 2

Gavinok avatar Oct 30 '24 19:10 Gavinok