From 201eeb642a3d8227b9b4f05a9f3c75870c1f174e Mon Sep 17 00:00:00 2001 From: sundowndev Date: Wed, 15 May 2019 15:16:38 +0200 Subject: [PATCH] refactor: build files --- dist/leafeon.js | 6 ++++-- dist/leafeon.js.map | 2 +- dist/leafeon.min.js | 2 +- lib/leafeon.js | 6 ++++-- lib/leafeon.js.map | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dist/leafeon.js b/dist/leafeon.js index 490bb6e..e1681bc 100644 --- a/dist/leafeon.js +++ b/dist/leafeon.js @@ -178,7 +178,9 @@ var Router = /** @class */ (function (_super) { * @function notFoundException */ _this.notFoundException = function () { - _this.notFoundCallback.apply(null, []); + if (_this.notFoundCallback !== null) { + _this.notFoundCallback.apply(null, []); + } }; /** * @function before @@ -242,7 +244,7 @@ var Router = /** @class */ (function (_super) { return targetedRoute.name === route || targetedRoute.path === route; }); if (targetRoute === undefined) { - return _this.exception('Route ' + route + ' does not exist.'); + return _this.notFoundException(); } if (!targetRoute.paramsEnabled) { _this.setURI(targetRoute.path); diff --git a/dist/leafeon.js.map b/dist/leafeon.js.map index 0cff478..7ee279f 100644 --- a/dist/leafeon.js.map +++ b/dist/leafeon.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap c41afcde593b15b66c14","webpack:///./src/leafeon.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;A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Q,IAAI,IAAI,EAAE;gBAClB,IAAI,KAAK,KAAK,GAAG,EAAE;oBACf,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;iBACnC;qBAAM,IAAI,KAAK,KAAK,KAAI,CAAC,MAAM,EAAE,EAAE;oBAChC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;iBACnC;aACJ;QACL,CAAC;QAzQG,KAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,6DAA6D;QACnF,KAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,KAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,KAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,KAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,KAAI,CAAC,qBAAqB,GAAG,GAAG,CAAC;QACjC,KAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,KAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;QACtC,KAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,KAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAE7B,KAAI,CAAC,cAAc,CAAC,KAAI,CAAC,GAAG,CAAC,CAAC;;IAClC,CAAC;IA8PL,aAAC;AAAD,CAAC,CAzR2B,aAAa,GAyRxC;AAzRY,wBAAM","file":"leafeon.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"leafeon\"] = factory();\n\telse\n\t\troot[\"leafeon\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap c41afcde593b15b66c14","interface IRoute {\n name: string;\n path: string;\n callback: void;\n paramsEnabled?: boolean;\n params?: Array;\n}\n\n/**\n * @class RouterRequest\n */\nclass RouterRequest {\n public URI: string;\n public windowObj: any;\n\n constructor() {\n const fakeLocation = {\n location: {\n href: '/#/',\n hash: '#/',\n },\n };\n\n this.windowObj = (typeof window === 'undefined') ? fakeLocation : window;\n this.URI = this.getURI();\n }\n\n /**\n * @function getURI\n * @returns {string}\n */\n public getURI = (): string => {\n return this.URI = this.formatPath(this.windowObj.location.hash);\n }\n\n /**\n * @function setURI\n * @param route string\n */\n public setURI = (route: string): void => {\n this.windowObj.location.hash = route;\n }\n\n /**\n * @function formatPath\n * @description Format given path\n * @param path\n */\n public formatPath = (path: string): string => {\n if (path === '') {\n return '/';\n }\n\n if (path.match(/^(?:\\/)?(?:\\#)?(?:\\/)?[a-zA-Z0-9\\-_\\/:]+/)[0] !== path) {\n this.exception('Path is not formated correctly.');\n }\n\n return path.replace(/^(?:\\/)?(?:\\#)?(?:\\/)/, '/');\n }\n\n /**\n * @function exception\n * @param {string} message\n * @returns {never}\n */\n public exception = (message: string): never => {\n throw new TypeError(message);\n }\n\n /**\n * @function windowListener\n * @param route string\n */\n public windowListener = (callback: Function): void => {\n if (typeof window !== 'undefined') {\n window.onhashchange = () => {\n callback();\n };\n }\n }\n}\n\n/**\n * @package leafeon\n * @description Client-sided and dependency-free Javascript routing library\n * @license MIT\n */\nexport class Router extends RouterRequest {\n private notfound: boolean;\n private routeCall: any;\n private params: Array;\n private beforeRouteMiddleware: string;\n private beforeRouteMiddlewareFunc: any;\n private afterRouteCallback: any;\n private notFoundCallback: any;\n public route: object;\n public routes: Array;\n public paramsEnabled: boolean;\n\n constructor() {\n super();\n\n this.notfound = true; // While a route has not match the URI, set page as not found\n this.routes = [];\n this.paramsEnabled = false;\n this.route = null;\n this.params = [];\n this.beforeRouteMiddleware = '*';\n this.routeCall = null;\n this.beforeRouteMiddlewareFunc = null;\n this.afterRouteCallback = null;\n this.notFoundCallback = null;\n\n this.windowListener(this.run);\n }\n\n /**\n * @function setErrorCallback\n * @param func\n */\n public setErrorCallback = (func: any): this => {\n this.notFoundCallback = func;\n\n return this;\n }\n\n /**\n * @function notFoundException\n */\n public notFoundException = (): void => {\n this.notFoundCallback.apply(null, []);\n }\n\n /**\n * @function before\n * @description Before route function\n * @param route\n * @param func\n */\n public before = (route: string, func: any): this => {\n this.beforeRouteMiddleware = route;\n this.beforeRouteMiddlewareFunc = func;\n\n return this;\n }\n\n /**\n * @function add\n * @param {string} name\n * @param {string} path\n * @param callback\n */\n public add = (name: string, path: string, callback: any): this => {\n const routeArray = path.split('/');\n\n let paramsEnabled = false;\n const params: Array = [];\n\n routeArray.forEach(r => {\n if (r.substr(0, 1) === ':') {\n paramsEnabled = true;\n params.push(r.substr(1, r.length));\n }\n });\n\n this.paramsEnabled = paramsEnabled;\n\n path = path.split('#')[1] || path;\n\n this.routes.push({\n name: name,\n path: path,\n callback: callback,\n paramsEnabled: paramsEnabled,\n params: params,\n });\n\n return this;\n }\n\n /**\n * @function map\n * @description Mapping routes into a specific path\n * @param name\n * @param mount\n * @param routes\n */\n public map = (name: string, mount: string, routes: any[]): this => {\n routes.forEach((route: IRoute) => {\n this.add(name + route.name, mount + this.formatPath(route.path), route.callback);\n });\n\n return this;\n }\n\n /**\n * @function fetchRoute\n * @description Target a given route by name or path\n * @param route\n * @param params\n */\n public fetchRoute = (route: string, params: Array): void => {\n const targetRoute = this.routes.find((targetedRoute: IRoute) => {\n return targetedRoute.name === route || targetedRoute.path === route;\n });\n\n if (targetRoute === undefined) {\n return this.exception('Route ' + route + ' does not exist.');\n }\n\n if (!targetRoute.paramsEnabled) {\n this.setURI(targetRoute.path);\n return;\n }\n\n if (!params) {\n this.exception('Error: route \"' + route + '\" requires some parameters. None specified.');\n }\n\n const generatedURI = this.generateURL(targetRoute.path, params);\n\n this.setURI(generatedURI);\n }\n\n /**\n * @function generateURL\n * @description Generate URL from route and parameters\n * @param route\n * @param params\n * @returns string\n */\n private generateURL = (route: string, params: Array): string => {\n let generatedURI = route;\n\n Object.keys(params).forEach(p => {\n const paramInRoute = route.split('/').find(targetParam => {\n return targetParam === ':' + p;\n });\n\n if (paramInRoute !== undefined) {\n generatedURI = generatedURI.replace(paramInRoute, params[p]);\n }\n });\n\n return generatedURI;\n }\n\n /**\n * @function setRoute\n * @description Set the route callback if it match\n * @param route\n * @param params\n */\n private setRoute = (route: IRoute, params: Array = []): void => {\n this.route = route;\n this.routeCall = route.callback;\n this.params = params;\n this.notfound = false;\n }\n\n /**\n * @function handle\n * @description Check route\n * @param routes\n */\n private handle = (routes: Array): void => {\n const URI = this.getURI();\n\n routes.forEach(route => {\n const routeArray = route.path.split('/');\n const uriArray: Array = URI.split('/');\n\n if (uriArray.length !== routeArray.length) {\n return;\n }\n\n const routeOptions: any = this.handlingParams(route.path);\n\n if (routeOptions.RouteString === URI && this.notfound) {\n return this.setRoute(route, routeOptions.params);\n }\n });\n }\n\n /**\n * @function handlingParams\n * @param {string} route\n * @returns {object}\n */\n private handlingParams = (route: string): object => {\n const uriArray = this.getURI().split('/');\n const routeArray = route.split('/');\n const params: Array = [];\n\n for (let i = 0; i < routeArray.length; i++) {\n if (routeArray[i].substr(0, 1) === ':') {\n if (uriArray[i] !== '') {\n params.push(uriArray[i]);\n }\n\n routeArray[i] = uriArray[i];\n }\n }\n\n return {\n params: params,\n RouteString: routeArray.join('/'),\n };\n }\n\n /**\n * @function run\n * @description Run the router and search for a route match\n * @param afterRouteCallback\n */\n public run = (afterRouteCallback?: any): void => {\n this.route = null;\n this.routeCall = null;\n this.params = [];\n this.notfound = true;\n\n const URI = this.getURI();\n const routes: Array = [];\n\n // Execute before middleware\n this.beforeMiddleware(this.beforeRouteMiddleware, this.beforeRouteMiddlewareFunc);\n\n this.routes.forEach(route => {\n if (route.paramsEnabled) {\n routes.push(route);\n this.handle(routes);\n } else if (route.path === URI) {\n this.setRoute(route);\n }\n });\n\n // If there's a route match, execute the callback\n if (this.notfound) {\n this.notFoundException();\n } else {\n this.routeCall.apply(null, this.params);\n }\n\n // Call after middleware\n if (afterRouteCallback != null) {\n this.afterRouteCallback = afterRouteCallback;\n this.afterRouteCallback.apply(null, []);\n } else if (this.afterRouteCallback != null) {\n this.afterRouteCallback.apply(null, []);\n }\n }\n\n /**\n * @function beforeMiddleware\n * @param {string} route\n * @param callback\n */\n private beforeMiddleware = (route: string, callback: any) => {\n route = route.split('#')[1] || route;\n\n if (callback != null) {\n if (route === '*') {\n return callback.apply(null, []);\n } else if (route === this.getURI()) {\n return callback.apply(null, []);\n }\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/leafeon.ts"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap d3812e70b47117f692db","webpack:///./src/leafeon.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;ACxDA;;GAEG;AACH;IAII;QAAA,iBAUC;QAED;;;WAGG;QACI,WAAM,GAAG;YACZ,OAAO,KAAI,CAAC,GAAG,GAAG,KAAI,CAAC,UAAU,CAAC,KAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpE,CAAC;QAED;;;WAGG;QACI,WAAM,GAAG,UAAC,KAAa;YAC1B,KAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC;QACzC,CAAC;QAED;;;;WAIG;QACI,eAAU,GAAG,UAAC,IAAY;YAC7B,IAAI,IAAI,KAAK,EAAE,EAAE;gBACf,OAAO,GAAG,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B,KAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,KAAI,CAAC,qBAAqB,GAAG,GAAG,CAAC;QACjC,KAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,KAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;QACtC,KAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,KAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAE7B,KAAI,CAAC,cAAc,CAAC,KAAI,CAAC,GAAG,CAAC,CAAC;;IAClC,CAAC;IAgQL,aAAC;AAAD,CAAC,CA3R2B,aAAa,GA2RxC;AA3RY,wBAAM","file":"leafeon.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"leafeon\"] = factory();\n\telse\n\t\troot[\"leafeon\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap d3812e70b47117f692db","interface IRoute {\n name: string;\n path: string;\n callback: void;\n paramsEnabled?: boolean;\n params?: Array;\n}\n\n/**\n * @class RouterRequest\n */\nclass RouterRequest {\n public URI: string;\n public windowObj: any;\n\n constructor() {\n const fakeLocation = {\n location: {\n href: '/#/',\n hash: '#/',\n },\n };\n\n this.windowObj = (typeof window === 'undefined') ? fakeLocation : window;\n this.URI = this.getURI();\n }\n\n /**\n * @function getURI\n * @returns {string}\n */\n public getURI = (): string => {\n return this.URI = this.formatPath(this.windowObj.location.hash);\n }\n\n /**\n * @function setURI\n * @param route string\n */\n public setURI = (route: string): void => {\n this.windowObj.location.hash = route;\n }\n\n /**\n * @function formatPath\n * @description Format given path\n * @param path\n */\n public formatPath = (path: string): string => {\n if (path === '') {\n return '/';\n }\n\n if (path.match(/^(?:\\/)?(?:\\#)?(?:\\/)?[a-zA-Z0-9\\-_\\/:]+/)[0] !== path) {\n this.exception('Path is not formated correctly.');\n }\n\n return path.replace(/^(?:\\/)?(?:\\#)?(?:\\/)/, '/');\n }\n\n /**\n * @function exception\n * @param {string} message\n * @returns {never}\n */\n public exception = (message: string): never => {\n throw new TypeError(message);\n }\n\n /**\n * @function windowListener\n * @param route string\n */\n public windowListener = (callback: Function): void => {\n if (typeof window !== 'undefined') {\n window.onhashchange = () => {\n callback();\n };\n }\n }\n}\n\n/**\n * @package leafeon\n * @description Client-sided and dependency-free Javascript routing library\n * @license MIT\n */\nexport class Router extends RouterRequest {\n private notfound: boolean;\n private routeCall: any;\n private params: Array;\n private beforeRouteMiddleware: string;\n private beforeRouteMiddlewareFunc: any;\n private afterRouteCallback: any;\n private notFoundCallback: any;\n public route: object;\n public routes: Array;\n public paramsEnabled: boolean;\n\n constructor() {\n super();\n\n this.notfound = true; // While a route has not match the URI, set page as not found\n this.routes = [];\n this.paramsEnabled = false;\n this.route = null;\n this.params = [];\n this.beforeRouteMiddleware = '*';\n this.routeCall = null;\n this.beforeRouteMiddlewareFunc = null;\n this.afterRouteCallback = null;\n this.notFoundCallback = null;\n\n this.windowListener(this.run);\n }\n\n /**\n * @function setErrorCallback\n * @param func\n */\n public setErrorCallback = (func: any): this => {\n this.notFoundCallback = func;\n\n return this;\n }\n\n /**\n * @function notFoundException\n */\n public notFoundException = (): void => {\n if (this.notFoundCallback !== null) {\n this.notFoundCallback.apply(null, []);\n }\n }\n\n /**\n * @function before\n * @description Before route function\n * @param route\n * @param func\n */\n public before = (route: string, func: any): this => {\n this.beforeRouteMiddleware = route;\n this.beforeRouteMiddlewareFunc = func;\n\n return this;\n }\n\n /**\n * @function add\n * @param {string} name\n * @param {string} path\n * @param callback\n */\n public add = (name: string, path: string, callback: any): this => {\n const routeArray = path.split('/');\n\n let paramsEnabled = false;\n const params: Array = [];\n\n routeArray.forEach(r => {\n if (r.substr(0, 1) === ':') {\n paramsEnabled = true;\n params.push(r.substr(1, r.length));\n }\n });\n\n this.paramsEnabled = paramsEnabled;\n\n path = path.split('#')[1] || path;\n\n this.routes.push({\n name: name,\n path: path,\n callback: callback,\n paramsEnabled: paramsEnabled,\n params: params,\n });\n\n return this;\n }\n\n /**\n * @function map\n * @description Mapping routes into a specific path\n * @param name\n * @param mount\n * @param routes\n */\n public map = (name: string, mount: string, routes: any[]): this => {\n routes.forEach((route: IRoute) => {\n this.add(name + route.name, mount + this.formatPath(route.path), route.callback);\n });\n\n return this;\n }\n\n /**\n * @function fetchRoute\n * @description Target a given route by name or path\n * @param route\n * @param params\n */\n public fetchRoute = (route: string, params: Array): void => {\n const targetRoute = this.routes.find((targetedRoute: IRoute) => {\n return targetedRoute.name === route || targetedRoute.path === route;\n });\n\n if (targetRoute === undefined) {\n return this.notFoundException();\n }\n\n if (!targetRoute.paramsEnabled) {\n this.setURI(targetRoute.path);\n return;\n }\n\n if (!params) {\n this.exception('Error: route \"' + route + '\" requires some parameters. None specified.');\n }\n\n const generatedURI = this.generateURL(targetRoute.path, params);\n\n this.setURI(generatedURI);\n }\n\n /**\n * @function generateURL\n * @description Generate URL from route and parameters\n * @param route\n * @param params\n * @returns string\n */\n private generateURL = (route: string, params: Array): string => {\n let generatedURI = route;\n\n Object.keys(params).forEach(p => {\n const paramInRoute = route.split('/').find(targetParam => {\n return targetParam === ':' + p;\n });\n\n if (paramInRoute !== undefined) {\n generatedURI = generatedURI.replace(paramInRoute, params[p]);\n }\n });\n\n return generatedURI;\n }\n\n /**\n * @function setRoute\n * @description Set the route callback if it match\n * @param route\n * @param params\n */\n private setRoute = (route: IRoute, params: Array = []): void => {\n this.route = route;\n this.routeCall = route.callback;\n this.params = params;\n this.notfound = false;\n }\n\n /**\n * @function handle\n * @description Check route\n * @param routes\n */\n private handle = (routes: Array): void => {\n const URI = this.getURI();\n\n routes.forEach(route => {\n const routeArray = route.path.split('/');\n const uriArray: Array = URI.split('/');\n\n if (uriArray.length !== routeArray.length) {\n return;\n }\n\n const routeOptions: any = this.handlingParams(route.path);\n\n if (routeOptions.RouteString === URI && this.notfound) {\n return this.setRoute(route, routeOptions.params);\n }\n });\n }\n\n /**\n * @function handlingParams\n * @param {string} route\n * @returns {object}\n */\n private handlingParams = (route: string): object => {\n const uriArray = this.getURI().split('/');\n const routeArray = route.split('/');\n const params: Array = [];\n\n for (let i = 0; i < routeArray.length; i++) {\n if (routeArray[i].substr(0, 1) === ':') {\n if (uriArray[i] !== '') {\n params.push(uriArray[i]);\n }\n\n routeArray[i] = uriArray[i];\n }\n }\n\n return {\n params: params,\n RouteString: routeArray.join('/'),\n };\n }\n\n /**\n * @function run\n * @description Run the router and search for a route match\n * @param afterRouteCallback\n */\n public run = (afterRouteCallback?: any): void => {\n this.route = null;\n this.routeCall = null;\n this.params = [];\n this.notfound = true;\n\n const URI = this.getURI();\n const routes: Array = [];\n\n // Execute before middleware\n this.beforeMiddleware(this.beforeRouteMiddleware, this.beforeRouteMiddlewareFunc);\n\n this.routes.forEach(route => {\n if (route.paramsEnabled) {\n routes.push(route);\n this.handle(routes);\n } else if (route.path === URI) {\n this.setRoute(route);\n }\n });\n\n // If there's a route match, execute the callback\n if (this.notfound) {\n this.notFoundException();\n } else {\n this.routeCall.apply(null, this.params);\n }\n\n // Call after middleware\n if (afterRouteCallback != null) {\n this.afterRouteCallback = afterRouteCallback;\n this.afterRouteCallback.apply(null, []);\n } else if (this.afterRouteCallback != null) {\n this.afterRouteCallback.apply(null, []);\n }\n }\n\n /**\n * @function beforeMiddleware\n * @param {string} route\n * @param callback\n */\n private beforeMiddleware = (route: string, callback: any) => {\n route = route.split('#')[1] || route;\n\n if (callback != null) {\n if (route === '*') {\n return callback.apply(null, []);\n } else if (route === this.getURI()) {\n return callback.apply(null, []);\n }\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/leafeon.ts"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/leafeon.min.js b/dist/leafeon.min.js index 17028f5..217c6b2 100644 --- a/dist/leafeon.min.js +++ b/dist/leafeon.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.leafeon=e():t.leafeon=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";var o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}();Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(){var t=this;this.getURI=function(){return t.URI=t.formatPath(t.windowObj.location.hash)},this.setURI=function(e){t.windowObj.location.hash=e},this.formatPath=function(e){return""===e?"/":(e.match(/^(?:\/)?(?:\#)?(?:\/)?[a-zA-Z0-9\-_\/:]+/)[0]!==e&&t.exception("Path is not formated correctly."),e.replace(/^(?:\/)?(?:\#)?(?:\/)/,"/"))},this.exception=function(t){throw new TypeError(t)},this.windowListener=function(t){"undefined"!=typeof window&&(window.onhashchange=function(){t()})};var e={location:{href:"/#/",hash:"#/"}};this.windowObj="undefined"==typeof window?e:window,this.URI=this.getURI()}return t}(),a=function(t){function e(){var e=t.call(this)||this;return e.setErrorCallback=function(t){return e.notFoundCallback=t,e},e.notFoundException=function(){e.notFoundCallback.apply(null,[])},e.before=function(t,n){return e.beforeRouteMiddleware=t,e.beforeRouteMiddlewareFunc=n,e},e.add=function(t,n,o){var r=n.split("/"),a=!1,u=[];return r.forEach(function(t){":"===t.substr(0,1)&&(a=!0,u.push(t.substr(1,t.length)))}),e.paramsEnabled=a,n=n.split("#")[1]||n,e.routes.push({name:t,path:n,callback:o,paramsEnabled:a,params:u}),e},e.map=function(t,n,o){return o.forEach(function(o){e.add(t+o.name,n+e.formatPath(o.path),o.callback)}),e},e.fetchRoute=function(t,n){var o=e.routes.find(function(e){return e.name===t||e.path===t});if(void 0===o)return e.exception("Route "+t+" does not exist.");if(!o.paramsEnabled)return void e.setURI(o.path);n||e.exception('Error: route "'+t+'" requires some parameters. None specified.');var r=e.generateURL(o.path,n);e.setURI(r)},e.generateURL=function(t,e){var n=t;return Object.keys(e).forEach(function(o){var r=t.split("/").find(function(t){return t===":"+o});void 0!==r&&(n=n.replace(r,e[o]))}),n},e.setRoute=function(t,n){void 0===n&&(n=[]),e.route=t,e.routeCall=t.callback,e.params=n,e.notfound=!1},e.handle=function(t){var n=e.getURI();t.forEach(function(t){var o=t.path.split("/");if(n.split("/").length===o.length){var r=e.handlingParams(t.path);return r.RouteString===n&&e.notfound?e.setRoute(t,r.params):void 0}})},e.handlingParams=function(t){for(var n=e.getURI().split("/"),o=t.split("/"),r=[],a=0;a