All files / generators/e2e-project to-valid-ssm-parameter-name.ts

100% Statements 6/6
100% Branches 1/1
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16        3x 72x   72x 1x         71x    
/**
 * Filters out invalid SSM parameter name characters (https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-su-create.html).
 * Throws an error if the resulting name has zero length.
 */
export const toValidSsmParameterName = (parameterName: string): string => {
  const validName = parameterName.replace(/[^a-zA-Z0-9_./-]/g, '');
 
  if (!validName) {
    throw new Error(
      `The valid SSM parameter name for '${parameterName}' is an empty string.`,
    );
  }
 
  return validName;
};