Skip to content

Instantly share code, notes, and snippets.

@IAmJulianAcosta
Last active May 5, 2016 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IAmJulianAcosta/79048dd927b7655bfa3fb1efb578fb4f to your computer and use it in GitHub Desktop.
Save IAmJulianAcosta/79048dd927b7655bfa3fb1efb578fb4f to your computer and use it in GitHub Desktop.
Get Ember object simple name from complex name
//Returns a string with full name of component, like: <ProjectName@component:path/to/component-name::ember793>
let componentName = this.toString ();
//This regex will match the component and capture the latest part of component path.
let regex = componentName.match (/<[a-zA-Z]+@[a-zA-Z]+:(?:[a-z]+[\/])*([-a-z]+)::[a-zA-Z]+[0-9]+>/);
//The latest element of array is the component name.
console.log (regex[regex.length-1]); //component-name
//See: https://regex101.com/r/rX9bQ7/3 for explanation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment