diff --git a/dist/router.js b/dist/router.js index 4ef663c..01aa85c 100644 --- a/dist/router.js +++ b/dist/router.js @@ -1,6 +1,6 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c {\n return {\n hash: window.location.hash,\n href: window.location.href\n };\n },\n set: (location: string) => {\n window.history.pushState(null, null, location);\n }\n });\n }\n\n watch () {\n if (this.running) {\n if (this.client && this.client.onNavigate) {\n this.client.onNavigate({\n router: this,\n location: this.location,\n previous: this.previous,\n });\n }\n }\n }\n\n start () {\n if (!this.running) {\n if (this.client && this.client.onStart) {\n this.client.onStart({\n router: this,\n });\n }\n window.addEventListener('hashchange', this.watch);\n }\n }\n\n stop () {\n if (this.running) {\n this.running = false;\n if (this.client && this.client.onStop) {\n this.client.onStop({\n router: this,\n });\n }\n window.removeEventListener('hashchange', this.watch);\n }\n }\n}\n"]} \ No newline at end of file +{"version":3,"sources":["config.ts","router.ts"],"names":[],"mappings":";AAEa,aAAA,OAAA,eAAA,QAAA,aAAA,CAAA,OAAA,IAAA,QAAA,OAAkB,CAC7B,SAAU,CACR,KAAM,KACN,QAAS,KAEX,MAAO,CACL,SAAU,CACR,QAAS,eACT,KAAM,kCAER,OAAQ,CACN,UAAW,2BAGf,UAAW,CACT,MAAO,GACP,UAAW;;ACiDf,aAAA,OAAA,eAAA,QAAA,aAAA,CAAA,OAAA,IAhEA,IAAA,EAAA,QAAA,YAEA,EAAA,WAQE,SAAA,EAAa,GACN,KAAA,OAAS,EAAK,QAAU,EAAA,OACxB,KAAA,OAAS,EAAK,OACd,KAAA,SAAU,EAEf,OAAO,eAAe,KAAM,WAAY,CACtC,IAAK,WACI,MAAA,CACL,KAAM,OAAO,SAAS,KACtB,KAAM,OAAO,SAAS,OAG1B,IAAK,SAAC,GACJ,OAAO,QAAQ,UAAU,KAAM,KAAM,MAuC7C,OAlCE,EAAA,UAAA,MAAA,WACM,KAAK,SACH,KAAK,QAAU,KAAK,OAAO,YACxB,KAAA,OAAO,WAAW,CACrB,OAAQ,KACR,SAAU,KAAK,SACf,SAAU,KAAK,YAMvB,EAAA,UAAA,MAAA,WACO,KAAK,UACJ,KAAK,QAAU,KAAK,OAAO,SACxB,KAAA,OAAO,QAAQ,CAClB,OAAQ,OAGZ,OAAO,iBAAiB,aAAc,KAAK,SAI/C,EAAA,UAAA,KAAA,WACM,KAAK,UACF,KAAA,SAAU,EACX,KAAK,QAAU,KAAK,OAAO,QACxB,KAAA,OAAO,OAAO,CACjB,OAAQ,OAGZ,OAAO,oBAAoB,aAAc,KAAK,SAGpD,EA5DA,GA8DA,OAAO,QAAU","file":"router.js","sourceRoot":"../src","sourcesContent":["import { IConfig } from './interfaces/config';\n\nexport const Config: IConfig = {\n settings: {\n hash: '#!',\n timeout: 5000\n },\n regex: {\n settings: {\n default: /[a-zA-Z0-9]/g,\n href: /(www|http:|https:)+[^\\s]+[\\w]/g,\n },\n routes: {\n variables: /(:(?!qargs)[a-zA-Z]*)/g\n }\n },\n intervals: {\n start: 10,\n fragments: 250\n }\n};\n","import { IRouterClient, IRouterTools, IRouterArgs, IRouter } from './interfaces/router';\nimport { IRouterLocation } from './interfaces/event';\nimport { IConfig } from './interfaces/config';\nimport { Config } from './config';\n\nclass Router implements IRouter {\n public config: IConfig;\n public location: IRouterLocation;\n public previous: IRouterLocation;\n public tools: IRouterTools;\n public running: boolean;\n public client?: IRouterClient;\n\n constructor (args: IRouterArgs) {\n this.config = args.config || Config;\n this.client = args.client;\n this.running = false;\n\n Object.defineProperty(this, 'location', {\n get: () => {\n return {\n hash: window.location.hash,\n href: window.location.href\n };\n },\n set: (location: string) => {\n window.history.pushState(null, null, location);\n }\n });\n }\n\n watch () {\n if (this.running) {\n if (this.client && this.client.onNavigate) {\n this.client.onNavigate({\n router: this,\n location: this.location,\n previous: this.previous,\n });\n }\n }\n }\n\n start () {\n if (!this.running) {\n if (this.client && this.client.onStart) {\n this.client.onStart({\n router: this,\n });\n }\n window.addEventListener('hashchange', this.watch);\n }\n }\n\n stop () {\n if (this.running) {\n this.running = false;\n if (this.client && this.client.onStop) {\n this.client.onStop({\n router: this,\n });\n }\n window.removeEventListener('hashchange', this.watch);\n }\n }\n}\n\nmodule.exports = Router;\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 61132e2..b2a11f1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "lint": "npx tslint src/**.ts && npx eslint __test__/**.js", - "bundle": "npx parcel build src/router.ts", + "bundle": "npx parcel build src/router.ts --global Router --target browser", "test": "node_modules/.bin/jest --coverage", "build": "npm run lint && npm run bundle && npm run test" }, diff --git a/src/router.ts b/src/router.ts index 555f4f2..3f13bec 100644 --- a/src/router.ts +++ b/src/router.ts @@ -3,7 +3,7 @@ import { IRouterLocation } from './interfaces/event'; import { IConfig } from './interfaces/config'; import { Config } from './config'; -export class Router implements IRouter { +class Router implements IRouter { public config: IConfig; public location: IRouterLocation; public previous: IRouterLocation; @@ -64,3 +64,5 @@ export class Router implements IRouter { } } } + +module.exports = Router;