StringUtility
Index
Constructors
constructor
Returns StringUtility
Methods
staticboundedName
Shortens a name to at most
maxLengthcharacters, replacing what is cut with a digest of the whole name. Two names that differ anywhere still differ after shortening, and the same name always shortens the same way. A name already within the limit is returned as it is.Use it where a provider limits a name that is built by joining others, e.g. a distribution name and an origin id, so that cutting the tail alone could make two names collide.
Parameters
name: string
maxLength: number
Returns string
staticdeterministicHash
Produces a 16-character hex hash of any value, with object keys sorted recursively, so the hash does not change when key insertion order does. Hash several parts as an array,
deterministicHash([bucketName, accessPrefix]), which keeps['ab', 'c']and['a', 'bc']apart. Take a prefix of it where a shorter id is enough.Parameters
value: unknown
Returns string
staticsanitizeForEnvironmentVariable
Replaces every character that is not a letter, digit, or underscore with an underscore. Suitable for names that travel through environment variables (e.g. terraform variables, which terragrunt passes as
TF_VAR_<name>), where dashes are not allowed.Parameters
value: string
Returns string
staticsanitizeForIdentifier
Replaces every character that is not a letter, digit, underscore, or dash with an underscore. Suitable for terraform identifiers (resource names, output names), which allow dashes.
Parameters
value: string
Returns string
String helpers for module and resource authors: hashing values into stable ids, fitting names into a provider's length limit, and making names safe for terraform.
Utilities/String