UNPKG

http-micro

Version:

Micro-framework on top of node's http module

54 lines (53 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class RouteContext { constructor(pathname) { this.params = null; this._pendingRoutePath = pathname; } push(match) { if (this._matches) { this._matches.push(match); } else { this._matches = [match]; } if (match.params) { if (!this.params) this.params = {}; Object.assign(this.params, match.params); } if (match.path) { this._setPendingRoutePath(this.getPendingRoutePath().slice(match.path.length)); } this._currentMatch = match; } pop() { let m = [].pop.call(this._matches); this._currentMatch = this._getLastMatch(); this._setPendingRoutePath(m.path + this.getPendingRoutePath()); return m; } getPendingRoutePath() { return this._pendingRoutePath; } getMatches() { return this._matches; } getCurrentMatch() { return this._currentMatch; } _setPendingRoutePath(value) { this._pendingRoutePath = value; } _getLastMatch() { let matches = this.getMatches(); if (matches) { let len = matches.length; if (len > 0) return matches[len - 1]; } return null; } } exports.RouteContext = RouteContext;