john-goldsmith/vscode-aws-cloudformation-auto-template-generator

View on GitHub
src/utils/get-logical-id.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
/**
 * Creates and returns a logical ID. If the provided `type` param is a
 * string, it will prefix with `My` and remove all instances of `::`.
 * If the provided `type` param is not a string, it defaults to `MyResource`.
 *
 * @param {string} type
 * @return {string}
 */
export default function getLogicalId(type: string): string {
  if (typeof type !== 'string') return 'MyResource'
  const logicalId = `My${type.replace(/::/g, '')}`
  return logicalId
}