Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. export default function route(name, config={}) {
  2. let {url} = config
  3. url = url || `/${name}`
  4. url = normalizeRouteUrl(url)
  5. const normalizedRouteName = normalizeRouteName(name)
  6. const nameCap = normalizedRouteName[0].toUpperCase() + normalizedRouteName.slice(1)
  7. const controller = `${nameCap}Ctrl as vm`
  8. const templateUrl = `controllers/${nameCap}Ctrl.html`
  9. return {
  10. name,
  11. url,
  12. controller,
  13. templateUrl,
  14. ...config,
  15. }
  16. }
  17.  
  18. function normalizeRouteUrl(routeUrl) {
  19. if( /\.index$/g.test(routeUrl) ){
  20. return '/'
  21. }
  22. const match = routeUrl.match(/[^\/\.]*$/)
  23. if( match ) {
  24. return '/'+match[0]
  25. }
  26. return routeUrl
  27. }
  28.  
  29. function normalizeRouteName(routeName) {
  30. return routeName.replace(/\.(.)/g, function(_, group) {
  31. return group.toUpperCase()
  32. })
  33. }
  34.  
  35. function isConfig(object) {
  36. return Object.prototype.toString.call(object) === '[object Object]'
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement