Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function route(name, config={}) {
- let {url} = config
- url = url || `/${name}`
- url = normalizeRouteUrl(url)
- const normalizedRouteName = normalizeRouteName(name)
- const nameCap = normalizedRouteName[0].toUpperCase() + normalizedRouteName.slice(1)
- const controller = `${nameCap}Ctrl as vm`
- const templateUrl = `controllers/${nameCap}Ctrl.html`
- return {
- name,
- url,
- controller,
- templateUrl,
- ...config,
- }
- }
- function normalizeRouteUrl(routeUrl) {
- if( /\.index$/g.test(routeUrl) ){
- return '/'
- }
- const match = routeUrl.match(/[^\/\.]*$/)
- if( match ) {
- return '/'+match[0]
- }
- return routeUrl
- }
- function normalizeRouteName(routeName) {
- return routeName.replace(/\.(.)/g, function(_, group) {
- return group.toUpperCase()
- })
- }
- function isConfig(object) {
- return Object.prototype.toString.call(object) === '[object Object]'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement