+1
| {"presets": ["es2015"]} |
| { | ||
| // Use IntelliSense to learn about possible Node.js debug attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "node", | ||
| "request": "launch", | ||
| "name": "Launch Program", | ||
| "program": "${workspaceRoot}/dist/grapnel.js", | ||
| "cwd": "${workspaceRoot}", | ||
| "outFiles": [], | ||
| "sourceMaps": true | ||
| }, | ||
| { | ||
| "type": "node", | ||
| "request": "launch", | ||
| "name": "Launch Debug", | ||
| "program": "${workspaceRoot}/test/index.js", | ||
| "cwd": "${workspaceRoot}", | ||
| "outFiles": [], | ||
| "sourceMaps": true | ||
| }, | ||
| { | ||
| "type": "node", | ||
| "request": "attach", | ||
| "name": "Attach to Process", | ||
| "port": 5858, | ||
| "outFiles": [], | ||
| "sourceMaps": true | ||
| } | ||
| ] | ||
| } |
| { | ||
| // See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
| // for the documentation about the tasks.json format | ||
| "version": "0.1.0", | ||
| "command": "tsc", | ||
| "isShellCommand": true, | ||
| "args": ["-w", "-p", "."], | ||
| "showOutput": "silent", | ||
| "isWatching": true, | ||
| "problemMatcher": "$tsc-watch" | ||
| } |
+209
| "use strict"; | ||
| /**** | ||
| * Grapnel | ||
| * https://github.com/baseprime/grapnel | ||
| * | ||
| * @author Greg Sabia Tucker <greg@narrowlabs.com> | ||
| * @link http://basepri.me | ||
| * | ||
| * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const events_1 = require("events"); | ||
| const route_1 = require("./route"); | ||
| class Grapnel extends events_1.EventEmitter { | ||
| constructor(options) { | ||
| super(); | ||
| this._maxListeners = Infinity; | ||
| this.options = {}; | ||
| this.defaults = { | ||
| root: '', | ||
| target: ('object' === typeof window) ? window : {}, | ||
| isWindow: ('object' === typeof window), | ||
| pushState: false, | ||
| hashBang: false | ||
| }; | ||
| this.options = Object.assign({}, this.defaults, options); | ||
| if ('object' === typeof this.options.target && 'function' === typeof this.options.target.addEventListener) { | ||
| this.options.target.addEventListener('hashchange', () => { | ||
| this.emit('hashchange'); | ||
| }); | ||
| this.options.target.addEventListener('popstate', (e) => { | ||
| // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome | ||
| if (this.state && this.state.previousState === null) | ||
| return false; | ||
| this.emit('navigate'); | ||
| }); | ||
| } | ||
| } | ||
| add(routePath) { | ||
| let middleware = Array.prototype.slice.call(arguments, 1, -1); | ||
| let handler = Array.prototype.slice.call(arguments, -1)[0]; | ||
| let fullPath = this.options.root + routePath; | ||
| let route = new route_1.default(fullPath); | ||
| let routeHandler = (function () { | ||
| // Build request parameters | ||
| let req = route.parse(this.path()); | ||
| // Check if matches are found | ||
| if (req.match) { | ||
| // Match found | ||
| let extra = { | ||
| req, | ||
| route: fullPath, | ||
| params: req.params, | ||
| regex: req.match | ||
| }; | ||
| // Create call stack -- add middleware first, then handler | ||
| let stack = new MiddlewareStack(this, extra).enqueue(middleware.concat(handler)); | ||
| // emit main event | ||
| this.emit('match', stack, req); | ||
| // Continue? | ||
| if (!stack.runCallback) | ||
| return this; | ||
| // Previous state becomes current state | ||
| stack.previousState = this.state; | ||
| // Save new state | ||
| this.state = stack; | ||
| // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events | ||
| if (stack.parent() && stack.parent().propagateEvent === false) { | ||
| stack.propagateEvent = false; | ||
| return this; | ||
| } | ||
| // Call handler | ||
| stack.callback(); | ||
| } | ||
| // Returns self | ||
| return this; | ||
| }).bind(this); | ||
| // Event name | ||
| let eventName = (!this.options.pushState && this.options.isWindow) ? 'hashchange' : 'navigate'; | ||
| // Invoke when route is defined, and once again when app navigates | ||
| return routeHandler().on(eventName, routeHandler); | ||
| } | ||
| get() { | ||
| return this.add.apply(this, arguments); | ||
| } | ||
| trigger() { | ||
| return this.emit.apply(this, arguments); | ||
| } | ||
| bind() { | ||
| // Backwards compatibility with older versions which mimed jQuery's bind() | ||
| return this.on.apply(this, arguments); | ||
| } | ||
| context(context) { | ||
| let middleware = Array.prototype.slice.call(arguments, 1); | ||
| return (...args) => { | ||
| let value = args[0]; | ||
| let subMiddleware = (args.length > 2) ? Array.prototype.slice.call(args, 1, -1) : []; | ||
| let handler = Array.prototype.slice.call(args, -1)[0]; | ||
| let prefix = (context.slice(-1) !== '/' && value !== '/' && value !== '') ? context + '/' : context; | ||
| let path = (value.substr(0, 1) !== '/') ? value : value.substr(1); | ||
| let pattern = prefix + path; | ||
| return this.add.apply(this, [pattern].concat(middleware).concat(subMiddleware).concat([handler])); | ||
| }; | ||
| } | ||
| navigate(path, options) { | ||
| this.path(path, options).emit('navigate'); | ||
| return this; | ||
| } | ||
| path(pathname, options = {}) { | ||
| let root = this.options.target; | ||
| let frag = undefined; | ||
| let pageName = options.title; | ||
| if ('string' === typeof pathname) { | ||
| // Set path | ||
| if (this.options.pushState && 'function' === typeof root.history.pushState) { | ||
| let state = options.state || root.history.state; | ||
| frag = (this.options.root) ? (this.options.root + pathname) : pathname; | ||
| root.history.pushState(state, pageName, frag); | ||
| } | ||
| else if (root.location) { | ||
| let _frag = (this.options.root) ? (this.options.root + pathname) : pathname; | ||
| root.location.hash = (this.options.hashBang ? '!' : '') + _frag; | ||
| } | ||
| else { | ||
| root.pathname = pathname || ''; | ||
| } | ||
| return this; | ||
| } | ||
| else if ('undefined' === typeof pathname) { | ||
| // Get path | ||
| return (root.location && root.location.pathname) ? root.location.pathname : (root.pathname || ''); | ||
| } | ||
| else if (pathname === false) { | ||
| // Clear path | ||
| if (this.options.pushState && 'function' === typeof root.history.pushState) { | ||
| let state = options.state || root.history.state; | ||
| root.history.pushState(state, pageName, this.options.root || '/'); | ||
| } | ||
| else if (root.location) { | ||
| root.location.hash = (this.options.hashBang) ? '!' : ''; | ||
| } | ||
| return this; | ||
| } | ||
| } | ||
| static listen(...args) { | ||
| let opts; | ||
| let routes; | ||
| if (args[0] && args[1]) { | ||
| opts = args[0]; | ||
| routes = args[1]; | ||
| } | ||
| else { | ||
| routes = args[0]; | ||
| } | ||
| // Return a new Grapnel instance | ||
| return (function () { | ||
| // TODO: Accept multi-level routes | ||
| for (let key in routes) { | ||
| this.add.call(this, key, routes[key]); | ||
| } | ||
| return this; | ||
| }).call(new Grapnel(opts || {})); | ||
| } | ||
| static toString() { | ||
| return this.name; | ||
| } | ||
| } | ||
| class MiddlewareStack { | ||
| constructor(router, extendObj) { | ||
| this.runCallback = true; | ||
| this.callbackRan = true; | ||
| this.propagateEvent = true; | ||
| this.stack = MiddlewareStack.global.slice(0); | ||
| this.router = router; | ||
| this.value = router.path(); | ||
| Object.assign(this, extendObj); | ||
| return this; | ||
| } | ||
| preventDefault() { | ||
| this.runCallback = false; | ||
| } | ||
| stopPropagation() { | ||
| this.propagateEvent = false; | ||
| } | ||
| parent() { | ||
| let hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value); | ||
| return (hasParentEvents) ? this.previousState : false; | ||
| } | ||
| callback() { | ||
| this.callbackRan = true; | ||
| this.timeStamp = Date.now(); | ||
| this.next(); | ||
| } | ||
| enqueue(handler, atIndex) { | ||
| let handlers = (!Array.isArray(handler)) ? [handler] : ((atIndex < handler.length) ? handler.reverse() : handler); | ||
| while (handlers.length) { | ||
| this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift()); | ||
| } | ||
| return this; | ||
| } | ||
| next() { | ||
| return this.stack.shift().call(this.router, this.req, this, () => this.next()); | ||
| } | ||
| } | ||
| MiddlewareStack.global = []; | ||
| Grapnel.MiddlewareStack = MiddlewareStack; | ||
| Grapnel.Route = route_1.default; | ||
| exports = module.exports = Grapnel; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;EAQE;;AAEF,mCAAsC;AACtC,mCAA6C;AAE7C,aAAc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,GAAG,OAAO,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| class Route { | ||
| constructor(pathname, keys, sensitive, strict) { | ||
| this.keys = []; | ||
| this.strict = false; | ||
| this.sensitive = false; | ||
| this.path = pathname; | ||
| this.regex = this.create(); | ||
| } | ||
| parse(pathname) { | ||
| let match = pathname.match(this.regex); | ||
| let req = { | ||
| match, | ||
| params: {}, | ||
| keys: this.keys, | ||
| matches: (match || []).slice(1), | ||
| }; | ||
| // Build parameters | ||
| req.matches.forEach((value, i) => { | ||
| var key = (this.keys[i] && this.keys[i].name) ? this.keys[i].name : i; | ||
| // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched | ||
| req.params[key] = (value) ? decodeURIComponent(value) : undefined; | ||
| }); | ||
| return req; | ||
| } | ||
| create() { | ||
| if (this.path instanceof RegExp) | ||
| return this.path; | ||
| if (this.path instanceof Array) | ||
| this.path = '(' + this.path.join('|') + ')'; | ||
| // Build route RegExp | ||
| let newPath = this.path.concat(this.strict ? '' : '/?') | ||
| .replace(/\/\(/g, '(?:/') | ||
| .replace(/\+/g, '__plus__') | ||
| .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, (_, slash, format, key, capture, optional) => { | ||
| this.keys.push({ | ||
| name: key, | ||
| optional: !!optional | ||
| }); | ||
| slash = slash || ''; | ||
| return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); | ||
| }) | ||
| .replace(/([\/.])/g, '\\$1') | ||
| .replace(/__plus__/g, '(.+)') | ||
| .replace(/\*/g, '(.*)'); | ||
| return new RegExp('^' + newPath + '$', this.sensitive ? '' : 'i'); | ||
| } | ||
| } | ||
| exports.default = Route; | ||
| //# sourceMappingURL=route.js.map |
| {"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":";;AACA;IAOI,YAAY,QAAa,EAAE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C,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACtE,CAAC;CACJ;AApDD,wBAoDC"} |
+681
| /*! | ||
| * Grapnel | ||
| * https://github.com/baseprime/grapnel.git | ||
| * | ||
| * @author Greg Sabia Tucker <greg@narrowlabs.com> | ||
| * @link http://basepri.me | ||
| * @version 0.7.0 | ||
| * | ||
| * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT | ||
| */ | ||
| var Grapnel = | ||
| /******/ (function(modules) { // webpackBootstrap | ||
| /******/ // The module cache | ||
| /******/ var installedModules = {}; | ||
| /******/ | ||
| /******/ // The require function | ||
| /******/ function __webpack_require__(moduleId) { | ||
| /******/ | ||
| /******/ // Check if module is in cache | ||
| /******/ if(installedModules[moduleId]) | ||
| /******/ return installedModules[moduleId].exports; | ||
| /******/ | ||
| /******/ // Create a new module (and put it into the cache) | ||
| /******/ var module = installedModules[moduleId] = { | ||
| /******/ exports: {}, | ||
| /******/ id: moduleId, | ||
| /******/ loaded: false | ||
| /******/ }; | ||
| /******/ | ||
| /******/ // Execute the module function | ||
| /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
| /******/ | ||
| /******/ // Flag the module as loaded | ||
| /******/ module.loaded = true; | ||
| /******/ | ||
| /******/ // Return the exports of the module | ||
| /******/ return module.exports; | ||
| /******/ } | ||
| /******/ | ||
| /******/ | ||
| /******/ // expose the modules object (__webpack_modules__) | ||
| /******/ __webpack_require__.m = modules; | ||
| /******/ | ||
| /******/ // expose the module cache | ||
| /******/ __webpack_require__.c = installedModules; | ||
| /******/ | ||
| /******/ // __webpack_public_path__ | ||
| /******/ __webpack_require__.p = ""; | ||
| /******/ | ||
| /******/ // Load entry module and return exports | ||
| /******/ return __webpack_require__(0); | ||
| /******/ }) | ||
| /************************************************************************/ | ||
| /******/ ([ | ||
| /* 0 */ | ||
| /***/ (function(module, exports, __webpack_require__) { | ||
| "use strict"; | ||
| /**** | ||
| * Grapnel | ||
| * https://github.com/baseprime/grapnel | ||
| * | ||
| * @author Greg Sabia Tucker <greg@narrowlabs.com> | ||
| * @link http://basepri.me | ||
| * | ||
| * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT | ||
| */ | ||
| var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var events_1 = __webpack_require__(1); | ||
| var route_1 = __webpack_require__(2); | ||
| var Grapnel = function (_events_1$EventEmitte) { | ||
| _inherits(Grapnel, _events_1$EventEmitte); | ||
| function Grapnel(options) { | ||
| _classCallCheck(this, Grapnel); | ||
| var _this = _possibleConstructorReturn(this, (Grapnel.__proto__ || Object.getPrototypeOf(Grapnel)).call(this)); | ||
| _this._maxListeners = Infinity; | ||
| _this.options = {}; | ||
| _this.defaults = { | ||
| root: '', | ||
| target: 'object' === (typeof window === "undefined" ? "undefined" : _typeof(window)) ? window : {}, | ||
| isWindow: 'object' === (typeof window === "undefined" ? "undefined" : _typeof(window)), | ||
| pushState: false, | ||
| hashBang: false | ||
| }; | ||
| _this.options = Object.assign({}, _this.defaults, options); | ||
| if ('object' === _typeof(_this.options.target) && 'function' === typeof _this.options.target.addEventListener) { | ||
| _this.options.target.addEventListener('hashchange', function () { | ||
| _this.emit('hashchange'); | ||
| }); | ||
| _this.options.target.addEventListener('popstate', function (e) { | ||
| // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome | ||
| if (_this.state && _this.state.previousState === null) return false; | ||
| _this.emit('navigate'); | ||
| }); | ||
| } | ||
| return _this; | ||
| } | ||
| _createClass(Grapnel, [{ | ||
| key: "add", | ||
| value: function add(routePath) { | ||
| var middleware = Array.prototype.slice.call(arguments, 1, -1); | ||
| var handler = Array.prototype.slice.call(arguments, -1)[0]; | ||
| var fullPath = this.options.root + routePath; | ||
| var route = new route_1.default(fullPath); | ||
| var routeHandler = function () { | ||
| // Build request parameters | ||
| var req = route.parse(this.path()); | ||
| // Check if matches are found | ||
| if (req.match) { | ||
| // Match found | ||
| var extra = { | ||
| req: req, | ||
| route: fullPath, | ||
| params: req.params, | ||
| regex: req.match | ||
| }; | ||
| // Create call stack -- add middleware first, then handler | ||
| var stack = new MiddlewareStack(this, extra).enqueue(middleware.concat(handler)); | ||
| // emit main event | ||
| this.emit('match', stack, req); | ||
| // Continue? | ||
| if (!stack.runCallback) return this; | ||
| // Previous state becomes current state | ||
| stack.previousState = this.state; | ||
| // Save new state | ||
| this.state = stack; | ||
| // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events | ||
| if (stack.parent() && stack.parent().propagateEvent === false) { | ||
| stack.propagateEvent = false; | ||
| return this; | ||
| } | ||
| // Call handler | ||
| stack.callback(); | ||
| } | ||
| // Returns self | ||
| return this; | ||
| }.bind(this); | ||
| // Event name | ||
| var eventName = !this.options.pushState && this.options.isWindow ? 'hashchange' : 'navigate'; | ||
| // Invoke when route is defined, and once again when app navigates | ||
| return routeHandler().on(eventName, routeHandler); | ||
| } | ||
| }, { | ||
| key: "get", | ||
| value: function get() { | ||
| return this.add.apply(this, arguments); | ||
| } | ||
| }, { | ||
| key: "trigger", | ||
| value: function trigger() { | ||
| return this.emit.apply(this, arguments); | ||
| } | ||
| }, { | ||
| key: "bind", | ||
| value: function bind() { | ||
| // Backwards compatibility with older versions which mimed jQuery's bind() | ||
| return this.on.apply(this, arguments); | ||
| } | ||
| }, { | ||
| key: "context", | ||
| value: function context(_context) { | ||
| var _this2 = this; | ||
| var middleware = Array.prototype.slice.call(arguments, 1); | ||
| return function () { | ||
| for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
| args[_key] = arguments[_key]; | ||
| } | ||
| var value = args[0]; | ||
| var subMiddleware = args.length > 2 ? Array.prototype.slice.call(args, 1, -1) : []; | ||
| var handler = Array.prototype.slice.call(args, -1)[0]; | ||
| var prefix = _context.slice(-1) !== '/' && value !== '/' && value !== '' ? _context + '/' : _context; | ||
| var path = value.substr(0, 1) !== '/' ? value : value.substr(1); | ||
| var pattern = prefix + path; | ||
| return _this2.add.apply(_this2, [pattern].concat(middleware).concat(subMiddleware).concat([handler])); | ||
| }; | ||
| } | ||
| }, { | ||
| key: "navigate", | ||
| value: function navigate(path, options) { | ||
| this.path(path, options).emit('navigate'); | ||
| return this; | ||
| } | ||
| }, { | ||
| key: "path", | ||
| value: function path(pathname) { | ||
| var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
| var root = this.options.target; | ||
| var frag = undefined; | ||
| var pageName = options.title; | ||
| if ('string' === typeof pathname) { | ||
| // Set path | ||
| if (this.options.pushState && 'function' === typeof root.history.pushState) { | ||
| var state = options.state || root.history.state; | ||
| frag = this.options.root ? this.options.root + pathname : pathname; | ||
| root.history.pushState(state, pageName, frag); | ||
| } else if (root.location) { | ||
| var _frag = this.options.root ? this.options.root + pathname : pathname; | ||
| root.location.hash = (this.options.hashBang ? '!' : '') + _frag; | ||
| } else { | ||
| root.pathname = pathname || ''; | ||
| } | ||
| return this; | ||
| } else if ('undefined' === typeof pathname) { | ||
| // Get path | ||
| return root.location && root.location.pathname ? root.location.pathname : root.pathname || ''; | ||
| } else if (pathname === false) { | ||
| // Clear path | ||
| if (this.options.pushState && 'function' === typeof root.history.pushState) { | ||
| var _state = options.state || root.history.state; | ||
| root.history.pushState(_state, pageName, this.options.root || '/'); | ||
| } else if (root.location) { | ||
| root.location.hash = this.options.hashBang ? '!' : ''; | ||
| } | ||
| return this; | ||
| } | ||
| } | ||
| }], [{ | ||
| key: "listen", | ||
| value: function listen() { | ||
| var opts = void 0; | ||
| var routes = void 0; | ||
| if ((arguments.length <= 0 ? undefined : arguments[0]) && (arguments.length <= 1 ? undefined : arguments[1])) { | ||
| opts = arguments.length <= 0 ? undefined : arguments[0]; | ||
| routes = arguments.length <= 1 ? undefined : arguments[1]; | ||
| } else { | ||
| routes = arguments.length <= 0 ? undefined : arguments[0]; | ||
| } | ||
| // Return a new Grapnel instance | ||
| return function () { | ||
| // TODO: Accept multi-level routes | ||
| for (var key in routes) { | ||
| this.add.call(this, key, routes[key]); | ||
| } | ||
| return this; | ||
| }.call(new Grapnel(opts || {})); | ||
| } | ||
| }, { | ||
| key: "toString", | ||
| value: function toString() { | ||
| return this.name; | ||
| } | ||
| }]); | ||
| return Grapnel; | ||
| }(events_1.EventEmitter); | ||
| var MiddlewareStack = function () { | ||
| function MiddlewareStack(router, extendObj) { | ||
| _classCallCheck(this, MiddlewareStack); | ||
| this.runCallback = true; | ||
| this.callbackRan = true; | ||
| this.propagateEvent = true; | ||
| this.stack = MiddlewareStack.global.slice(0); | ||
| this.router = router; | ||
| this.value = router.path(); | ||
| Object.assign(this, extendObj); | ||
| return this; | ||
| } | ||
| _createClass(MiddlewareStack, [{ | ||
| key: "preventDefault", | ||
| value: function preventDefault() { | ||
| this.runCallback = false; | ||
| } | ||
| }, { | ||
| key: "stopPropagation", | ||
| value: function stopPropagation() { | ||
| this.propagateEvent = false; | ||
| } | ||
| }, { | ||
| key: "parent", | ||
| value: function parent() { | ||
| var hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value); | ||
| return hasParentEvents ? this.previousState : false; | ||
| } | ||
| }, { | ||
| key: "callback", | ||
| value: function callback() { | ||
| this.callbackRan = true; | ||
| this.timeStamp = Date.now(); | ||
| this.next(); | ||
| } | ||
| }, { | ||
| key: "enqueue", | ||
| value: function enqueue(handler, atIndex) { | ||
| var handlers = !Array.isArray(handler) ? [handler] : atIndex < handler.length ? handler.reverse() : handler; | ||
| while (handlers.length) { | ||
| this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift()); | ||
| } | ||
| return this; | ||
| } | ||
| }, { | ||
| key: "next", | ||
| value: function next() { | ||
| var _this3 = this; | ||
| return this.stack.shift().call(this.router, this.req, this, function () { | ||
| return _this3.next(); | ||
| }); | ||
| } | ||
| }]); | ||
| return MiddlewareStack; | ||
| }(); | ||
| MiddlewareStack.global = []; | ||
| Grapnel.MiddlewareStack = MiddlewareStack; | ||
| Grapnel.Route = route_1.default; | ||
| exports = module.exports = Grapnel; | ||
| //# sourceMappingURL=index.js.map | ||
| /***/ }), | ||
| /* 1 */ | ||
| /***/ (function(module, exports) { | ||
| 'use strict'; | ||
| var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
| // Copyright Joyent, Inc. and other Node contributors. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a | ||
| // copy of this software and associated documentation files (the | ||
| // "Software"), to deal in the Software without restriction, including | ||
| // without limitation the rights to use, copy, modify, merge, publish, | ||
| // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
| // persons to whom the Software is furnished to do so, subject to the | ||
| // following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included | ||
| // in all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
| // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
| // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
| // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| function EventEmitter() { | ||
| this._events = this._events || {}; | ||
| this._maxListeners = this._maxListeners || undefined; | ||
| } | ||
| module.exports = EventEmitter; | ||
| // Backwards-compat with node 0.10.x | ||
| EventEmitter.EventEmitter = EventEmitter; | ||
| EventEmitter.prototype._events = undefined; | ||
| EventEmitter.prototype._maxListeners = undefined; | ||
| // By default EventEmitters will print a warning if more than 10 listeners are | ||
| // added to it. This is a useful default which helps finding memory leaks. | ||
| EventEmitter.defaultMaxListeners = 10; | ||
| // Obviously not all Emitters should be limited to 10. This function allows | ||
| // that to be increased. Set to zero for unlimited. | ||
| EventEmitter.prototype.setMaxListeners = function (n) { | ||
| if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number'); | ||
| this._maxListeners = n; | ||
| return this; | ||
| }; | ||
| EventEmitter.prototype.emit = function (type) { | ||
| var er, handler, len, args, i, listeners; | ||
| if (!this._events) this._events = {}; | ||
| // If there is no 'error' event listener then throw. | ||
| if (type === 'error') { | ||
| if (!this._events.error || isObject(this._events.error) && !this._events.error.length) { | ||
| er = arguments[1]; | ||
| if (er instanceof Error) { | ||
| throw er; // Unhandled 'error' event | ||
| } else { | ||
| // At least give some kind of context to the user | ||
| var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); | ||
| err.context = er; | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| handler = this._events[type]; | ||
| if (isUndefined(handler)) return false; | ||
| if (isFunction(handler)) { | ||
| switch (arguments.length) { | ||
| // fast cases | ||
| case 1: | ||
| handler.call(this); | ||
| break; | ||
| case 2: | ||
| handler.call(this, arguments[1]); | ||
| break; | ||
| case 3: | ||
| handler.call(this, arguments[1], arguments[2]); | ||
| break; | ||
| // slower | ||
| default: | ||
| args = Array.prototype.slice.call(arguments, 1); | ||
| handler.apply(this, args); | ||
| } | ||
| } else if (isObject(handler)) { | ||
| args = Array.prototype.slice.call(arguments, 1); | ||
| listeners = handler.slice(); | ||
| len = listeners.length; | ||
| for (i = 0; i < len; i++) { | ||
| listeners[i].apply(this, args); | ||
| } | ||
| } | ||
| return true; | ||
| }; | ||
| EventEmitter.prototype.addListener = function (type, listener) { | ||
| var m; | ||
| if (!isFunction(listener)) throw TypeError('listener must be a function'); | ||
| if (!this._events) this._events = {}; | ||
| // To avoid recursion in the case that type === "newListener"! Before | ||
| // adding it to the listeners, first emit "newListener". | ||
| if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener); | ||
| if (!this._events[type]) | ||
| // Optimize the case of one listener. Don't need the extra array object. | ||
| this._events[type] = listener;else if (isObject(this._events[type])) | ||
| // If we've already got an array, just append. | ||
| this._events[type].push(listener);else | ||
| // Adding the second element, need to change to array. | ||
| this._events[type] = [this._events[type], listener]; | ||
| // Check for listener leak | ||
| if (isObject(this._events[type]) && !this._events[type].warned) { | ||
| if (!isUndefined(this._maxListeners)) { | ||
| m = this._maxListeners; | ||
| } else { | ||
| m = EventEmitter.defaultMaxListeners; | ||
| } | ||
| if (m && m > 0 && this._events[type].length > m) { | ||
| this._events[type].warned = true; | ||
| console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length); | ||
| if (typeof console.trace === 'function') { | ||
| // not supported in IE 10 | ||
| console.trace(); | ||
| } | ||
| } | ||
| } | ||
| return this; | ||
| }; | ||
| EventEmitter.prototype.on = EventEmitter.prototype.addListener; | ||
| EventEmitter.prototype.once = function (type, listener) { | ||
| if (!isFunction(listener)) throw TypeError('listener must be a function'); | ||
| var fired = false; | ||
| function g() { | ||
| this.removeListener(type, g); | ||
| if (!fired) { | ||
| fired = true; | ||
| listener.apply(this, arguments); | ||
| } | ||
| } | ||
| g.listener = listener; | ||
| this.on(type, g); | ||
| return this; | ||
| }; | ||
| // emits a 'removeListener' event iff the listener was removed | ||
| EventEmitter.prototype.removeListener = function (type, listener) { | ||
| var list, position, length, i; | ||
| if (!isFunction(listener)) throw TypeError('listener must be a function'); | ||
| if (!this._events || !this._events[type]) return this; | ||
| list = this._events[type]; | ||
| length = list.length; | ||
| position = -1; | ||
| if (list === listener || isFunction(list.listener) && list.listener === listener) { | ||
| delete this._events[type]; | ||
| if (this._events.removeListener) this.emit('removeListener', type, listener); | ||
| } else if (isObject(list)) { | ||
| for (i = length; i-- > 0;) { | ||
| if (list[i] === listener || list[i].listener && list[i].listener === listener) { | ||
| position = i; | ||
| break; | ||
| } | ||
| } | ||
| if (position < 0) return this; | ||
| if (list.length === 1) { | ||
| list.length = 0; | ||
| delete this._events[type]; | ||
| } else { | ||
| list.splice(position, 1); | ||
| } | ||
| if (this._events.removeListener) this.emit('removeListener', type, listener); | ||
| } | ||
| return this; | ||
| }; | ||
| EventEmitter.prototype.removeAllListeners = function (type) { | ||
| var key, listeners; | ||
| if (!this._events) return this; | ||
| // not listening for removeListener, no need to emit | ||
| if (!this._events.removeListener) { | ||
| if (arguments.length === 0) this._events = {};else if (this._events[type]) delete this._events[type]; | ||
| return this; | ||
| } | ||
| // emit removeListener for all listeners on all events | ||
| if (arguments.length === 0) { | ||
| for (key in this._events) { | ||
| if (key === 'removeListener') continue; | ||
| this.removeAllListeners(key); | ||
| } | ||
| this.removeAllListeners('removeListener'); | ||
| this._events = {}; | ||
| return this; | ||
| } | ||
| listeners = this._events[type]; | ||
| if (isFunction(listeners)) { | ||
| this.removeListener(type, listeners); | ||
| } else if (listeners) { | ||
| // LIFO order | ||
| while (listeners.length) { | ||
| this.removeListener(type, listeners[listeners.length - 1]); | ||
| } | ||
| } | ||
| delete this._events[type]; | ||
| return this; | ||
| }; | ||
| EventEmitter.prototype.listeners = function (type) { | ||
| var ret; | ||
| if (!this._events || !this._events[type]) ret = [];else if (isFunction(this._events[type])) ret = [this._events[type]];else ret = this._events[type].slice(); | ||
| return ret; | ||
| }; | ||
| EventEmitter.prototype.listenerCount = function (type) { | ||
| if (this._events) { | ||
| var evlistener = this._events[type]; | ||
| if (isFunction(evlistener)) return 1;else if (evlistener) return evlistener.length; | ||
| } | ||
| return 0; | ||
| }; | ||
| EventEmitter.listenerCount = function (emitter, type) { | ||
| return emitter.listenerCount(type); | ||
| }; | ||
| function isFunction(arg) { | ||
| return typeof arg === 'function'; | ||
| } | ||
| function isNumber(arg) { | ||
| return typeof arg === 'number'; | ||
| } | ||
| function isObject(arg) { | ||
| return (typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) === 'object' && arg !== null; | ||
| } | ||
| function isUndefined(arg) { | ||
| return arg === void 0; | ||
| } | ||
| /***/ }), | ||
| /* 2 */ | ||
| /***/ (function(module, exports) { | ||
| "use strict"; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var Route = function () { | ||
| function Route(pathname, keys, sensitive, strict) { | ||
| _classCallCheck(this, Route); | ||
| this.keys = []; | ||
| this.strict = false; | ||
| this.sensitive = false; | ||
| this.path = pathname; | ||
| this.regex = this.create(); | ||
| } | ||
| _createClass(Route, [{ | ||
| key: "parse", | ||
| value: function parse(pathname) { | ||
| var _this = this; | ||
| var match = pathname.match(this.regex); | ||
| var req = { | ||
| match: match, | ||
| params: {}, | ||
| keys: this.keys, | ||
| matches: (match || []).slice(1) | ||
| }; | ||
| // Build parameters | ||
| req.matches.forEach(function (value, i) { | ||
| var key = _this.keys[i] && _this.keys[i].name ? _this.keys[i].name : i; | ||
| // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched | ||
| req.params[key] = value ? decodeURIComponent(value) : undefined; | ||
| }); | ||
| return req; | ||
| } | ||
| }, { | ||
| key: "create", | ||
| value: function create() { | ||
| var _this2 = this; | ||
| if (this.path instanceof RegExp) return this.path; | ||
| if (this.path instanceof Array) this.path = '(' + this.path.join('|') + ')'; | ||
| // Build route RegExp | ||
| var newPath = this.path.concat(this.strict ? '' : '/?').replace(/\/\(/g, '(?:/').replace(/\+/g, '__plus__').replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function (_, slash, format, key, capture, optional) { | ||
| _this2.keys.push({ | ||
| name: key, | ||
| optional: !!optional | ||
| }); | ||
| slash = slash || ''; | ||
| return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || format && '([^/.]+?)' || '([^/]+?)') + ')' + (optional || ''); | ||
| }).replace(/([\/.])/g, '\\$1').replace(/__plus__/g, '(.+)').replace(/\*/g, '(.*)'); | ||
| return new RegExp('^' + newPath + '$', this.sensitive ? '' : 'i'); | ||
| } | ||
| }]); | ||
| return Route; | ||
| }(); | ||
| exports.default = Route; | ||
| //# sourceMappingURL=route.js.map | ||
| /***/ }) | ||
| /******/ ]); | ||
| //# sourceMappingURL=grapnel.js.map |
| {"version":3,"sources":["webpack:///webpack/bootstrap 15f96c9751e0422681be","webpack:///./build/index.js","webpack:///./~/events/events.js","webpack:///./build/route.js"],"names":["Object","defineProperty","exports","value","events_1","require","route_1","Grapnel","options","_maxListeners","Infinity","defaults","root","target","window","isWindow","pushState","hashBang","assign","addEventListener","emit","e","state","previousState","routePath","middleware","Array","prototype","slice","call","arguments","handler","fullPath","route","default","routeHandler","req","parse","path","match","extra","params","regex","stack","MiddlewareStack","enqueue","concat","runCallback","parent","propagateEvent","callback","bind","eventName","on","add","apply","context","args","subMiddleware","length","prefix","substr","pattern","pathname","frag","undefined","pageName","title","history","location","_frag","hash","opts","routes","key","name","EventEmitter","router","extendObj","callbackRan","global","hasParentEvents","timeStamp","Date","now","next","atIndex","handlers","isArray","reverse","splice","shift","Route","module","_events","defaultMaxListeners","setMaxListeners","n","isNumber","isNaN","TypeError","type","er","len","i","listeners","error","isObject","Error","err","isUndefined","isFunction","addListener","listener","m","newListener","push","warned","console","trace","once","fired","g","removeListener","list","position","removeAllListeners","ret","listenerCount","evlistener","emitter","arg","keys","sensitive","strict","create","matches","forEach","decodeURIComponent","RegExp","join","newPath","replace","_","slash","format","capture","optional"],"mappings":";;;;;;;;;;;;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;AACA;;;;;;;;;;;;;;;;;;;;AASAA,QAAOC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C,EAAEC,OAAO,IAAT,EAA7C;AACA,KAAMC,WAAW,mBAAAC,CAAQ,CAAR,CAAjB;AACA,KAAMC,UAAU,mBAAAD,CAAQ,CAAR,CAAhB;;KACME,O;;;AACF,sBAAYC,OAAZ,EAAqB;AAAA;;AAAA;;AAEjB,eAAKC,aAAL,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mB,EAA3D,KAAkEC,UAAU,EAA5E,KAAmFC,WAAYD,UAAU,WAAV,IAAyB,UAAxH,IAAuI,GAAvI,IAA8IE,YAAY,EAA1J,CAAP;AACH,cAVa,EAWTL,OAXS,CAWD,UAXC,EAWW,MAXX,EAYTA,OAZS,CAYD,WAZC,EAYY,MAZZ,EAaTA,OAbS,CAaD,KAbC,EAaM,MAbN,CAAd;AAcA,oBAAO,IAAIH,MAAJ,CAAW,MAAME,OAAN,GAAgB,GAA3B,EAAgC,KAAKR,SAAL,GAAiB,EAAjB,GAAsB,GAAtD,CAAP;AACH;;;;;;AAELnI,SAAQgC,OAAR,GAAkB0D,KAAlB;AACA,kC","file":"grapnel.js","sourcesContent":[" \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\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\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.loaded = 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// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 15f96c9751e0422681be","\"use strict\";\n/****\n * Grapnel\n * https://github.com/baseprime/grapnel\n *\n * @author Greg Sabia Tucker <greg@narrowlabs.com>\n * @link http://basepri.me\n *\n * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT\n*/\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst events_1 = require(\"events\");\nconst route_1 = require(\"./route\");\nclass Grapnel extends events_1.EventEmitter {\n constructor(options) {\n super();\n this._maxListeners = Infinity;\n this.options = {};\n this.defaults = {\n root: '',\n target: ('object' === typeof window) ? window : {},\n isWindow: ('object' === typeof window),\n pushState: false,\n hashBang: false\n };\n this.options = Object.assign({}, this.defaults, options);\n if ('object' === typeof this.options.target && 'function' === typeof this.options.target.addEventListener) {\n this.options.target.addEventListener('hashchange', () => {\n this.emit('hashchange');\n });\n this.options.target.addEventListener('popstate', (e) => {\n // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome\n if (this.state && this.state.previousState === null)\n return false;\n this.emit('navigate');\n });\n }\n }\n add(routePath) {\n let middleware = Array.prototype.slice.call(arguments, 1, -1);\n let handler = Array.prototype.slice.call(arguments, -1)[0];\n let fullPath = this.options.root + routePath;\n let route = new route_1.default(fullPath);\n let routeHandler = (function () {\n // Build request parameters\n let req = route.parse(this.path());\n // Check if matches are found\n if (req.match) {\n // Match found\n let extra = {\n req,\n route: fullPath,\n params: req.params,\n regex: req.match\n };\n // Create call stack -- add middleware first, then handler\n let stack = new MiddlewareStack(this, extra).enqueue(middleware.concat(handler));\n // emit main event\n this.emit('match', stack, req);\n // Continue?\n if (!stack.runCallback)\n return this;\n // Previous state becomes current state\n stack.previousState = this.state;\n // Save new state\n this.state = stack;\n // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events\n if (stack.parent() && stack.parent().propagateEvent === false) {\n stack.propagateEvent = false;\n return this;\n }\n // Call handler\n stack.callback();\n }\n // Returns self\n return this;\n }).bind(this);\n // Event name\n let eventName = (!this.options.pushState && this.options.isWindow) ? 'hashchange' : 'navigate';\n // Invoke when route is defined, and once again when app navigates\n return routeHandler().on(eventName, routeHandler);\n }\n get() {\n return this.add.apply(this, arguments);\n }\n trigger() {\n return this.emit.apply(this, arguments);\n }\n bind() {\n // Backwards compatibility with older versions which mimed jQuery's bind()\n return this.on.apply(this, arguments);\n }\n context(context) {\n let middleware = Array.prototype.slice.call(arguments, 1);\n return (...args) => {\n let value = args[0];\n let subMiddleware = (args.length > 2) ? Array.prototype.slice.call(args, 1, -1) : [];\n let handler = Array.prototype.slice.call(args, -1)[0];\n let prefix = (context.slice(-1) !== '/' && value !== '/' && value !== '') ? context + '/' : context;\n let path = (value.substr(0, 1) !== '/') ? value : value.substr(1);\n let pattern = prefix + path;\n return this.add.apply(this, [pattern].concat(middleware).concat(subMiddleware).concat([handler]));\n };\n }\n navigate(path, options) {\n this.path(path, options).emit('navigate');\n return this;\n }\n path(pathname, options = {}) {\n let root = this.options.target;\n let frag = undefined;\n let pageName = options.title;\n if ('string' === typeof pathname) {\n // Set path\n if (this.options.pushState && 'function' === typeof root.history.pushState) {\n let state = options.state || root.history.state;\n frag = (this.options.root) ? (this.options.root + pathname) : pathname;\n root.history.pushState(state, pageName, frag);\n }\n else if (root.location) {\n let _frag = (this.options.root) ? (this.options.root + pathname) : pathname;\n root.location.hash = (this.options.hashBang ? '!' : '') + _frag;\n }\n else {\n root.pathname = pathname || '';\n }\n return this;\n }\n else if ('undefined' === typeof pathname) {\n // Get path\n return (root.location && root.location.pathname) ? root.location.pathname : (root.pathname || '');\n }\n else if (pathname === false) {\n // Clear path\n if (this.options.pushState && 'function' === typeof root.history.pushState) {\n let state = options.state || root.history.state;\n root.history.pushState(state, pageName, this.options.root || '/');\n }\n else if (root.location) {\n root.location.hash = (this.options.hashBang) ? '!' : '';\n }\n return this;\n }\n }\n static listen(...args) {\n let opts;\n let routes;\n if (args[0] && args[1]) {\n opts = args[0];\n routes = args[1];\n }\n else {\n routes = args[0];\n }\n // Return a new Grapnel instance\n return (function () {\n // TODO: Accept multi-level routes\n for (let key in routes) {\n this.add.call(this, key, routes[key]);\n }\n return this;\n }).call(new Grapnel(opts || {}));\n }\n static toString() {\n return this.name;\n }\n}\nclass MiddlewareStack {\n constructor(router, extendObj) {\n this.runCallback = true;\n this.callbackRan = true;\n this.propagateEvent = true;\n this.stack = MiddlewareStack.global.slice(0);\n this.router = router;\n this.value = router.path();\n Object.assign(this, extendObj);\n return this;\n }\n preventDefault() {\n this.runCallback = false;\n }\n stopPropagation() {\n this.propagateEvent = false;\n }\n parent() {\n let hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value);\n return (hasParentEvents) ? this.previousState : false;\n }\n callback() {\n this.callbackRan = true;\n this.timeStamp = Date.now();\n this.next();\n }\n enqueue(handler, atIndex) {\n let handlers = (!Array.isArray(handler)) ? [handler] : ((atIndex < handler.length) ? handler.reverse() : handler);\n while (handlers.length) {\n this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift());\n }\n return this;\n }\n next() {\n return this.stack.shift().call(this.router, this.req, this, () => this.next());\n }\n}\nMiddlewareStack.global = [];\nGrapnel.MiddlewareStack = MiddlewareStack;\nGrapnel.Route = route_1.default;\nexports = module.exports = Grapnel;\n//# sourceMappingURL=index.js.map\n\n\n// WEBPACK FOOTER //\n// ./build/index.js","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./~/events/events.js","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass Route {\n constructor(pathname, keys, sensitive, strict) {\n this.keys = [];\n this.strict = false;\n this.sensitive = false;\n this.path = pathname;\n this.regex = this.create();\n }\n parse(pathname) {\n let match = pathname.match(this.regex);\n let req = {\n match,\n params: {},\n keys: this.keys,\n matches: (match || []).slice(1),\n };\n // Build parameters\n req.matches.forEach((value, i) => {\n var key = (this.keys[i] && this.keys[i].name) ? this.keys[i].name : i;\n // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched\n req.params[key] = (value) ? decodeURIComponent(value) : undefined;\n });\n return req;\n }\n create() {\n if (this.path instanceof RegExp)\n return this.path;\n if (this.path instanceof Array)\n this.path = '(' + this.path.join('|') + ')';\n // Build route RegExp\n let newPath = this.path.concat(this.strict ? '' : '/?')\n .replace(/\\/\\(/g, '(?:/')\n .replace(/\\+/g, '__plus__')\n .replace(/(\\/)?(\\.)?:(\\w+)(?:(\\(.*?\\)))?(\\?)?/g, (_, slash, format, key, capture, optional) => {\n this.keys.push({\n name: key,\n optional: !!optional\n });\n slash = slash || '';\n return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || '');\n })\n .replace(/([\\/.])/g, '\\\\$1')\n .replace(/__plus__/g, '(.+)')\n .replace(/\\*/g, '(.*)');\n return new RegExp('^' + newPath + '$', this.sensitive ? '' : 'i');\n }\n}\nexports.default = Route;\n//# sourceMappingURL=route.js.map\n\n\n// WEBPACK FOOTER //\n// ./build/route.js"],"sourceRoot":""} |
| {"version":3,"sources":["webpack:///grapnel.min.js","webpack:///webpack/bootstrap 15f96c9751e0422681be?32cf","webpack:///./build/index.js?1b30","webpack:///./~/events/events.js?7c71","webpack:///./build/route.js?345a"],"names":["Grapnel","modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","_classCallCheck","instance","Constructor","TypeError","_possibleConstructorReturn","self","ReferenceError","_inherits","subClass","superClass","prototype","Object","create","constructor","value","enumerable","writable","configurable","setPrototypeOf","__proto__","_typeof","Symbol","iterator","obj","_createClass","defineProperties","target","props","i","length","descriptor","defineProperty","key","protoProps","staticProps","events_1","route_1","_events_1$EventEmitte","options","this","_this","getPrototypeOf","_maxListeners","Infinity","defaults","root","window","isWindow","pushState","hashBang","assign","addEventListener","emit","e","state","previousState","routePath","middleware","Array","slice","arguments","handler","fullPath","route","default","routeHandler","req","parse","path","match","extra","params","regex","stack","MiddlewareStack","enqueue","concat","runCallback","parent","propagateEvent","callback","bind","eventName","on","add","apply","context","_this2","_len","args","_key","subMiddleware","prefix","substr","pattern","pathname","undefined","frag","pageName","title","history","location","_frag","hash","opts","routes","name","EventEmitter","router","extendObj","callbackRan","global","hasParentEvents","timeStamp","Date","now","next","atIndex","handlers","isArray","reverse","splice","shift","_this3","Route","_events","isFunction","arg","isNumber","isObject","isUndefined","defaultMaxListeners","setMaxListeners","n","isNaN","type","er","len","listeners","error","Error","err","addListener","listener","newListener","push","warned","console","trace","once","g","removeListener","fired","list","position","removeAllListeners","ret","listenerCount","evlistener","emitter","keys","sensitive","strict","matches","forEach","decodeURIComponent","RegExp","join","newPath","replace","_","slash","format","capture","optional"],"mappings":";;;;;;;;;;AAAA,GAAIA,SACK,SAAUC,GCGnB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDOM,SAAUI,EAAQD,EAASH,GE7CjC,YF8DC,SAASW,GAAgBC,EAAUC,GAAe,KAAMD,YAAoBC,IAAgB,KAAM,IAAIC,WAAU,qCAEhH,QAASC,GAA2BC,EAAMT,GAAQ,IAAKS,EAAQ,KAAM,IAAIC,gBAAe,4DAAgE,QAAOV,GAAyB,gBAATA,IAAqC,kBAATA,GAA8BS,EAAPT,EAElO,QAASW,GAAUC,EAAUC,GAAc,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IAAM7B,KAAK6B,KAAKmG,KAAK,KAAO,IAE5C,IAAIC,GAAUjI,KAAK6B,KAAKQ,OAAOrC,KAAK2H,OAAS,GAAK,MAC7CO,QAAQ,QAAS,QACjBA,QAAQ,MAAO,YACfA,QAAQ,uCAAwC,SAACC,EAAGC,EAAOC,EAAQ5I,EAAK6I,EAASC,GAMlF,MALAvF,GAAKyE,KAAKf,MACNvC,KAAM1E,EACN8I,WAAYA,IAEhBH,EAAQA,GAAS,GACV,IAAMG,EAAW,GAAKH,GAAS,OAASG,EAAWH,EAAQ,KAAOC,GAAU,KAAOC,GAAYD,GAAU,aAAe,YAAe,KAAOE,GAAY,MAEhKL,QAAQ,WAAY,QACpBA,QAAQ,YAAa,QACrBA,QAAQ,MAAO,OACpB,OAAO,IAAIH,QAAO,IAAME,EAAU,IAAKjI,KAAK0H,UAAY,GAAK,SJwmBzDrC,IIrmBZpI,GAAQwE,QAAU4D","file":"grapnel.min.js","sourcesContent":["var Grapnel =\n/******/ (function(modules) { // webpackBootstrap\n/******/ \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/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\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.loaded = 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// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t/****\n\t * Grapnel\n\t * https://github.com/baseprime/grapnel\n\t *\n\t * @author Greg Sabia Tucker <greg@narrowlabs.com>\n\t * @link http://basepri.me\n\t *\n\t * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT\n\t*/\n\t\n\tvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\t\n\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\t\n\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\t\n\tfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\t\n\tfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\t\n\tObject.defineProperty(exports, \"__esModule\", { value: true });\n\tvar events_1 = __webpack_require__(1);\n\tvar route_1 = __webpack_require__(2);\n\t\n\tvar Grapnel = function (_events_1$EventEmitte) {\n\t _inherits(Grapnel, _events_1$EventEmitte);\n\t\n\t function Grapnel(options) {\n\t _classCallCheck(this, Grapnel);\n\t\n\t var _this = _possibleConstructorReturn(this, (Grapnel.__proto__ || Object.getPrototypeOf(Grapnel)).call(this));\n\t\n\t _this._maxListeners = Infinity;\n\t _this.options = {};\n\t _this.defaults = {\n\t root: '',\n\t target: 'object' === (typeof window === \"undefined\" ? \"undefined\" : _typeof(window)) ? window : {},\n\t isWindow: 'object' === (typeof window === \"undefined\" ? \"undefined\" : _typeof(window)),\n\t pushState: false,\n\t hashBang: false\n\t };\n\t _this.options = Object.assign({}, _this.defaults, options);\n\t if ('object' === _typeof(_this.options.target) && 'function' === typeof _this.options.target.addEventListener) {\n\t _this.options.target.addEventListener('hashchange', function () {\n\t _this.emit('hashchange');\n\t });\n\t _this.options.target.addEventListener('popstate', function (e) {\n\t // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome\n\t if (_this.state && _this.state.previousState === null) return false;\n\t _this.emit('navigate');\n\t });\n\t }\n\t return _this;\n\t }\n\t\n\t _createClass(Grapnel, [{\n\t key: \"add\",\n\t value: function add(routePath) {\n\t var middleware = Array.prototype.slice.call(arguments, 1, -1);\n\t var handler = Array.prototype.slice.call(arguments, -1)[0];\n\t var fullPath = this.options.root + routePath;\n\t var route = new route_1.default(fullPath);\n\t var routeHandler = function () {\n\t // Build request parameters\n\t var req = route.parse(this.path());\n\t // Check if matches are found\n\t if (req.match) {\n\t // Match found\n\t var extra = {\n\t req: req,\n\t route: fullPath,\n\t params: req.params,\n\t regex: req.match\n\t };\n\t // Create call stack -- add middleware first, then handler\n\t var stack = new MiddlewareStack(this, extra).enqueue(middleware.concat(handler));\n\t // emit main event\n\t this.emit('match', stack, req);\n\t // Continue?\n\t if (!stack.runCallback) return this;\n\t // Previous state becomes current state\n\t stack.previousState = this.state;\n\t // Save new state\n\t this.state = stack;\n\t // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events\n\t if (stack.parent() && stack.parent().propagateEvent === false) {\n\t stack.propagateEvent = false;\n\t return this;\n\t }\n\t // Call handler\n\t stack.callback();\n\t }\n\t // Returns self\n\t return this;\n\t }.bind(this);\n\t // Event name\n\t var eventName = !this.options.pushState && this.options.isWindow ? 'hashchange' : 'navigate';\n\t // Invoke when route is defined, and once again when app navigates\n\t return routeHandler().on(eventName, routeHandler);\n\t }\n\t }, {\n\t key: \"get\",\n\t value: function get() {\n\t return this.add.apply(this, arguments);\n\t }\n\t }, {\n\t key: \"trigger\",\n\t value: function trigger() {\n\t return this.emit.apply(this, arguments);\n\t }\n\t }, {\n\t key: \"bind\",\n\t value: function bind() {\n\t // Backwards compatibility with older versions which mimed jQuery's bind()\n\t return this.on.apply(this, arguments);\n\t }\n\t }, {\n\t key: \"context\",\n\t value: function context(_context) {\n\t var _this2 = this;\n\t\n\t var middleware = Array.prototype.slice.call(arguments, 1);\n\t return function () {\n\t for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\n\t args[_key] = arguments[_key];\n\t }\n\t\n\t var value = args[0];\n\t var subMiddleware = args.length > 2 ? Array.prototype.slice.call(args, 1, -1) : [];\n\t var handler = Array.prototype.slice.call(args, -1)[0];\n\t var prefix = _context.slice(-1) !== '/' && value !== '/' && value !== '' ? _context + '/' : _context;\n\t var path = value.substr(0, 1) !== '/' ? value : value.substr(1);\n\t var pattern = prefix + path;\n\t return _this2.add.apply(_this2, [pattern].concat(middleware).concat(subMiddleware).concat([handler]));\n\t };\n\t }\n\t }, {\n\t key: \"navigate\",\n\t value: function navigate(path, options) {\n\t this.path(path, options).emit('navigate');\n\t return this;\n\t }\n\t }, {\n\t key: \"path\",\n\t value: function path(pathname) {\n\t var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\t\n\t var root = this.options.target;\n\t var frag = undefined;\n\t var pageName = options.title;\n\t if ('string' === typeof pathname) {\n\t // Set path\n\t if (this.options.pushState && 'function' === typeof root.history.pushState) {\n\t var state = options.state || root.history.state;\n\t frag = this.options.root ? this.options.root + pathname : pathname;\n\t root.history.pushState(state, pageName, frag);\n\t } else if (root.location) {\n\t var _frag = this.options.root ? this.options.root + pathname : pathname;\n\t root.location.hash = (this.options.hashBang ? '!' : '') + _frag;\n\t } else {\n\t root.pathname = pathname || '';\n\t }\n\t return this;\n\t } else if ('undefined' === typeof pathname) {\n\t // Get path\n\t return root.location && root.location.pathname ? root.location.pathname : root.pathname || '';\n\t } else if (pathname === false) {\n\t // Clear path\n\t if (this.options.pushState && 'function' === typeof root.history.pushState) {\n\t var _state = options.state || root.history.state;\n\t root.history.pushState(_state, pageName, this.options.root || '/');\n\t } else if (root.location) {\n\t root.location.hash = this.options.hashBang ? '!' : '';\n\t }\n\t return this;\n\t }\n\t }\n\t }], [{\n\t key: \"listen\",\n\t value: function listen() {\n\t var opts = void 0;\n\t var routes = void 0;\n\t if ((arguments.length <= 0 ? undefined : arguments[0]) && (arguments.length <= 1 ? undefined : arguments[1])) {\n\t opts = arguments.length <= 0 ? undefined : arguments[0];\n\t routes = arguments.length <= 1 ? undefined : arguments[1];\n\t } else {\n\t routes = arguments.length <= 0 ? undefined : arguments[0];\n\t }\n\t // Return a new Grapnel instance\n\t return function () {\n\t // TODO: Accept multi-level routes\n\t for (var key in routes) {\n\t this.add.call(this, key, routes[key]);\n\t }\n\t return this;\n\t }.call(new Grapnel(opts || {}));\n\t }\n\t }, {\n\t key: \"toString\",\n\t value: function toString() {\n\t return this.name;\n\t }\n\t }]);\n\t\n\t return Grapnel;\n\t}(events_1.EventEmitter);\n\t\n\tvar MiddlewareStack = function () {\n\t function MiddlewareStack(router, extendObj) {\n\t _classCallCheck(this, MiddlewareStack);\n\t\n\t this.runCallback = true;\n\t this.callbackRan = true;\n\t this.propagateEvent = true;\n\t this.stack = MiddlewareStack.global.slice(0);\n\t this.router = router;\n\t this.value = router.path();\n\t Object.assign(this, extendObj);\n\t return this;\n\t }\n\t\n\t _createClass(MiddlewareStack, [{\n\t key: \"preventDefault\",\n\t value: function preventDefault() {\n\t this.runCallback = false;\n\t }\n\t }, {\n\t key: \"stopPropagation\",\n\t value: function stopPropagation() {\n\t this.propagateEvent = false;\n\t }\n\t }, {\n\t key: \"parent\",\n\t value: function parent() {\n\t var hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value);\n\t return hasParentEvents ? this.previousState : false;\n\t }\n\t }, {\n\t key: \"callback\",\n\t value: function callback() {\n\t this.callbackRan = true;\n\t this.timeStamp = Date.now();\n\t this.next();\n\t }\n\t }, {\n\t key: \"enqueue\",\n\t value: function enqueue(handler, atIndex) {\n\t var handlers = !Array.isArray(handler) ? [handler] : atIndex < handler.length ? handler.reverse() : handler;\n\t while (handlers.length) {\n\t this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift());\n\t }\n\t return this;\n\t }\n\t }, {\n\t key: \"next\",\n\t value: function next() {\n\t var _this3 = this;\n\t\n\t return this.stack.shift().call(this.router, this.req, this, function () {\n\t return _this3.next();\n\t });\n\t }\n\t }]);\n\t\n\t return MiddlewareStack;\n\t}();\n\t\n\tMiddlewareStack.global = [];\n\tGrapnel.MiddlewareStack = MiddlewareStack;\n\tGrapnel.Route = route_1.default;\n\texports = module.exports = Grapnel;\n\t//# sourceMappingURL=index.js.map\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports) {\n\n\t'use strict';\n\t\n\tvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\t\n\t// Copyright Joyent, Inc. and other Node contributors.\n\t//\n\t// Permission is hereby granted, free of charge, to any person obtaining a\n\t// copy of this software and associated documentation files (the\n\t// \"Software\"), to deal in the Software without restriction, including\n\t// without limitation the rights to use, copy, modify, merge, publish,\n\t// distribute, sublicense, and/or sell copies of the Software, and to permit\n\t// persons to whom the Software is furnished to do so, subject to the\n\t// following conditions:\n\t//\n\t// The above copyright notice and this permission notice shall be included\n\t// in all copies or substantial portions of the Software.\n\t//\n\t// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n\t// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\t// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n\t// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n\t// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n\t// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n\t// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\t\n\tfunction EventEmitter() {\n\t this._events = this._events || {};\n\t this._maxListeners = this._maxListeners || undefined;\n\t}\n\tmodule.exports = EventEmitter;\n\t\n\t// Backwards-compat with node 0.10.x\n\tEventEmitter.EventEmitter = EventEmitter;\n\t\n\tEventEmitter.prototype._events = undefined;\n\tEventEmitter.prototype._maxListeners = undefined;\n\t\n\t// By default EventEmitters will print a warning if more than 10 listeners are\n\t// added to it. This is a useful default which helps finding memory leaks.\n\tEventEmitter.defaultMaxListeners = 10;\n\t\n\t// Obviously not all Emitters should be limited to 10. This function allows\n\t// that to be increased. Set to zero for unlimited.\n\tEventEmitter.prototype.setMaxListeners = function (n) {\n\t if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number');\n\t this._maxListeners = n;\n\t return this;\n\t};\n\t\n\tEventEmitter.prototype.emit = function (type) {\n\t var er, handler, len, args, i, listeners;\n\t\n\t if (!this._events) this._events = {};\n\t\n\t // If there is no 'error' event listener then throw.\n\t if (type === 'error') {\n\t if (!this._events.error || isObject(this._events.error) && !this._events.error.length) {\n\t er = arguments[1];\n\t if (er instanceof Error) {\n\t throw er; // Unhandled 'error' event\n\t } else {\n\t // At least give some kind of context to the user\n\t var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n\t err.context = er;\n\t throw err;\n\t }\n\t }\n\t }\n\t\n\t handler = this._events[type];\n\t\n\t if (isUndefined(handler)) return false;\n\t\n\t if (isFunction(handler)) {\n\t switch (arguments.length) {\n\t // fast cases\n\t case 1:\n\t handler.call(this);\n\t break;\n\t case 2:\n\t handler.call(this, arguments[1]);\n\t break;\n\t case 3:\n\t handler.call(this, arguments[1], arguments[2]);\n\t break;\n\t // slower\n\t default:\n\t args = Array.prototype.slice.call(arguments, 1);\n\t handler.apply(this, args);\n\t }\n\t } else if (isObject(handler)) {\n\t args = Array.prototype.slice.call(arguments, 1);\n\t listeners = handler.slice();\n\t len = listeners.length;\n\t for (i = 0; i < len; i++) {\n\t listeners[i].apply(this, args);\n\t }\n\t }\n\t\n\t return true;\n\t};\n\t\n\tEventEmitter.prototype.addListener = function (type, listener) {\n\t var m;\n\t\n\t if (!isFunction(listener)) throw TypeError('listener must be a function');\n\t\n\t if (!this._events) this._events = {};\n\t\n\t // To avoid recursion in the case that type === \"newListener\"! Before\n\t // adding it to the listeners, first emit \"newListener\".\n\t if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener);\n\t\n\t if (!this._events[type])\n\t // Optimize the case of one listener. Don't need the extra array object.\n\t this._events[type] = listener;else if (isObject(this._events[type]))\n\t // If we've already got an array, just append.\n\t this._events[type].push(listener);else\n\t // Adding the second element, need to change to array.\n\t this._events[type] = [this._events[type], listener];\n\t\n\t // Check for listener leak\n\t if (isObject(this._events[type]) && !this._events[type].warned) {\n\t if (!isUndefined(this._maxListeners)) {\n\t m = this._maxListeners;\n\t } else {\n\t m = EventEmitter.defaultMaxListeners;\n\t }\n\t\n\t if (m && m > 0 && this._events[type].length > m) {\n\t this._events[type].warned = true;\n\t console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length);\n\t if (typeof console.trace === 'function') {\n\t // not supported in IE 10\n\t console.trace();\n\t }\n\t }\n\t }\n\t\n\t return this;\n\t};\n\t\n\tEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\t\n\tEventEmitter.prototype.once = function (type, listener) {\n\t if (!isFunction(listener)) throw TypeError('listener must be a function');\n\t\n\t var fired = false;\n\t\n\t function g() {\n\t this.removeListener(type, g);\n\t\n\t if (!fired) {\n\t fired = true;\n\t listener.apply(this, arguments);\n\t }\n\t }\n\t\n\t g.listener = listener;\n\t this.on(type, g);\n\t\n\t return this;\n\t};\n\t\n\t// emits a 'removeListener' event iff the listener was removed\n\tEventEmitter.prototype.removeListener = function (type, listener) {\n\t var list, position, length, i;\n\t\n\t if (!isFunction(listener)) throw TypeError('listener must be a function');\n\t\n\t if (!this._events || !this._events[type]) return this;\n\t\n\t list = this._events[type];\n\t length = list.length;\n\t position = -1;\n\t\n\t if (list === listener || isFunction(list.listener) && list.listener === listener) {\n\t delete this._events[type];\n\t if (this._events.removeListener) this.emit('removeListener', type, listener);\n\t } else if (isObject(list)) {\n\t for (i = length; i-- > 0;) {\n\t if (list[i] === listener || list[i].listener && list[i].listener === listener) {\n\t position = i;\n\t break;\n\t }\n\t }\n\t\n\t if (position < 0) return this;\n\t\n\t if (list.length === 1) {\n\t list.length = 0;\n\t delete this._events[type];\n\t } else {\n\t list.splice(position, 1);\n\t }\n\t\n\t if (this._events.removeListener) this.emit('removeListener', type, listener);\n\t }\n\t\n\t return this;\n\t};\n\t\n\tEventEmitter.prototype.removeAllListeners = function (type) {\n\t var key, listeners;\n\t\n\t if (!this._events) return this;\n\t\n\t // not listening for removeListener, no need to emit\n\t if (!this._events.removeListener) {\n\t if (arguments.length === 0) this._events = {};else if (this._events[type]) delete this._events[type];\n\t return this;\n\t }\n\t\n\t // emit removeListener for all listeners on all events\n\t if (arguments.length === 0) {\n\t for (key in this._events) {\n\t if (key === 'removeListener') continue;\n\t this.removeAllListeners(key);\n\t }\n\t this.removeAllListeners('removeListener');\n\t this._events = {};\n\t return this;\n\t }\n\t\n\t listeners = this._events[type];\n\t\n\t if (isFunction(listeners)) {\n\t this.removeListener(type, listeners);\n\t } else if (listeners) {\n\t // LIFO order\n\t while (listeners.length) {\n\t this.removeListener(type, listeners[listeners.length - 1]);\n\t }\n\t }\n\t delete this._events[type];\n\t\n\t return this;\n\t};\n\t\n\tEventEmitter.prototype.listeners = function (type) {\n\t var ret;\n\t if (!this._events || !this._events[type]) ret = [];else if (isFunction(this._events[type])) ret = [this._events[type]];else ret = this._events[type].slice();\n\t return ret;\n\t};\n\t\n\tEventEmitter.prototype.listenerCount = function (type) {\n\t if (this._events) {\n\t var evlistener = this._events[type];\n\t\n\t if (isFunction(evlistener)) return 1;else if (evlistener) return evlistener.length;\n\t }\n\t return 0;\n\t};\n\t\n\tEventEmitter.listenerCount = function (emitter, type) {\n\t return emitter.listenerCount(type);\n\t};\n\t\n\tfunction isFunction(arg) {\n\t return typeof arg === 'function';\n\t}\n\t\n\tfunction isNumber(arg) {\n\t return typeof arg === 'number';\n\t}\n\t\n\tfunction isObject(arg) {\n\t return (typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) === 'object' && arg !== null;\n\t}\n\t\n\tfunction isUndefined(arg) {\n\t return arg === void 0;\n\t}\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\n\t\"use strict\";\n\t\n\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\t\n\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\t\n\tObject.defineProperty(exports, \"__esModule\", { value: true });\n\t\n\tvar Route = function () {\n\t function Route(pathname, keys, sensitive, strict) {\n\t _classCallCheck(this, Route);\n\t\n\t this.keys = [];\n\t this.strict = false;\n\t this.sensitive = false;\n\t this.path = pathname;\n\t this.regex = this.create();\n\t }\n\t\n\t _createClass(Route, [{\n\t key: \"parse\",\n\t value: function parse(pathname) {\n\t var _this = this;\n\t\n\t var match = pathname.match(this.regex);\n\t var req = {\n\t match: match,\n\t params: {},\n\t keys: this.keys,\n\t matches: (match || []).slice(1)\n\t };\n\t // Build parameters\n\t req.matches.forEach(function (value, i) {\n\t var key = _this.keys[i] && _this.keys[i].name ? _this.keys[i].name : i;\n\t // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched\n\t req.params[key] = value ? decodeURIComponent(value) : undefined;\n\t });\n\t return req;\n\t }\n\t }, {\n\t key: \"create\",\n\t value: function create() {\n\t var _this2 = this;\n\t\n\t if (this.path instanceof RegExp) return this.path;\n\t if (this.path instanceof Array) this.path = '(' + this.path.join('|') + ')';\n\t // Build route RegExp\n\t var newPath = this.path.concat(this.strict ? '' : '/?').replace(/\\/\\(/g, '(?:/').replace(/\\+/g, '__plus__').replace(/(\\/)?(\\.)?:(\\w+)(?:(\\(.*?\\)))?(\\?)?/g, function (_, slash, format, key, capture, optional) {\n\t _this2.keys.push({\n\t name: key,\n\t optional: !!optional\n\t });\n\t slash = slash || '';\n\t return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || format && '([^/.]+?)' || '([^/]+?)') + ')' + (optional || '');\n\t }).replace(/([\\/.])/g, '\\\\$1').replace(/__plus__/g, '(.+)').replace(/\\*/g, '(.*)');\n\t return new RegExp('^' + newPath + '$', this.sensitive ? '' : 'i');\n\t }\n\t }]);\n\t\n\t return Route;\n\t}();\n\t\n\texports.default = Route;\n\t//# sourceMappingURL=route.js.map\n\n/***/ })\n/******/ ]);\n\n\n// WEBPACK FOOTER //\n// grapnel.min.js"," \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\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\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.loaded = 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// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 15f96c9751e0422681be","\"use strict\";\n/****\n * Grapnel\n * https://github.com/baseprime/grapnel\n *\n * @author Greg Sabia Tucker <greg@narrowlabs.com>\n * @link http://basepri.me\n *\n * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT\n*/\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst events_1 = require(\"events\");\nconst route_1 = require(\"./route\");\nclass Grapnel extends events_1.EventEmitter {\n constructor(options) {\n super();\n this._maxListeners = Infinity;\n this.options = {};\n this.defaults = {\n root: '',\n target: ('object' === typeof window) ? window : {},\n isWindow: ('object' === typeof window),\n pushState: false,\n hashBang: false\n };\n this.options = Object.assign({}, this.defaults, options);\n if ('object' === typeof this.options.target && 'function' === typeof this.options.target.addEventListener) {\n this.options.target.addEventListener('hashchange', () => {\n this.emit('hashchange');\n });\n this.options.target.addEventListener('popstate', (e) => {\n // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome\n if (this.state && this.state.previousState === null)\n return false;\n this.emit('navigate');\n });\n }\n }\n add(routePath) {\n let middleware = Array.prototype.slice.call(arguments, 1, -1);\n let handler = Array.prototype.slice.call(arguments, -1)[0];\n let fullPath = this.options.root + routePath;\n let route = new route_1.default(fullPath);\n let routeHandler = (function () {\n // Build request parameters\n let req = route.parse(this.path());\n // Check if matches are found\n if (req.match) {\n // Match found\n let extra = {\n req,\n route: fullPath,\n params: req.params,\n regex: req.match\n };\n // Create call stack -- add middleware first, then handler\n let stack = new MiddlewareStack(this, extra).enqueue(middleware.concat(handler));\n // emit main event\n this.emit('match', stack, req);\n // Continue?\n if (!stack.runCallback)\n return this;\n // Previous state becomes current state\n stack.previousState = this.state;\n // Save new state\n this.state = stack;\n // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events\n if (stack.parent() && stack.parent().propagateEvent === false) {\n stack.propagateEvent = false;\n return this;\n }\n // Call handler\n stack.callback();\n }\n // Returns self\n return this;\n }).bind(this);\n // Event name\n let eventName = (!this.options.pushState && this.options.isWindow) ? 'hashchange' : 'navigate';\n // Invoke when route is defined, and once again when app navigates\n return routeHandler().on(eventName, routeHandler);\n }\n get() {\n return this.add.apply(this, arguments);\n }\n trigger() {\n return this.emit.apply(this, arguments);\n }\n bind() {\n // Backwards compatibility with older versions which mimed jQuery's bind()\n return this.on.apply(this, arguments);\n }\n context(context) {\n let middleware = Array.prototype.slice.call(arguments, 1);\n return (...args) => {\n let value = args[0];\n let subMiddleware = (args.length > 2) ? Array.prototype.slice.call(args, 1, -1) : [];\n let handler = Array.prototype.slice.call(args, -1)[0];\n let prefix = (context.slice(-1) !== '/' && value !== '/' && value !== '') ? context + '/' : context;\n let path = (value.substr(0, 1) !== '/') ? value : value.substr(1);\n let pattern = prefix + path;\n return this.add.apply(this, [pattern].concat(middleware).concat(subMiddleware).concat([handler]));\n };\n }\n navigate(path, options) {\n this.path(path, options).emit('navigate');\n return this;\n }\n path(pathname, options = {}) {\n let root = this.options.target;\n let frag = undefined;\n let pageName = options.title;\n if ('string' === typeof pathname) {\n // Set path\n if (this.options.pushState && 'function' === typeof root.history.pushState) {\n let state = options.state || root.history.state;\n frag = (this.options.root) ? (this.options.root + pathname) : pathname;\n root.history.pushState(state, pageName, frag);\n }\n else if (root.location) {\n let _frag = (this.options.root) ? (this.options.root + pathname) : pathname;\n root.location.hash = (this.options.hashBang ? '!' : '') + _frag;\n }\n else {\n root.pathname = pathname || '';\n }\n return this;\n }\n else if ('undefined' === typeof pathname) {\n // Get path\n return (root.location && root.location.pathname) ? root.location.pathname : (root.pathname || '');\n }\n else if (pathname === false) {\n // Clear path\n if (this.options.pushState && 'function' === typeof root.history.pushState) {\n let state = options.state || root.history.state;\n root.history.pushState(state, pageName, this.options.root || '/');\n }\n else if (root.location) {\n root.location.hash = (this.options.hashBang) ? '!' : '';\n }\n return this;\n }\n }\n static listen(...args) {\n let opts;\n let routes;\n if (args[0] && args[1]) {\n opts = args[0];\n routes = args[1];\n }\n else {\n routes = args[0];\n }\n // Return a new Grapnel instance\n return (function () {\n // TODO: Accept multi-level routes\n for (let key in routes) {\n this.add.call(this, key, routes[key]);\n }\n return this;\n }).call(new Grapnel(opts || {}));\n }\n static toString() {\n return this.name;\n }\n}\nclass MiddlewareStack {\n constructor(router, extendObj) {\n this.runCallback = true;\n this.callbackRan = true;\n this.propagateEvent = true;\n this.stack = MiddlewareStack.global.slice(0);\n this.router = router;\n this.value = router.path();\n Object.assign(this, extendObj);\n return this;\n }\n preventDefault() {\n this.runCallback = false;\n }\n stopPropagation() {\n this.propagateEvent = false;\n }\n parent() {\n let hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value);\n return (hasParentEvents) ? this.previousState : false;\n }\n callback() {\n this.callbackRan = true;\n this.timeStamp = Date.now();\n this.next();\n }\n enqueue(handler, atIndex) {\n let handlers = (!Array.isArray(handler)) ? [handler] : ((atIndex < handler.length) ? handler.reverse() : handler);\n while (handlers.length) {\n this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift());\n }\n return this;\n }\n next() {\n return this.stack.shift().call(this.router, this.req, this, () => this.next());\n }\n}\nMiddlewareStack.global = [];\nGrapnel.MiddlewareStack = MiddlewareStack;\nGrapnel.Route = route_1.default;\nexports = module.exports = Grapnel;\n//# sourceMappingURL=index.js.map\n\n\n// WEBPACK FOOTER //\n// ./build/index.js","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./~/events/events.js","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass Route {\n constructor(pathname, keys, sensitive, strict) {\n this.keys = [];\n this.strict = false;\n this.sensitive = false;\n this.path = pathname;\n this.regex = this.create();\n }\n parse(pathname) {\n let match = pathname.match(this.regex);\n let req = {\n match,\n params: {},\n keys: this.keys,\n matches: (match || []).slice(1),\n };\n // Build parameters\n req.matches.forEach((value, i) => {\n var key = (this.keys[i] && this.keys[i].name) ? this.keys[i].name : i;\n // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched\n req.params[key] = (value) ? decodeURIComponent(value) : undefined;\n });\n return req;\n }\n create() {\n if (this.path instanceof RegExp)\n return this.path;\n if (this.path instanceof Array)\n this.path = '(' + this.path.join('|') + ')';\n // Build route RegExp\n let newPath = this.path.concat(this.strict ? '' : '/?')\n .replace(/\\/\\(/g, '(?:/')\n .replace(/\\+/g, '__plus__')\n .replace(/(\\/)?(\\.)?:(\\w+)(?:(\\(.*?\\)))?(\\?)?/g, (_, slash, format, key, capture, optional) => {\n this.keys.push({\n name: key,\n optional: !!optional\n });\n slash = slash || '';\n return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || '');\n })\n .replace(/([\\/.])/g, '\\\\$1')\n .replace(/__plus__/g, '(.+)')\n .replace(/\\*/g, '(.*)');\n return new RegExp('^' + newPath + '$', this.sensitive ? '' : 'i');\n }\n}\nexports.default = Route;\n//# sourceMappingURL=route.js.map\n\n\n// WEBPACK FOOTER //\n// ./build/route.js"],"sourceRoot":""} |
+256
| /**** | ||
| * Grapnel | ||
| * https://github.com/baseprime/grapnel | ||
| * | ||
| * @author Greg Sabia Tucker <greg@narrowlabs.com> | ||
| * @link http://basepri.me | ||
| * | ||
| * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT | ||
| */ | ||
| import { EventEmitter } from 'events'; | ||
| import Route, { ParsedRoute } from './route'; | ||
| class Grapnel extends EventEmitter { | ||
| static MiddlewareStack: typeof MiddlewareStack; | ||
| static Route: typeof Route; | ||
| _maxListeners: number = Infinity; | ||
| state: MiddlewareStack; | ||
| options: GrapnelOptions = {}; | ||
| defaults: any = { | ||
| root: '', | ||
| target: ('object' === typeof window) ? window : {}, | ||
| isWindow: ('object' === typeof window), | ||
| pushState: false, | ||
| hashBang: false | ||
| } | ||
| constructor(options?: GrapnelOptions) { | ||
| super(); | ||
| this.options = Object.assign({}, this.defaults, options); | ||
| if ('object' === typeof this.options.target && 'function' === typeof this.options.target.addEventListener) { | ||
| this.options.target.addEventListener('hashchange', () => { | ||
| this.emit('hashchange'); | ||
| }); | ||
| this.options.target.addEventListener('popstate', (e: any) => { | ||
| // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome | ||
| if (this.state && this.state.previousState === null) return false; | ||
| this.emit('navigate'); | ||
| }); | ||
| } | ||
| } | ||
| add(routePath: string & RegExp): Grapnel { | ||
| let middleware: Function[] = Array.prototype.slice.call(arguments, 1, -1); | ||
| let handler: Function = Array.prototype.slice.call(arguments, -1)[0]; | ||
| let fullPath = this.options.root + routePath; | ||
| let route = new Route(fullPath); | ||
| let routeHandler = (function () { | ||
| // Build request parameters | ||
| let req: ParsedRoute = route.parse(this.path()); | ||
| // Check if matches are found | ||
| if (req.match) { | ||
| // Match found | ||
| let extra = { | ||
| req, | ||
| route: fullPath, | ||
| params: req.params, | ||
| regex: req.match | ||
| }; | ||
| // Create call stack -- add middleware first, then handler | ||
| let stack = new MiddlewareStack(this, extra).enqueue(middleware.concat(handler)); | ||
| // emit main event | ||
| this.emit('match', stack, req); | ||
| // Continue? | ||
| if (!stack.runCallback) return this; | ||
| // Previous state becomes current state | ||
| stack.previousState = this.state; | ||
| // Save new state | ||
| this.state = stack; | ||
| // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events | ||
| if (stack.parent() && stack.parent().propagateEvent === false) { | ||
| stack.propagateEvent = false; | ||
| return this; | ||
| } | ||
| // Call handler | ||
| stack.callback(); | ||
| } | ||
| // Returns self | ||
| return this; | ||
| }).bind(this); | ||
| // Event name | ||
| let eventName = (!this.options.pushState && this.options.isWindow) ? 'hashchange' : 'navigate'; | ||
| // Invoke when route is defined, and once again when app navigates | ||
| return routeHandler().on(eventName, routeHandler); | ||
| } | ||
| get(): Grapnel { | ||
| return this.add.apply(this, arguments); | ||
| } | ||
| trigger(): Grapnel { | ||
| return this.emit.apply(this, arguments); | ||
| } | ||
| bind(): Grapnel { | ||
| // Backwards compatibility with older versions which mimed jQuery's bind() | ||
| return this.on.apply(this, arguments); | ||
| } | ||
| context(context: string & RegExp): () => Grapnel { | ||
| let middleware = Array.prototype.slice.call(arguments, 1); | ||
| return (...args: any[]) => { | ||
| let value = args[0]; | ||
| let subMiddleware = (args.length > 2) ? Array.prototype.slice.call(args, 1, -1) : []; | ||
| let handler = Array.prototype.slice.call(args, -1)[0]; | ||
| let prefix = (context.slice(-1) !== '/' && value !== '/' && value !== '') ? context + '/' : context; | ||
| let path = (value.substr(0, 1) !== '/') ? value : value.substr(1); | ||
| let pattern = prefix + path; | ||
| return this.add.apply(this, [pattern].concat(middleware).concat(subMiddleware).concat([handler])); | ||
| } | ||
| } | ||
| navigate(path: string, options: NavigateOptions): Grapnel { | ||
| this.path(path, options).emit('navigate'); | ||
| return this; | ||
| } | ||
| path(pathname?: string, options: NavigateOptions = {}) { | ||
| let root = this.options.target; | ||
| let frag = undefined; | ||
| let pageName = options.title; | ||
| if ('string' === typeof pathname) { | ||
| // Set path | ||
| if (this.options.pushState && 'function' === typeof root.history.pushState) { | ||
| let state = options.state || root.history.state; | ||
| frag = (this.options.root) ? (this.options.root + pathname) : pathname; | ||
| root.history.pushState(state, pageName, frag); | ||
| } else if (root.location) { | ||
| let _frag = (this.options.root) ? (this.options.root + pathname) : pathname; | ||
| root.location.hash = (this.options.hashBang ? '!' : '') + _frag; | ||
| } else { | ||
| root.pathname = pathname || ''; | ||
| } | ||
| return this; | ||
| } else if ('undefined' === typeof pathname) { | ||
| // Get path | ||
| return (root.location && root.location.pathname) ? root.location.pathname : (root.pathname || ''); | ||
| } else if (pathname === false) { | ||
| // Clear path | ||
| if (this.options.pushState && 'function' === typeof root.history.pushState) { | ||
| let state = options.state || root.history.state; | ||
| root.history.pushState(state, pageName, this.options.root || '/'); | ||
| } else if (root.location) { | ||
| root.location.hash = (this.options.hashBang) ? '!' : ''; | ||
| } | ||
| return this; | ||
| } | ||
| } | ||
| static listen(...args: any[]): Grapnel { | ||
| let opts: any; | ||
| let routes: any; | ||
| if (args[0] && args[1]) { | ||
| opts = args[0]; | ||
| routes = args[1]; | ||
| } else { | ||
| routes = args[0]; | ||
| } | ||
| // Return a new Grapnel instance | ||
| return (function () { | ||
| // TODO: Accept multi-level routes | ||
| for (let key in routes) { | ||
| this.add.call(this, key, routes[key]); | ||
| } | ||
| return this; | ||
| }).call(new Grapnel(opts || {})); | ||
| } | ||
| static toString() { | ||
| return this.name; | ||
| } | ||
| } | ||
| class MiddlewareStack { | ||
| stack: any[]; | ||
| router: Grapnel; | ||
| runCallback: boolean = true; | ||
| callbackRan: boolean = true; | ||
| propagateEvent: boolean = true; | ||
| value: string; | ||
| req: any; | ||
| previousState: any; | ||
| timeStamp: Number; | ||
| static global: any[] = []; | ||
| constructor(router: Grapnel, extendObj?: any) { | ||
| this.stack = MiddlewareStack.global.slice(0); | ||
| this.router = router; | ||
| this.value = router.path(); | ||
| Object.assign(this, extendObj); | ||
| return this; | ||
| } | ||
| preventDefault() { | ||
| this.runCallback = false; | ||
| } | ||
| stopPropagation() { | ||
| this.propagateEvent = false; | ||
| } | ||
| parent() { | ||
| let hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value); | ||
| return (hasParentEvents) ? this.previousState : false; | ||
| } | ||
| callback() { | ||
| this.callbackRan = true; | ||
| this.timeStamp = Date.now(); | ||
| this.next(); | ||
| } | ||
| enqueue(handler: any, atIndex?: number) { | ||
| let handlers = (!Array.isArray(handler)) ? [handler] : ((atIndex < handler.length) ? handler.reverse() : handler); | ||
| while (handlers.length) { | ||
| this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift()); | ||
| } | ||
| return this; | ||
| } | ||
| next() { | ||
| return this.stack.shift().call(this.router, this.req, this, () => this.next()); | ||
| } | ||
| } | ||
| export interface GrapnelOptions { | ||
| pushState?: boolean; | ||
| hashBang?: boolean; | ||
| isWindow?: boolean; | ||
| target?: any; | ||
| root?: string; | ||
| } | ||
| export interface NavigateOptions { | ||
| title?: string; | ||
| state?: any; | ||
| } | ||
| Grapnel.MiddlewareStack = MiddlewareStack; | ||
| Grapnel.Route = Route; | ||
| exports = module.exports = Grapnel; |
+61
| export default class Route { | ||
| path: string | string[] | RegExp; | ||
| keys: ParsedRoute['keys'] = []; | ||
| regex: RegExp; | ||
| strict?: boolean = false; | ||
| sensitive?: boolean = false; | ||
| constructor(pathname: any, keys?: any[], sensitive?: boolean, strict?: boolean) { | ||
| this.path = pathname; | ||
| this.regex = this.create(); | ||
| } | ||
| parse(pathname: string) { | ||
| let match = pathname.match(this.regex); | ||
| let req: ParsedRoute = { | ||
| match, | ||
| params: <any>{}, | ||
| keys: this.keys, | ||
| matches: (match || []).slice(1), | ||
| }; | ||
| // Build parameters | ||
| req.matches.forEach((value, i) => { | ||
| var key = (this.keys[i] && this.keys[i].name) ? this.keys[i].name : i; | ||
| // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched | ||
| req.params[key] = (value) ? decodeURIComponent(value) : undefined; | ||
| }); | ||
| return req; | ||
| } | ||
| create() { | ||
| if (this.path instanceof RegExp) return this.path; | ||
| if (this.path instanceof Array) this.path = '(' + this.path.join('|') + ')'; | ||
| // Build route RegExp | ||
| let newPath = this.path.concat(this.strict ? '' : '/?') | ||
| .replace(/\/\(/g, '(?:/') | ||
| .replace(/\+/g, '__plus__') | ||
| .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, (_: any, slash: any, format: any, key: any, capture: any, optional: any) => { | ||
| this.keys.push({ | ||
| name: key, | ||
| optional: !!optional | ||
| }); | ||
| slash = slash || ''; | ||
| return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); | ||
| }) | ||
| .replace(/([\/.])/g, '\\$1') | ||
| .replace(/__plus__/g, '(.+)') | ||
| .replace(/\*/g, '(.*)'); | ||
| return new RegExp('^' + newPath + '$', this.sensitive ? '' : 'i'); | ||
| } | ||
| } | ||
| export interface ParsedRoute { | ||
| params: any; | ||
| keys: { name: string; optional: boolean; }[]; | ||
| matches: string[]; | ||
| match: string[]; | ||
| } |
| { | ||
| "compilerOptions": { | ||
| "target": "es2016", | ||
| "module": "commonjs", | ||
| "watch": true, | ||
| "noImplicitAny": true, | ||
| "removeComments": false, | ||
| "preserveConstEnums": true, | ||
| "sourceMap": true, | ||
| "outDir": "build" | ||
| }, | ||
| "include": [ | ||
| "src/*.ts" | ||
| ] | ||
| } |
| const path = require('path'); | ||
| const webpack = require('webpack'); | ||
| const package = require('./package'); | ||
| module.exports = { | ||
| entry: { | ||
| 'grapnel': './build/index.js', | ||
| 'grapnel.min': './build/index.js' | ||
| }, | ||
| output: { | ||
| path: './dist', | ||
| filename: '[name].js', | ||
| library: 'Grapnel', | ||
| libraryTarget: 'var' | ||
| }, | ||
| devtool: 'source-map', | ||
| module: { | ||
| loaders: [ | ||
| { | ||
| test: /\.js$/, | ||
| loader: 'babel-loader', | ||
| query: { | ||
| presets: [require.resolve('babel-preset-es2015')] | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| plugins: [ | ||
| new webpack.optimize.UglifyJsPlugin({ | ||
| include: /\.min\.js$/, | ||
| compress: { warnings: false } | ||
| }), | ||
| new webpack.BannerPlugin(`Grapnel\n${package.repository.url}\n\n@author ${package.author}\n@link ${package.link}\n@version ${package.version}\n\nReleased under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT`) | ||
| ] | ||
| } |
+4
-3
| { | ||
| "name": "grapnel", | ||
| "version": "0.6.3", | ||
| "version": "0.7.0", | ||
| "homepage": "https://github.com/baseprime/grapnel", | ||
@@ -8,6 +8,7 @@ "authors": [ | ||
| ], | ||
| "description": "The smallest (1100 bytes gzipped!) JavaScript Router with PushState & Named Parameters", | ||
| "description": "The first (and smallest!) JavaScript Router with PushState, Middleware, and Named Parameter support", | ||
| "main": "dist/grapnel.min.js", | ||
| "moduleType": [ | ||
| "amd", | ||
| "node", | ||
| "es6", | ||
| "globals" | ||
@@ -14,0 +15,0 @@ ], |
+11
-0
| ## Changelog | ||
| ##### 0.7.0 | ||
| * Rewrote source in TypeScript | ||
| * Remove unnecessary `env` from options (this was never in the documentation so it shouldn't have been used) | ||
| * Move target out of constructor and into instance options so user can override | ||
| * Use isWindow on options to check if window is present | ||
| * Changed `Request()` constructor to `Route()` so we don't override native `Request` | ||
| * Added tests | ||
| * Bugfixes: | ||
| * Fix router root issues | ||
| * Navigate correctly returns self | ||
| ##### 0.6.2 | ||
@@ -4,0 +15,0 @@ * Singular code style now enforced (bracket styles, line endings, etc.) |
@@ -1,12 +0,12 @@ | ||
| /**** | ||
| /*! | ||
| * Grapnel | ||
| * https://github.com/baseprime/grapnel | ||
| * | ||
| * https://github.com/baseprime/grapnel.git | ||
| * | ||
| * @author Greg Sabia Tucker <greg@narrowlabs.com> | ||
| * @link http://basepri.me | ||
| * @version 0.6.4 | ||
| * | ||
| * @version 0.7.0 | ||
| * | ||
| * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT | ||
| */ | ||
| !function(a){function b(b){"use strict";var c=this;return this.events={},this.state=null,this.options=b||{},this.options.env=this.options.env||(0===Object.keys(a).length&&process&&process.browser!==!0?"server":"client"),this.options.mode=this.options.mode||("server"!==this.options.env&&this.options.pushState&&a.history&&a.history.pushState?"pushState":"hashchange"),this.version="0.6.4","function"==typeof a.addEventListener&&(a.addEventListener("hashchange",function(){c.trigger("hashchange")}),a.addEventListener("popstate",function(a){return(!c.state||null!==c.state.previousState)&&void c.trigger("navigate")})),this}function c(a,b){this.stack=c.global.slice(0),this.router=a,this.runCallback=!0,this.callbackRan=!1,this.propagateEvent=!0,this.value=a.path();for(var d in b)this[d]=b[d];return this}function d(a){this.route=a,this.keys=[],this.regex=b.regexRoute(a,this.keys)}b.regexRoute=function(a,b,c,d){return a instanceof RegExp?a:(a instanceof Array&&(a="("+a.join("|")+")"),a=a.concat(d?"":"/?").replace(/\/\(/g,"(?:/").replace(/\+/g,"__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g,function(a,c,d,e,f,g){return b.push({name:e,optional:!!g}),c=c||"",""+(g?"":c)+"(?:"+(g?c:"")+(d||"")+(f||d&&"([^/.]+?)"||"([^/]+?)")+")"+(g||"")}).replace(/([\/.])/g,"\\$1").replace(/__plus__/g,"(.+)").replace(/\*/g,"(.*)"),new RegExp("^"+a+"$",c?"":"i"))},b._forEach=function(a,b){return"function"==typeof Array.prototype.forEach?Array.prototype.forEach.call(a,b):function(a,b){for(var c=0,d=this.length;c<d;++c)a.call(b,this[c],c,this)}.call(a,b)},b.prototype.get=b.prototype.add=function(a){var b=this,e=Array.prototype.slice.call(arguments,1,-1),f=Array.prototype.slice.call(arguments,-1)[0],g=new d(a),h=function(){var d=g.parse(b.path());if(d.match){var h={route:a,params:d.params,req:d,regex:d.match},i=new c(b,h).enqueue(e.concat(f));if(b.trigger("match",i,d),!i.runCallback)return b;if(i.previousState=b.state,b.state=i,i.parent()&&i.parent().propagateEvent===!1)return i.propagateEvent=!1,b;i.callback()}return b},i="pushState"!==b.options.mode&&"server"!==b.options.env?"hashchange":"navigate";return h().on(i,h)},b.prototype.trigger=function(a){var c=this,d=Array.prototype.slice.call(arguments,1);return this.events[a]&&b._forEach(this.events[a],function(a){a.apply(c,d)}),this},b.prototype.on=b.prototype.bind=function(a,c){var d=this,e=a.split(" ");return b._forEach(e,function(a){d.events[a]?d.events[a].push(c):d.events[a]=[c]}),this},b.prototype.once=function(a,b){var c=!1;return this.on(a,function(){return!c&&(c=!0,b.apply(this,arguments),b=null,!0)})},b.prototype.context=function(a){var b=this,c=Array.prototype.slice.call(arguments,1);return function(){var d=arguments[0],e=arguments.length>2?Array.prototype.slice.call(arguments,1,-1):[],f=Array.prototype.slice.call(arguments,-1)[0],g="/"!==a.slice(-1)&&"/"!==d&&""!==d?a+"/":a,h="/"!==d.substr(0,1)?d:d.substr(1),i=g+h;return b.add.apply(b,[i].concat(c).concat(e).concat([f]))}},b.prototype.navigate=function(a){return this.path(a).trigger("navigate")},b.prototype.path=function(b){var c,d=this;return"string"==typeof b?("pushState"===d.options.mode?(c=d.options.root?d.options.root+b:b,a.history.pushState({},null,c)):a.location?a.location.hash=(d.options.hashBang?"!":"")+b:a._pathname=b||"",this):"undefined"==typeof b?c="pushState"===d.options.mode?a.location.pathname.replace(d.options.root,""):"pushState"!==d.options.mode&&a.location?a.location.hash?a.location.hash.split(d.options.hashBang?"#!":"#")[1]:"":a._pathname||"":b===!1?("pushState"===d.options.mode?a.history.pushState({},null,d.options.root||"/"):a.location&&(a.location.hash=d.options.hashBang?"!":""),d):void 0},b.listen=function(){var a,c;return arguments[0]&&arguments[1]?(a=arguments[0],c=arguments[1]):c=arguments[0],function(){for(var a in c)this.add.call(this,a,c[a]);return this}.call(new b(a||{}))},c.global=[],c.prototype.preventDefault=function(){this.runCallback=!1},c.prototype.stopPropagation=function(){this.propagateEvent=!1},c.prototype.parent=function(){var a=!(!this.previousState||!this.previousState.value||this.previousState.value!=this.value);return!!a&&this.previousState},c.prototype.callback=function(){this.callbackRan=!0,this.timeStamp=Date.now(),this.next()},c.prototype.enqueue=function(a,b){for(var c=Array.isArray(a)?b<a.length?a.reverse():a:[a];c.length;)this.stack.splice(b||this.stack.length+1,0,c.shift());return this},c.prototype.next=function(){var a=this;return this.stack.shift().call(this.router,this.req,this,function(){a.next.call(a)})},d.prototype.parse=function(a){var c=a.match(this.regex),d=this,e={params:{},keys:this.keys,matches:(c||[]).slice(1),match:c};return b._forEach(e.matches,function(a,b){var c=d.keys[b]&&d.keys[b].name?d.keys[b].name:b;e.params[c]=a?decodeURIComponent(a):void 0}),e},b.CallStack=c,b.Request=d,"function"!=typeof a.define||a.define.amd.grapnel?"object"==typeof module&&"object"==typeof module.exports?module.exports=exports=b:a.Grapnel=b:a.define(function(c,d,e){return a.define.amd.grapnel=!0,b})}.call({},"object"==typeof window?window:this); | ||
| */ | ||
| var Grapnel=function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}();Object.defineProperty(e,"__esModule",{value:!0});var h=n(1),u=n(2),l=function(t){function e(t){i(this,e);var n=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return n._maxListeners=1/0,n.options={},n.defaults={root:"",target:"object"===("undefined"==typeof window?"undefined":o(window))?window:{},isWindow:"object"===("undefined"==typeof window?"undefined":o(window)),pushState:!1,hashBang:!1},n.options=Object.assign({},n.defaults,t),"object"===o(n.options.target)&&"function"==typeof n.options.target.addEventListener&&(n.options.target.addEventListener("hashchange",function(){n.emit("hashchange")}),n.options.target.addEventListener("popstate",function(t){return(!n.state||null!==n.state.previousState)&&void n.emit("navigate")})),n}return s(e,t),a(e,[{key:"add",value:function(t){var e=Array.prototype.slice.call(arguments,1,-1),n=Array.prototype.slice.call(arguments,-1)[0],i=this.options.root+t,r=new u.default(i),s=function(){var t=r.parse(this.path());if(t.match){var s={req:t,route:i,params:t.params,regex:t.match},o=new c(this,s).enqueue(e.concat(n));if(this.emit("match",o,t),!o.runCallback)return this;if(o.previousState=this.state,this.state=o,o.parent()&&o.parent().propagateEvent===!1)return o.propagateEvent=!1,this;o.callback()}return this}.bind(this),o=!this.options.pushState&&this.options.isWindow?"hashchange":"navigate";return s().on(o,s)}},{key:"get",value:function(){return this.add.apply(this,arguments)}},{key:"trigger",value:function(){return this.emit.apply(this,arguments)}},{key:"bind",value:function(){return this.on.apply(this,arguments)}},{key:"context",value:function(t){var e=this,n=Array.prototype.slice.call(arguments,1);return function(){for(var i=arguments.length,r=Array(i),s=0;s<i;s++)r[s]=arguments[s];var o=r[0],a=r.length>2?Array.prototype.slice.call(r,1,-1):[],h=Array.prototype.slice.call(r,-1)[0],u="/"!==t.slice(-1)&&"/"!==o&&""!==o?t+"/":t,l="/"!==o.substr(0,1)?o:o.substr(1),c=u+l;return e.add.apply(e,[c].concat(n).concat(a).concat([h]))}}},{key:"navigate",value:function(t,e){return this.path(t,e).emit("navigate"),this}},{key:"path",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.options.target,i=void 0,r=e.title;if("string"==typeof t){if(this.options.pushState&&"function"==typeof n.history.pushState){var s=e.state||n.history.state;i=this.options.root?this.options.root+t:t,n.history.pushState(s,r,i)}else if(n.location){var o=this.options.root?this.options.root+t:t;n.location.hash=(this.options.hashBang?"!":"")+o}else n.pathname=t||"";return this}if("undefined"==typeof t)return n.location&&n.location.pathname?n.location.pathname:n.pathname||"";if(t===!1){if(this.options.pushState&&"function"==typeof n.history.pushState){var a=e.state||n.history.state;n.history.pushState(a,r,this.options.root||"/")}else n.location&&(n.location.hash=this.options.hashBang?"!":"");return this}}}],[{key:"listen",value:function(){var t=void 0,n=void 0;return(arguments.length<=0?void 0:arguments[0])&&(arguments.length<=1?void 0:arguments[1])?(t=arguments.length<=0?void 0:arguments[0],n=arguments.length<=1?void 0:arguments[1]):n=arguments.length<=0?void 0:arguments[0],function(){for(var t in n)this.add.call(this,t,n[t]);return this}.call(new e(t||{}))}},{key:"toString",value:function(){return this.name}}]),e}(h.EventEmitter),c=function(){function t(e,n){return i(this,t),this.runCallback=!0,this.callbackRan=!0,this.propagateEvent=!0,this.stack=t.global.slice(0),this.router=e,this.value=e.path(),Object.assign(this,n),this}return a(t,[{key:"preventDefault",value:function(){this.runCallback=!1}},{key:"stopPropagation",value:function(){this.propagateEvent=!1}},{key:"parent",value:function(){var t=!(!this.previousState||!this.previousState.value||this.previousState.value!=this.value);return!!t&&this.previousState}},{key:"callback",value:function(){this.callbackRan=!0,this.timeStamp=Date.now(),this.next()}},{key:"enqueue",value:function(t,e){for(var n=Array.isArray(t)?e<t.length?t.reverse():t:[t];n.length;)this.stack.splice(e||this.stack.length+1,0,n.shift());return this}},{key:"next",value:function(){var t=this;return this.stack.shift().call(this.router,this.req,this,function(){return t.next()})}}]),t}();c.global=[],l.MiddlewareStack=c,l.Route=u.default,e=t.exports=l},function(t,e){"use strict";function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(t){return"function"==typeof t}function r(t){return"number"==typeof t}function s(t){return"object"===("undefined"==typeof t?"undefined":a(t))&&null!==t}function o(t){return void 0===t}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(t){if(!r(t)||t<0||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},n.prototype.emit=function(t){var e,n,r,a,h,u;if(this._events||(this._events={}),"error"===t&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;var l=new Error('Uncaught, unspecified "error" event. ('+e+")");throw l.context=e,l}if(n=this._events[t],o(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(s(n))for(a=Array.prototype.slice.call(arguments,1),u=n.slice(),r=u.length,h=0;h<r;h++)u[h].apply(this,a);return!0},n.prototype.addListener=function(t,e){var r;if(!i(e))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,i(e.listener)?e.listener:e),this._events[t]?s(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,s(this._events[t])&&!this._events[t].warned&&(r=o(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[t].length>r&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),r||(r=!0,e.apply(this,arguments))}if(!i(e))throw TypeError("listener must be a function");var r=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,r,o,a;if(!i(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],o=n.length,r=-1,n===e||i(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(s(n)){for(a=o;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){r=a;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],i(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?i(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(i(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}();Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(e,i,r,s){n(this,t),this.keys=[],this.strict=!1,this.sensitive=!1,this.path=e,this.regex=this.create()}return i(t,[{key:"parse",value:function(t){var e=this,n=t.match(this.regex),i={match:n,params:{},keys:this.keys,matches:(n||[]).slice(1)};return i.matches.forEach(function(t,n){var r=e.keys[n]&&e.keys[n].name?e.keys[n].name:n;i.params[r]=t?decodeURIComponent(t):void 0}),i}},{key:"create",value:function(){var t=this;if(this.path instanceof RegExp)return this.path;this.path instanceof Array&&(this.path="("+this.path.join("|")+")");var e=this.path.concat(this.strict?"":"/?").replace(/\/\(/g,"(?:/").replace(/\+/g,"__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g,function(e,n,i,r,s,o){return t.keys.push({name:r,optional:!!o}),n=n||"",""+(o?"":n)+"(?:"+(o?n:"")+(i||"")+(s||i&&"([^/.]+?)"||"([^/]+?)")+")"+(o||"")}).replace(/([\/.])/g,"\\$1").replace(/__plus__/g,"(.+)").replace(/\*/g,"(.*)");return new RegExp("^"+e+"$",this.sensitive?"":"i")}}]),t}();e.default=r}]); | ||
| //# sourceMappingURL=grapnel.min.js.map |
+28
-25
| module.exports = function(grunt){ | ||
| module.exports = function (grunt) { | ||
| grunt.initConfig({ | ||
| pkg: grunt.file.readJSON('package.json'), | ||
| info : { | ||
| banner : "/****\n"+ | ||
| " * Grapnel\n"+ | ||
| " * https://github.com/baseprime/grapnel\n"+ | ||
| " *\n"+ | ||
| " * @author <%= pkg.author %>\n"+ | ||
| " * @link <%= pkg.link %>\n"+ | ||
| " * @version <%= pkg.version %>\n"+ | ||
| " *\n"+ | ||
| " * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT\n"+ | ||
| "*/\n\n" | ||
| info: { | ||
| banner: "/****\n" + | ||
| " * Grapnel\n" + | ||
| " * https://github.com/baseprime/grapnel\n" + | ||
| " *\n" + | ||
| " * @author <%= pkg.author %>\n" + | ||
| " * @link <%= pkg.link %>\n" + | ||
| " *\n" + | ||
| " * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT\n" + | ||
| "*/\n\n" | ||
| }, | ||
| uglify: { | ||
| options: { | ||
| banner: '<%= info.banner %>', | ||
| banner: '<%= info.banner %>' | ||
| }, | ||
| dist: { | ||
| src: 'src/grapnel.js', | ||
| dest : 'dist/grapnel.min.js' | ||
| files: { | ||
| 'dist/grapnel.min.js': ['dist/grapnel.min.js'] | ||
| } | ||
| } | ||
| }, | ||
| concat : { | ||
| options : { | ||
| banner : '<%= info.banner %>' | ||
| }, | ||
| dist: { | ||
| src: 'src/grapnel.js', | ||
| dest : 'src/grapnel.js' | ||
| connect: { | ||
| server: { | ||
| options: { | ||
| port: 3002, | ||
| hostname: '*', | ||
| base: './test' | ||
| } | ||
| } | ||
| }, | ||
| qunit: { | ||
| files: ['test/index.html'] | ||
| all: ['test/index.html'] | ||
| } | ||
| }); | ||
| grunt.loadNpmTasks('grunt-contrib-concat'); | ||
| grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
| grunt.loadNpmTasks('grunt-contrib-connect'); | ||
| grunt.loadNpmTasks('grunt-contrib-qunit'); | ||
| grunt.registerTask('default', ['uglify', 'concat', 'qunit']); | ||
| grunt.registerTask('default', ['uglify', 'qunit']); | ||
| grunt.registerTask('build', ['uglify', 'qunit']); | ||
| grunt.registerTask('test', ['qunit']); | ||
| grunt.registerTask('serve-tests', ['connect:server:keepalive']); | ||
| } |
+17
-8
| { | ||
| "name": "grapnel", | ||
| "version": "0.6.4", | ||
| "description": "The smallest JavaScript Router with PushState & Named Parameter support", | ||
| "main": "src/grapnel.js", | ||
| "version": "0.7.0", | ||
| "description": "The first (and smallest!) JavaScript Router with PushState, Middleware, and Named Parameter support", | ||
| "main": "build/index.js", | ||
| "scripts": { | ||
| "test": "pushd ./test; python -m SimpleHTTPServer 3002; popd" | ||
| "test": "grunt test", | ||
| "serve-tests": "grunt serve-tests", | ||
| "watch": "tsc & webpack --watch", | ||
| "build": "grunt build" | ||
| }, | ||
@@ -39,7 +42,13 @@ "repository": { | ||
| "devDependencies": { | ||
| "grunt": "^0.4.5", | ||
| "grunt-contrib-concat": "^0.5.0", | ||
| "grunt-contrib-qunit": "^0.5.2", | ||
| "grunt-contrib-uglify": "^0.7.0" | ||
| "@types/node": "~9.4.0", | ||
| "babel-core": "^6.26.0", | ||
| "babel-loader": "^6.4.1", | ||
| "babel-preset-es2015": "^6.24.1", | ||
| "grunt": "^1.0.0", | ||
| "grunt-contrib-concat": "^1.0.1", | ||
| "grunt-contrib-connect": "^1.0.2", | ||
| "grunt-contrib-qunit": "^1.2.0", | ||
| "grunt-contrib-uglify": "^2.0.0", | ||
| "webpack": "^1.15.0" | ||
| } | ||
| } |
+102
-105
| Grapnel | ||
| ========== | ||
| #### The smallest (1100 bytes gzipped!) Client/Server-Side JavaScript Router with Named Parameters, HTML5 pushState, and Middleware support. | ||
| #### The first (started in 2010!) Client/Server-Side JavaScript Router with Named Parameters, HTML5 pushState, and Middleware support. | ||
@@ -11,3 +11,3 @@ ## Download/Installation | ||
| - [Production](https://raw.githubusercontent.com/baseprime/grapnel/master/dist/grapnel.min.js) | ||
| - [Development](https://raw.githubusercontent.com/baseprime/grapnel/master/src/grapnel.js) | ||
| - [Development](https://raw.githubusercontent.com/baseprime/grapnel/development/dist/grapnel.js) | ||
@@ -22,3 +22,3 @@ **Install with npm** | ||
| ``` | ||
| **Server only:** (with HTTP methods added, [more info](https://github.com/baseprime/grapnel/tree/server-router)) | ||
| **Server only:** (with HTTP methods added, [more info](https://github.com/baseprime/grapnel-server)) | ||
| ```bash | ||
@@ -31,7 +31,6 @@ npm install grapnel-server | ||
| - Supports routing using `pushState` or `hashchange` concurrently | ||
| - Supports Named Parameters similar to Sinatra, Restify, and Express | ||
| - Supports Named Parameters similar to Express, Sinatra, and Restify | ||
| - Middleware Support | ||
| - Works on the client or server-side | ||
| - Works on the client or server side | ||
| - RegExp Support | ||
| - RequreJS/AMD, Browserify, and CommonJS Compatibility | ||
| - Supports `#` or `#!` for `hashchange` routing | ||
@@ -44,7 +43,7 @@ - Unobtrusive, supports multiple routers on the same page | ||
| ```javascript | ||
| var router = new Grapnel(); | ||
| const router = new Grapnel(); | ||
| router.get('products/:category/:id?', function(req){ | ||
| var id = req.params.id, | ||
| category = req.params.category; | ||
| router.get('products/:category/:id?', function(req) { | ||
| let id = req.params.id; | ||
| let category = req.params.category; | ||
| // GET http://mysite.com/#products/widgets/134 | ||
@@ -56,10 +55,10 @@ console.log(category, id); | ||
| ## Using pushState | ||
| ## Using HTML5 pushState | ||
| ```javascript | ||
| var router = new Grapnel({ pushState : true }); | ||
| const router = new Grapnel({ pushState : true }); | ||
| router.get('/products/:category/:id?', function(req){ | ||
| var id = req.params.id, | ||
| category = req.params.category | ||
| router.get('/products/:category/:id?', function(req) { | ||
| let id = req.params.id; | ||
| let category = req.params.category; | ||
@@ -77,9 +76,9 @@ console.log(category, id); | ||
| ```javascript | ||
| router.get('products/:id?', function(req){ | ||
| router.get('products/:id?', function(req) { | ||
| // GET /file.html#products/134 | ||
| req.params.id | ||
| console.log(req.params.id); | ||
| // => 134 | ||
| }); | ||
| router.get('products/*', function(req){ | ||
| router.get('products/*', function(req) { | ||
| // The wildcard/asterisk will match anything after that point in the URL | ||
@@ -95,4 +94,4 @@ // Parameters are provided req.params using req.params[n], where n is the nth capture | ||
| ```javascript | ||
| var auth = function(req, event, next){ | ||
| user.auth(function(err){ | ||
| let auth = function(req, event, next) { | ||
| user.auth(function(err) { | ||
| req.user = this; | ||
@@ -103,3 +102,3 @@ next(); | ||
| router.get('/*', auth, function(req){ | ||
| router.get('/*', auth, function(req) { | ||
| console.log(req.user); | ||
@@ -114,9 +113,9 @@ }); | ||
| ```javascript | ||
| var usersRoute = router.context('/user/:id', getUser, getFollowers); // Middleware can be used here | ||
| let usersRoute = router.context('/user/:id', getUser, getFollowers); // Middleware can be used here | ||
| usersRoute('/', function(req, event){ | ||
| usersRoute('/', function(req, event) { | ||
| console.log('Profile', req.params.id); | ||
| }); | ||
| usersRoute('/followers', otherMiddleware, function(req, event){ // Middleware can be used here too | ||
| usersRoute('/followers', otherMiddleware, function(req, event) { // Middleware can be used here too | ||
| console.log('Followers', req.params.id); | ||
@@ -133,3 +132,17 @@ }); | ||
| ## Works as a server-side router | ||
| ```javascript | ||
| import { createServer } from 'http'; | ||
| import Grapnel from 'grapnel'; | ||
| const app = new Grapnel(); | ||
| app.get('/', function(req, route) { | ||
| route.res.end('Hello World!', 200); | ||
| }); | ||
| createServer(function(req, res) { | ||
| app.once('match', function(route) { | ||
| route.res = res; | ||
| }).navigate(req.url); | ||
| }).listen(3000); | ||
| ``` | ||
| **This is now simplified as a separate package** ([more info](https://github.com/baseprime/grapnel/tree/server-router)) | ||
@@ -139,23 +152,13 @@ ```bash | ||
| ``` | ||
| ```javascript | ||
| var http = require('http'), | ||
| app = require('grapnel-server'); | ||
| app.get('/', function(req, res, next){ | ||
| res.end('Hello World!', 200); | ||
| }); | ||
| http.createServer(app.start()).listen(3000); | ||
| ``` | ||
| ## Declaring Multiple Routes | ||
| ```javascript | ||
| var routes = { | ||
| 'products' : function(req){ | ||
| let routes = { | ||
| 'products' : function(req) { | ||
| // GET /file.html#products | ||
| }, | ||
| 'products/:category/:id?' : function(req){ | ||
| 'products/:category/:id?' : function(req) { | ||
| // GET /file.html#products/widgets/35 | ||
| req.params.category | ||
| console.log(req.params.category); | ||
| // => widgets | ||
@@ -171,3 +174,3 @@ } | ||
| ```javascript | ||
| var router = new Grapnel({ pushState : true, root : '/' }); | ||
| const router = new Grapnel({ pushState : true, root : '/' }); | ||
@@ -186,4 +189,4 @@ router.on('navigate', function(event){ | ||
| ```javascript | ||
| var expression = /^food\/tacos\/(.*)$/i; | ||
| var router = new Grapnel(); | ||
| const router = new Grapnel(); | ||
| let expression = /^food\/tacos\/(.*)$/i; | ||
@@ -197,18 +200,2 @@ router.get(expression, function(req, event){ | ||
| ## RequireJS/AMD, Browserify, and CommonJS Compatibility | ||
| ```javascript | ||
| require(['lib/grapnel'], function(Grapnel){ | ||
| var router = new Grapnel({ pushState : true }); | ||
| router.bind('navigate', function(){ | ||
| console.log('It works!'); | ||
| }); | ||
| router.navigate('/'); | ||
| }); | ||
| ``` | ||
| | ||
@@ -222,23 +209,8 @@ | ||
| ```javascript | ||
| var router = new Grapnel(); | ||
| const router = new Grapnel(); | ||
| ``` | ||
| Or you can declare your routes with a literal object: | ||
| ```javascript | ||
| Grapnel.listen({ | ||
| 'products/:id' : function(req){ | ||
| // Handler | ||
| } | ||
| }); | ||
| ``` | ||
| When declaring routes with a literal object, router options can be passed as the first parameter: | ||
| ```javascript | ||
| var opts = { pushState : true }; | ||
| Grapnel.listen(opts, routes); | ||
| ``` | ||
| ## Enabling PushState | ||
| ```javascript | ||
| var router = new Grapnel({ pushState : true }); | ||
| const router = new Grapnel({ pushState : true }); | ||
| ``` | ||
@@ -248,13 +220,13 @@ You can also specify a root URL by setting it as an option: | ||
| ```javascript | ||
| var router = new Grapnel({ root : '/public/search/', pushState : true }); | ||
| const router = new Grapnel({ root : '/app', pushState : true }); | ||
| ``` | ||
| The root may require a beginning slash and a trailing slash depending on how your application utilizes the router. | ||
| The root may require a beginning slash and a trailing slash depending on how you set up your routes. | ||
| ## Middleware | ||
| Grapnel uses middleware similar to how Express uses middleware. Middleware has access to the `req` object, `event` object, and the next middleware in the call stack (commonly denoted as `next`). Middleware must call `next()` to pass control to the next middleware, otherwise the router will stop. | ||
| Grapnel uses middleware similar to how Express uses middleware. Middleware has access to the `req` object, `route` object, and the next middleware in the call stack (commonly denoted as `next`). Middleware must call `next()` to pass control to the next middleware, otherwise the router will stop. | ||
| For more information about how middleware works, see [Using Middleware](http://expressjs.com/guide/using-middleware.html). | ||
| ```javascript | ||
| var user = function(req, event, next){ | ||
| user.get(function(err){ | ||
| let user = function(req, route, next) { | ||
| user.get(function(err) { | ||
| req.user = this; | ||
@@ -265,3 +237,3 @@ next(); | ||
| router.get('/user/*', user, function(req){ | ||
| router.get('/user/*', user, function(req) { | ||
| console.log(req.user); | ||
@@ -271,2 +243,18 @@ }); | ||
| ## Declaring your routes with an object literal: | ||
| ```javascript | ||
| Grapnel.listen({ | ||
| 'products/:id' : function(req) { | ||
| // Handler | ||
| } | ||
| }); | ||
| ``` | ||
| When declaring routes with a literal object, router options can be passed as the first parameter: | ||
| ```javascript | ||
| let opts = { pushState : true }; | ||
| Grapnel.listen(opts, routes); | ||
| ``` | ||
| ## Navigation | ||
@@ -280,4 +268,4 @@ If pushState is enabled, you can navigate through your application with `router.navigate`: | ||
| ```javascript | ||
| router.on('match', function(event){ | ||
| event.preventDefault(); // Stops event handler | ||
| router.on('match', function(routeEvent) { | ||
| routeEvent.preventDefault(); // Stops event handler | ||
| }); | ||
@@ -288,7 +276,7 @@ ``` | ||
| ```javascript | ||
| router.get('/products/:id', function(req, event){ | ||
| event.stopPropagation(); // Stops propagation of the event | ||
| router.get('/products/:id', function(req, routeEvent) { | ||
| routeEvent.stopPropagation(); // Stops propagation of the event | ||
| }); | ||
| router.get('/products/widgets', function(req, event){ | ||
| router.get('/products/widgets', function(req, routeEvent) { | ||
| // This will not be executed | ||
@@ -301,16 +289,16 @@ }); | ||
| ## 404 Pages | ||
| You can specify a route that only uses a wildcard `*` as your final route, then use `event.parent()` which returns `false` if the call stack doesn't have any other routes to run. | ||
| You can specify a route that only uses a wildcard `*` as your final route, then use `route.parent()` which returns `false` if the call stack doesn't have any other routes to run. | ||
| ```javascript | ||
| var routes = { | ||
| '/' : function(req, e){ | ||
| let routes = { | ||
| '/' : function(req, route) { | ||
| // Handle route | ||
| }, | ||
| '/store/products/:id' : function(req, e){ | ||
| '/store/products/:id' : function(req, route) { | ||
| // Handle route | ||
| }, | ||
| '/category/:id' : function(req, e){ | ||
| '/category/:id' : function(req, route) { | ||
| // Handle route | ||
| }, | ||
| '/*' : function(req, e){ | ||
| if(!e.parent()){ | ||
| '/*' : function(req, route) { | ||
| if(!route.parent()){ | ||
| // Handle 404 | ||
@@ -324,2 +312,9 @@ } | ||
| ## Setting window state | ||
| ```javascript | ||
| router.navigate('/', { | ||
| state: { ...windowState } | ||
| }); | ||
| ``` | ||
| | ||
@@ -329,3 +324,3 @@ | ||
| # API Documentation | ||
| # Documentation | ||
@@ -338,5 +333,5 @@ ##### `get` Adds a listeners and middleware for routes | ||
| */ | ||
| router.get('/store/:category/:id?', function(req, event){ | ||
| var category = req.params.category, | ||
| id = req.params.id; | ||
| router.get('/store/:category/:id?', function(req, route){ | ||
| let category = req.params.category; | ||
| let id = req.params.id; | ||
@@ -351,4 +346,5 @@ console.log('Product #%s in %s', id, category); | ||
| * @param {String} path relative to root | ||
| * @param {Object} options navigation options | ||
| */ | ||
| router.navigate('/products/123'); | ||
| router.navigate('/products/123', ...options); | ||
| ``` | ||
@@ -362,3 +358,3 @@ | ||
| */ | ||
| router.on('myevent', function(event){ | ||
| router.on('myevent', function(event) { | ||
| console.log('Grapnel works!'); | ||
@@ -374,3 +370,3 @@ }); | ||
| */ | ||
| router.once('init', function(){ | ||
| router.once('init', function() { | ||
| console.log('This will only be executed once'); | ||
@@ -380,9 +376,9 @@ }); | ||
| ##### `trigger` Triggers an event | ||
| ##### `emit` Triggers an event | ||
| ```javascript | ||
| /** | ||
| * @param {String} event name | ||
| * @param {Mixed} [attributes] Parameters that will be applied to event handler | ||
| * @param {...Mixed} attributes Parameters that will be applied to event handler | ||
| */ | ||
| router.trigger('event', eventArg1, eventArg2, etc); | ||
| router.emit('event', eventArg1, eventArg2, ...etc); | ||
| ``` | ||
@@ -398,5 +394,5 @@ | ||
| */ | ||
| var usersRoute = router.context('/user/:id'); | ||
| let usersRoute = router.context('/user/:id'); | ||
| usersRoute('/followers', function(req, event){ | ||
| usersRoute('/followers', function(req, route) { | ||
| console.log('Followers', req.params.id); | ||
@@ -415,4 +411,4 @@ }); | ||
| ##### `bind` An alias of `on` | ||
| ##### `trigger` An alias of `emit` | ||
| ##### `add` An alias of `get` | ||
| ##### `fragment` (Deprecated) | ||
@@ -422,2 +418,3 @@ ## Options | ||
| * `root` Root of your app, all navigation will be relative to this | ||
| * `target` Target object where the router will apply its changes (default: `window`) | ||
| * `hashBang` Enable `#!` as the anchor of a `hashchange` router instead of using just a `#` | ||
@@ -424,0 +421,0 @@ |
-424
| /**** | ||
| * Grapnel | ||
| * https://github.com/baseprime/grapnel | ||
| * | ||
| * @author Greg Sabia Tucker <greg@narrowlabs.com> | ||
| * @link http://basepri.me | ||
| * @version 0.6.4 | ||
| * | ||
| * Released under MIT License. See LICENSE.txt or http://opensource.org/licenses/MIT | ||
| */ | ||
| !(function(root) { | ||
| function Grapnel(opts) { | ||
| "use strict"; | ||
| var self = this; // Scope reference | ||
| this.events = {}; // Event Listeners | ||
| this.state = null; // Router state object | ||
| this.options = opts || {}; // Options | ||
| this.options.env = this.options.env || (!!(Object.keys(root).length === 0 && process && process.browser !== true) ? 'server' : 'client'); | ||
| this.options.mode = this.options.mode || (!!(this.options.env !== 'server' && this.options.pushState && root.history && root.history.pushState) ? 'pushState' : 'hashchange'); | ||
| this.version = '0.6.4'; // Version | ||
| if ('function' === typeof root.addEventListener) { | ||
| root.addEventListener('hashchange', function() { | ||
| self.trigger('hashchange'); | ||
| }); | ||
| root.addEventListener('popstate', function(e) { | ||
| // Make sure popstate doesn't run on init -- this is a common issue with Safari and old versions of Chrome | ||
| if (self.state && self.state.previousState === null) return false; | ||
| self.trigger('navigate'); | ||
| }); | ||
| } | ||
| return this; | ||
| }; | ||
| /** | ||
| * Create a RegExp Route from a string | ||
| * This is the heart of the router and I've made it as small as possible! | ||
| * | ||
| * @param {String} Path of route | ||
| * @param {Array} Array of keys to fill | ||
| * @param {Bool} Case sensitive comparison | ||
| * @param {Bool} Strict mode | ||
| */ | ||
| Grapnel.regexRoute = function(path, keys, sensitive, strict) { | ||
| if (path instanceof RegExp) return path; | ||
| if (path instanceof Array) path = '(' + path.join('|') + ')'; | ||
| // Build route RegExp | ||
| path = path.concat(strict ? '' : '/?') | ||
| .replace(/\/\(/g, '(?:/') | ||
| .replace(/\+/g, '__plus__') | ||
| .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional) { | ||
| keys.push({ | ||
| name: key, | ||
| optional: !!optional | ||
| }); | ||
| slash = slash || ''; | ||
| return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); | ||
| }) | ||
| .replace(/([\/.])/g, '\\$1') | ||
| .replace(/__plus__/g, '(.+)') | ||
| .replace(/\*/g, '(.*)'); | ||
| return new RegExp('^' + path + '$', sensitive ? '' : 'i'); | ||
| }; | ||
| /** | ||
| * ForEach workaround utility | ||
| * | ||
| * @param {Array} to iterate | ||
| * @param {Function} callback | ||
| */ | ||
| Grapnel._forEach = function(a, callback) { | ||
| if (typeof Array.prototype.forEach === 'function') return Array.prototype.forEach.call(a, callback); | ||
| // Replicate forEach() | ||
| return function(c, next) { | ||
| for (var i = 0, n = this.length; i < n; ++i) { | ||
| c.call(next, this[i], i, this); | ||
| } | ||
| }.call(a, callback); | ||
| }; | ||
| /** | ||
| * Add an route and handler | ||
| * | ||
| * @param {String|RegExp} route name | ||
| * @return {self} Router | ||
| */ | ||
| Grapnel.prototype.get = Grapnel.prototype.add = function(route) { | ||
| var self = this, | ||
| middleware = Array.prototype.slice.call(arguments, 1, -1), | ||
| handler = Array.prototype.slice.call(arguments, -1)[0], | ||
| request = new Request(route); | ||
| var invoke = function RouteHandler() { | ||
| // Build request parameters | ||
| var req = request.parse(self.path()); | ||
| // Check if matches are found | ||
| if (req.match) { | ||
| // Match found | ||
| var extra = { | ||
| route: route, | ||
| params: req.params, | ||
| req: req, | ||
| regex: req.match | ||
| }; | ||
| // Create call stack -- add middleware first, then handler | ||
| var stack = new CallStack(self, extra).enqueue(middleware.concat(handler)); | ||
| // Trigger main event | ||
| self.trigger('match', stack, req); | ||
| // Continue? | ||
| if (!stack.runCallback) return self; | ||
| // Previous state becomes current state | ||
| stack.previousState = self.state; | ||
| // Save new state | ||
| self.state = stack; | ||
| // Prevent this handler from being called if parent handler in stack has instructed not to propagate any more events | ||
| if (stack.parent() && stack.parent().propagateEvent === false) { | ||
| stack.propagateEvent = false; | ||
| return self; | ||
| } | ||
| // Call handler | ||
| stack.callback(); | ||
| } | ||
| // Returns self | ||
| return self; | ||
| }; | ||
| // Event name | ||
| var eventName = (self.options.mode !== 'pushState' && self.options.env !== 'server') ? 'hashchange' : 'navigate'; | ||
| // Invoke when route is defined, and once again when app navigates | ||
| return invoke().on(eventName, invoke); | ||
| }; | ||
| /** | ||
| * Fire an event listener | ||
| * | ||
| * @param {String} event name | ||
| * @param {Mixed} [attributes] Parameters that will be applied to event handler | ||
| * @return {self} Router | ||
| */ | ||
| Grapnel.prototype.trigger = function(event) { | ||
| var self = this, | ||
| params = Array.prototype.slice.call(arguments, 1); | ||
| // Call matching events | ||
| if (this.events[event]) { | ||
| Grapnel._forEach(this.events[event], function(fn) { | ||
| fn.apply(self, params); | ||
| }); | ||
| } | ||
| return this; | ||
| }; | ||
| /** | ||
| * Add an event listener | ||
| * | ||
| * @param {String} event name (multiple events can be called when separated by a space " ") | ||
| * @param {Function} callback | ||
| * @return {self} Router | ||
| */ | ||
| Grapnel.prototype.on = Grapnel.prototype.bind = function(event, handler) { | ||
| var self = this, | ||
| events = event.split(' '); | ||
| Grapnel._forEach(events, function(event) { | ||
| if (self.events[event]) { | ||
| self.events[event].push(handler); | ||
| } else { | ||
| self.events[event] = [handler]; | ||
| } | ||
| }); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Allow event to be called only once | ||
| * | ||
| * @param {String} event name(s) | ||
| * @param {Function} callback | ||
| * @return {self} Router | ||
| */ | ||
| Grapnel.prototype.once = function(event, handler) { | ||
| var ran = false; | ||
| return this.on(event, function() { | ||
| if (ran) return false; | ||
| ran = true; | ||
| handler.apply(this, arguments); | ||
| handler = null; | ||
| return true; | ||
| }); | ||
| }; | ||
| /** | ||
| * @param {String} Route context (without trailing slash) | ||
| * @param {[Function]} Middleware (optional) | ||
| * @return {Function} Adds route to context | ||
| */ | ||
| Grapnel.prototype.context = function(context) { | ||
| var self = this, | ||
| middleware = Array.prototype.slice.call(arguments, 1); | ||
| return function() { | ||
| var value = arguments[0], | ||
| submiddleware = (arguments.length > 2) ? Array.prototype.slice.call(arguments, 1, -1) : [], | ||
| handler = Array.prototype.slice.call(arguments, -1)[0], | ||
| prefix = (context.slice(-1) !== '/' && value !== '/' && value !== '') ? context + '/' : context, | ||
| path = (value.substr(0, 1) !== '/') ? value : value.substr(1), | ||
| pattern = prefix + path; | ||
| return self.add.apply(self, [pattern].concat(middleware).concat(submiddleware).concat([handler])); | ||
| } | ||
| }; | ||
| /** | ||
| * Navigate through history API | ||
| * | ||
| * @param {String} Pathname | ||
| * @return {self} Router | ||
| */ | ||
| Grapnel.prototype.navigate = function(path) { | ||
| return this.path(path).trigger('navigate'); | ||
| }; | ||
| Grapnel.prototype.path = function(pathname) { | ||
| var self = this, | ||
| frag; | ||
| if ('string' === typeof pathname) { | ||
| // Set path | ||
| if (self.options.mode === 'pushState') { | ||
| frag = (self.options.root) ? (self.options.root + pathname) : pathname; | ||
| root.history.pushState({}, null, frag); | ||
| } else if (root.location) { | ||
| root.location.hash = (self.options.hashBang ? '!' : '') + pathname; | ||
| } else { | ||
| root._pathname = pathname || ''; | ||
| } | ||
| return this; | ||
| } else if ('undefined' === typeof pathname) { | ||
| // Get path | ||
| if (self.options.mode === 'pushState') { | ||
| frag = root.location.pathname.replace(self.options.root, ''); | ||
| } else if (self.options.mode !== 'pushState' && root.location) { | ||
| frag = (root.location.hash) ? root.location.hash.split((self.options.hashBang ? '#!' : '#'))[1] : ''; | ||
| } else { | ||
| frag = root._pathname || ''; | ||
| } | ||
| return frag; | ||
| } else if (pathname === false) { | ||
| // Clear path | ||
| if (self.options.mode === 'pushState') { | ||
| root.history.pushState({}, null, self.options.root || '/'); | ||
| } else if (root.location) { | ||
| root.location.hash = (self.options.hashBang) ? '!' : ''; | ||
| } | ||
| return self; | ||
| } | ||
| }; | ||
| /** | ||
| * Create routes based on an object | ||
| * | ||
| * @param {Object} [Options, Routes] | ||
| * @param {Object Routes} | ||
| * @return {self} Router | ||
| */ | ||
| Grapnel.listen = function() { | ||
| var opts, routes; | ||
| if (arguments[0] && arguments[1]) { | ||
| opts = arguments[0]; | ||
| routes = arguments[1]; | ||
| } else { | ||
| routes = arguments[0]; | ||
| } | ||
| // Return a new Grapnel instance | ||
| return (function() { | ||
| // TODO: Accept multi-level routes | ||
| for (var key in routes) { | ||
| this.add.call(this, key, routes[key]); | ||
| } | ||
| return this; | ||
| }).call(new Grapnel(opts || {})); | ||
| }; | ||
| /** | ||
| * Create a call stack that can be enqueued by handlers and middleware | ||
| * | ||
| * @param {Object} Router | ||
| * @param {Object} Extend | ||
| * @return {self} CallStack | ||
| */ | ||
| function CallStack(router, extendObj) { | ||
| this.stack = CallStack.global.slice(0); | ||
| this.router = router; | ||
| this.runCallback = true; | ||
| this.callbackRan = false; | ||
| this.propagateEvent = true; | ||
| this.value = router.path(); | ||
| for (var key in extendObj) { | ||
| this[key] = extendObj[key]; | ||
| } | ||
| return this; | ||
| }; | ||
| /** | ||
| * Build request parameters and allow them to be checked against a string (usually the current path) | ||
| * | ||
| * @param {String} Route | ||
| * @return {self} Request | ||
| */ | ||
| function Request(route) { | ||
| this.route = route; | ||
| this.keys = []; | ||
| this.regex = Grapnel.regexRoute(route, this.keys); | ||
| }; | ||
| // This allows global middleware | ||
| CallStack.global = []; | ||
| /** | ||
| * Prevent a callback from being called | ||
| * | ||
| * @return {self} CallStack | ||
| */ | ||
| CallStack.prototype.preventDefault = function() { | ||
| this.runCallback = false; | ||
| }; | ||
| /** | ||
| * Prevent any future callbacks from being called | ||
| * | ||
| * @return {self} CallStack | ||
| */ | ||
| CallStack.prototype.stopPropagation = function() { | ||
| this.propagateEvent = false; | ||
| }; | ||
| /** | ||
| * Get parent state | ||
| * | ||
| * @return {Object} Previous state | ||
| */ | ||
| CallStack.prototype.parent = function() { | ||
| var hasParentEvents = !!(this.previousState && this.previousState.value && this.previousState.value == this.value); | ||
| return (hasParentEvents) ? this.previousState : false; | ||
| }; | ||
| /** | ||
| * Run a callback (calls to next) | ||
| * | ||
| * @return {self} CallStack | ||
| */ | ||
| CallStack.prototype.callback = function() { | ||
| this.callbackRan = true; | ||
| this.timeStamp = Date.now(); | ||
| this.next(); | ||
| }; | ||
| /** | ||
| * Add handler or middleware to the stack | ||
| * | ||
| * @param {Function|Array} Handler or a array of handlers | ||
| * @param {Int} Index to start inserting | ||
| * @return {self} CallStack | ||
| */ | ||
| CallStack.prototype.enqueue = function(handler, atIndex) { | ||
| var handlers = (!Array.isArray(handler)) ? [handler] : ((atIndex < handler.length) ? handler.reverse() : handler); | ||
| while (handlers.length) { | ||
| this.stack.splice(atIndex || this.stack.length + 1, 0, handlers.shift()); | ||
| } | ||
| return this; | ||
| }; | ||
| /** | ||
| * Call to next item in stack -- this adds the `req`, `event`, and `next()` arguments to all middleware | ||
| * | ||
| * @return {self} CallStack | ||
| */ | ||
| CallStack.prototype.next = function() { | ||
| var self = this; | ||
| return this.stack.shift().call(this.router, this.req, this, function next() { | ||
| self.next.call(self); | ||
| }); | ||
| }; | ||
| /** | ||
| * Match a path string -- returns a request object if there is a match -- returns false otherwise | ||
| * | ||
| * @return {Object} req | ||
| */ | ||
| Request.prototype.parse = function(path) { | ||
| var match = path.match(this.regex), | ||
| self = this; | ||
| var req = { | ||
| params: {}, | ||
| keys: this.keys, | ||
| matches: (match || []).slice(1), | ||
| match: match | ||
| }; | ||
| // Build parameters | ||
| Grapnel._forEach(req.matches, function(value, i) { | ||
| var key = (self.keys[i] && self.keys[i].name) ? self.keys[i].name : i; | ||
| // Parameter key will be its key or the iteration index. This is useful if a wildcard (*) is matched | ||
| req.params[key] = (value) ? decodeURIComponent(value) : undefined; | ||
| }); | ||
| return req; | ||
| }; | ||
| // Append utility constructors to Grapnel | ||
| Grapnel.CallStack = CallStack; | ||
| Grapnel.Request = Request; | ||
| if ('function' === typeof root.define && !root.define.amd.grapnel) { | ||
| root.define(function(require, exports, module) { | ||
| root.define.amd.grapnel = true; | ||
| return Grapnel; | ||
| }); | ||
| } else if ('object' === typeof module && 'object' === typeof module.exports) { | ||
| module.exports = exports = Grapnel; | ||
| } else { | ||
| root.Grapnel = Grapnel; | ||
| } | ||
| }).call({}, ('object' === typeof window) ? window : this); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
187779
408.45%22
144.44%1345
179.63%10
150%399
-0.75%2
100%