diff --git a/dist/leafeon.js b/dist/leafeon.js index 56fed10..490bb6e 100644 --- a/dist/leafeon.js +++ b/dist/leafeon.js @@ -104,24 +104,14 @@ var RouterRequest = /** @class */ (function () { * @returns {string} */ this.getURI = function () { - if (typeof window !== 'undefined') { - return _this.URI = _this.formatPath(window.location.hash); - } - else { - return _this.URI = _this.formatPath(_this.windowObj.location.hash); - } + return _this.URI = _this.formatPath(_this.windowObj.location.hash); }; /** * @function setURI * @param route string */ this.setURI = function (route) { - if (typeof window !== 'undefined') { - window.location.hash = route; - } - else { - _this.windowObj.location.hash = route; - } + _this.windowObj.location.hash = route; }; /** * @function formatPath @@ -146,12 +136,12 @@ var RouterRequest = /** @class */ (function () { throw new TypeError(message); }; /** - * @function setURI + * @function windowListener * @param route string */ this.windowListener = function (callback) { if (typeof window !== 'undefined') { - window.onpopstate = function () { + window.onhashchange = function () { callback(); }; } @@ -343,6 +333,10 @@ var Router = /** @class */ (function (_super) { * @param afterRouteCallback */ _this.run = function (afterRouteCallback) { + _this.route = null; + _this.routeCall = null; + _this.params = []; + _this.notfound = true; var URI = _this.getURI(); var routes = []; // Execute before middleware @@ -391,13 +385,13 @@ var Router = /** @class */ (function (_super) { _this.notfound = true; // While a route has not match the URI, set page as not found _this.routes = []; _this.paramsEnabled = false; + _this.route = null; _this.params = []; _this.beforeRouteMiddleware = '*'; - _this.routeCall = function () { }; - _this.beforeRouteMiddlewareFunc = function () { }; - _this.afterRouteCallback = function () { }; - _this.route = {}; - _this.notFoundCallback = function () { }; + _this.routeCall = null; + _this.beforeRouteMiddlewareFunc = null; + _this.afterRouteCallback = null; + _this.notFoundCallback = null; _this.windowListener(_this.run); return _this; } diff --git a/dist/leafeon.js.map b/dist/leafeon.js.map index 573d8e5..0cff478 100644 --- a/dist/leafeon.js.map +++ b/dist/leafeon.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 44524b785f7520e395df","webpack:///./src/leafeon.ts"],"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cAAO,CAAC,CAAC;QAEjC,KAAI,CAAC,cAAc,CAAC,KAAI,CAAC,GAAG,CAAC,CAAC;;IAClC,CAAC;IAyPL,aAAC;AAAD,CAAC,CApR2B,aAAa,GAoRxC;AApRY,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 44524b785f7520e395df","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 if (typeof window !== 'undefined') {\n return this.URI = this.formatPath(window.location.hash);\n } else {\n return this.URI = this.formatPath(this.windowObj.location.hash);\n }\n }\n\n /**\n * @function setURI\n * @param route string\n */\n public setURI = (route: string): void => {\n if (typeof window !== 'undefined') {\n window.location.hash = route;\n } else {\n this.windowObj.location.hash = route;\n }\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 setURI\n * @param route string\n */\n public windowListener = (callback: Function): void => {\n if (typeof window !== 'undefined') {\n window.onpopstate = () => {\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.params = [];\n this.beforeRouteMiddleware = '*';\n this.routeCall = () => {};\n this.beforeRouteMiddlewareFunc = () => {};\n this.afterRouteCallback = () => {};\n this.route = {};\n this.notFoundCallback = () => {};\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 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 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;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KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;YAErC,IAAI,QAAQ,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 diff --git a/dist/leafeon.min.js b/dist/leafeon.min.js index 52fc21e..17028f5 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"undefined"!=typeof window?t.URI=t.formatPath(window.location.hash):t.URI=t.formatPath(t.windowObj.location.hash)},this.setURI=function(e){"undefined"!=typeof window?window.location.hash=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.onpopstate=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 never; /** - * @function setURI + * @function windowListener * @param route string */ windowListener: (callback: Function) => void; diff --git a/lib/leafeon.js b/lib/leafeon.js index e006ce5..e2425ac 100644 --- a/lib/leafeon.js +++ b/lib/leafeon.js @@ -21,24 +21,14 @@ var RouterRequest = /** @class */ (function () { * @returns {string} */ this.getURI = function () { - if (typeof window !== 'undefined') { - return _this.URI = _this.formatPath(window.location.hash); - } - else { - return _this.URI = _this.formatPath(_this.windowObj.location.hash); - } + return _this.URI = _this.formatPath(_this.windowObj.location.hash); }; /** * @function setURI * @param route string */ this.setURI = function (route) { - if (typeof window !== 'undefined') { - window.location.hash = route; - } - else { - _this.windowObj.location.hash = route; - } + _this.windowObj.location.hash = route; }; /** * @function formatPath @@ -63,12 +53,12 @@ var RouterRequest = /** @class */ (function () { throw new TypeError(message); }; /** - * @function setURI + * @function windowListener * @param route string */ this.windowListener = function (callback) { if (typeof window !== 'undefined') { - window.onpopstate = function () { + window.onhashchange = function () { callback(); }; } @@ -260,6 +250,10 @@ var Router = /** @class */ (function (_super) { * @param afterRouteCallback */ _this.run = function (afterRouteCallback) { + _this.route = null; + _this.routeCall = null; + _this.params = []; + _this.notfound = true; var URI = _this.getURI(); var routes = []; // Execute before middleware @@ -308,13 +302,13 @@ var Router = /** @class */ (function (_super) { _this.notfound = true; // While a route has not match the URI, set page as not found _this.routes = []; _this.paramsEnabled = false; + _this.route = null; _this.params = []; _this.beforeRouteMiddleware = '*'; - _this.routeCall = function () { }; - _this.beforeRouteMiddlewareFunc = function () { }; - _this.afterRouteCallback = function () { }; - _this.route = {}; - _this.notFoundCallback = function () { }; + _this.routeCall = null; + _this.beforeRouteMiddlewareFunc = null; + _this.afterRouteCallback = null; + _this.notFoundCallback = null; _this.windowListener(_this.run); return _this; } diff --git a/lib/leafeon.js.map b/lib/leafeon.js.map index 921db4a..1b61035 100644 --- a/lib/leafeon.js.map +++ b/lib/leafeon.js.map @@ -1 +1 @@ -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D,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;YAErC,IAAI,QAAQ,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,CAAA;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,AAzRD,CAA4B,aAAa,GAyRxC;AAzRY,wBAAM"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8b9f9bf..3c4b4fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2055,7 +2055,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2076,12 +2077,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2096,17 +2099,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2223,7 +2229,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2235,6 +2242,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2249,6 +2257,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2256,12 +2265,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2280,6 +2291,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2360,7 +2372,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2372,6 +2385,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2457,7 +2471,8 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2493,6 +2508,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2512,6 +2528,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2555,12 +2572,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -3804,6 +3823,7 @@ "version": "0.1.4", "bundled": true, "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -4128,7 +4148,8 @@ "is-buffer": { "version": "1.1.6", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "is-builtin-module": { "version": "1.0.0", @@ -4212,6 +4233,7 @@ "version": "3.2.2", "bundled": true, "dev": true, + "optional": true, "requires": { "is-buffer": "^1.1.5" } @@ -4258,7 +4280,8 @@ "longest": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "lru-cache": { "version": "4.1.3", @@ -4524,7 +4547,8 @@ "repeat-string": { "version": "1.6.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "require-directory": { "version": "2.1.1", diff --git a/package.json b/package.json index 0140e5d..2bb85d9 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "name": "leafeon", - "version": "2.1.16", + "version": "2.1.18", "description": "Client-sided and dependency-free Javascript routing library", "author": "Sundowndev", - "main": "dist/leafeon", + "main": "lib/leafeon", "types": "lib/leafeon.d.ts", "directories": { "src": "src" }, "scripts": { "build:ts": "rimraf lib dist && tsc", - "build:webpack": "rimraf dist && webpack && webpack --config webpack.config.min.js", + "build:webpack": "rimraf dist && webpack --config webpack.config.js && webpack --config webpack.config.min.js", "build": "npm run build:ts && npm run build:webpack", "test": "npm run lint && npm run test:unit", "test:unit": "mocha --compilers ts:ts-node/register \"test/**/*.spec.ts\" --exit", diff --git a/src/leafeon.ts b/src/leafeon.ts index 29e1acc..9f393b2 100644 --- a/src/leafeon.ts +++ b/src/leafeon.ts @@ -30,11 +30,7 @@ class RouterRequest { * @returns {string} */ public getURI = (): string => { - if (typeof window !== 'undefined') { - return this.URI = this.formatPath(window.location.hash); - } else { - return this.URI = this.formatPath(this.windowObj.location.hash); - } + return this.URI = this.formatPath(this.windowObj.location.hash); } /** @@ -42,11 +38,7 @@ class RouterRequest { * @param route string */ public setURI = (route: string): void => { - if (typeof window !== 'undefined') { - window.location.hash = route; - } else { - this.windowObj.location.hash = route; - } + this.windowObj.location.hash = route; } /** @@ -76,12 +68,12 @@ class RouterRequest { } /** - * @function setURI + * @function windowListener * @param route string */ public windowListener = (callback: Function): void => { if (typeof window !== 'undefined') { - window.onpopstate = () => { + window.onhashchange = () => { callback(); }; } @@ -111,13 +103,13 @@ export class Router extends RouterRequest { this.notfound = true; // While a route has not match the URI, set page as not found this.routes = []; this.paramsEnabled = false; + this.route = null; this.params = []; this.beforeRouteMiddleware = '*'; - this.routeCall = () => {}; - this.beforeRouteMiddlewareFunc = () => {}; - this.afterRouteCallback = () => {}; - this.route = {}; - this.notFoundCallback = () => {}; + this.routeCall = null; + this.beforeRouteMiddlewareFunc = null; + this.afterRouteCallback = null; + this.notFoundCallback = null; this.windowListener(this.run); } @@ -322,6 +314,11 @@ export class Router extends RouterRequest { * @param afterRouteCallback */ public run = (afterRouteCallback?: any): void => { + this.route = null; + this.routeCall = null; + this.params = []; + this.notfound = true; + const URI = this.getURI(); const routes: Array = [];