From 81d91e9e46f98d3df2bc229a06478cc2a835fad3 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Fri, 14 Aug 2015 02:30:44 -0400 Subject: [PATCH] chore(all): prepare release 0.6.2 --- bower.json | 2 +- dist/amd/aurelia-route-recognizer.d.ts | 60 ++--- dist/amd/aurelia-route-recognizer.js | 182 +++++++------- dist/aurelia-route-recognizer.d.ts | 60 ++--- dist/aurelia-route-recognizer.js | 248 ++++++++++---------- dist/commonjs/aurelia-route-recognizer.d.ts | 60 ++--- dist/commonjs/aurelia-route-recognizer.js | 184 +++++++-------- dist/es6/aurelia-route-recognizer.d.ts | 60 ++--- dist/es6/aurelia-route-recognizer.js | 248 ++++++++++---------- dist/system/aurelia-route-recognizer.d.ts | 60 ++--- dist/system/aurelia-route-recognizer.js | 186 +++++++-------- doc/CHANGELOG.md | 13 + package.json | 2 +- 13 files changed, 687 insertions(+), 678 deletions(-) diff --git a/bower.json b/bower.json index f54dad3..6a0cbde 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-route-recognizer", - "version": "0.6.1", + "version": "0.6.2", "description": "A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.", "keywords": [ "aurelia", diff --git a/dist/amd/aurelia-route-recognizer.d.ts b/dist/amd/aurelia-route-recognizer.d.ts index b6a706b..ce4bf91 100644 --- a/dist/amd/aurelia-route-recognizer.d.ts +++ b/dist/amd/aurelia-route-recognizer.d.ts @@ -1,5 +1,5 @@ declare module 'aurelia-route-recognizer' { - import core from 'core-js'; + import * as core from 'core-js'; export interface RouteHandler { name: string; } @@ -22,6 +22,31 @@ declare module 'aurelia-route-recognizer' { repeat?: boolean; } + // A State has a character specification and (`charSpec`) and a list of possible + // subsequent states (`nextStates`). + // + // If a State is an accepting state, it will also have several additional + // properties: + // + // * `regex`: A regular expression that is used to extract parameters from paths + // that reached this accepting state. + // * `handlers`: Information on how to convert the list of captures into calls + // to registered handlers with the specified parameters. + // * `types`: How many static, dynamic, or star segments in this route. Used to + // decide which route to use if multiple registered routes match a path. + // + // Currently, State is implemented naively by looping over `nextStates` and + // comparing a character specification against a character. A more efficient + // implementation would use a hash of keys pointing at one or more next states. + export class State { + constructor(charSpec: CharSpec); + get(charSpec: CharSpec): State; + put(charSpec: CharSpec): State; + + // Find a list of child states matching the next character + match(ch: string): State[]; + } + // A Segment represents a segment in the original route description. // Each Segment type provides an `eachChar` and `regex` method. // @@ -40,53 +65,28 @@ declare module 'aurelia-route-recognizer' { // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class DynamicSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class StarSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class EpsilonSegment { - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } - // A State has a character specification and (`charSpec`) and a list of possible - // subsequent states (`nextStates`). - // - // If a State is an accepting state, it will also have several additional - // properties: - // - // * `regex`: A regular expression that is used to extract parameters from paths - // that reached this accepting state. - // * `handlers`: Information on how to convert the list of captures into calls - // to registered handlers with the specified parameters. - // * `types`: How many static, dynamic, or star segments in this route. Used to - // decide which route to use if multiple registered routes match a path. - // - // Currently, State is implemented naively by looping over `nextStates` and - // comparing a character specification against a character. A more efficient - // implementation would use a hash of keys pointing at one or more next states. - export class State { - constructor(charSpec: CharSpec); - get(charSpec: CharSpec): State; - put(charSpec: CharSpec): State; - - // Find a list of child states matching the next character - match(ch: string): State[]; - } - /** * Class that parses route patterns and matches path strings. * diff --git a/dist/amd/aurelia-route-recognizer.js b/dist/amd/aurelia-route-recognizer.js index d647cbf..560772f 100644 --- a/dist/amd/aurelia-route-recognizer.js +++ b/dist/amd/aurelia-route-recognizer.js @@ -3,11 +3,88 @@ define(['exports', 'core-js'], function (exports, _coreJs) { exports.__esModule = true; - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - var _core = _interopRequireDefault(_coreJs); + var State = (function () { + function State(charSpec) { + _classCallCheck(this, State); + + this.charSpec = charSpec; + this.nextStates = []; + } + + State.prototype.get = function get(charSpec) { + for (var _iterator = this.nextStates, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var child = _ref; + + var isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; + + if (isEqual) { + return child; + } + } + }; + + State.prototype.put = function put(charSpec) { + var state = this.get(charSpec); + + if (state) { + return state; + } + + state = new State(charSpec); + + this.nextStates.push(state); + + if (charSpec.repeat) { + state.nextStates.push(state); + } + + return state; + }; + + State.prototype.match = function match(ch) { + var nextStates = this.nextStates, + results = [], + child, + charSpec, + chars; + + for (var i = 0, l = nextStates.length; i < l; i++) { + child = nextStates[i]; + + charSpec = child.charSpec; + + if (typeof (chars = charSpec.validChars) !== 'undefined') { + if (chars.indexOf(ch) !== -1) { + results.push(child); + } + } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { + if (chars.indexOf(ch) === -1) { + results.push(child); + } + } + } + + return results; + }; + + return State; + })(); + + exports.State = State; + ; var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; @@ -21,19 +98,19 @@ define(['exports', 'core-js'], function (exports, _coreJs) { } StaticSegment.prototype.eachChar = function eachChar(callback) { - for (var _iterator = this.string, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; + for (var _iterator2 = this.string, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; } - var ch = _ref; + var ch = _ref2; callback({ validChars: ch }); } @@ -122,87 +199,6 @@ define(['exports', 'core-js'], function (exports, _coreJs) { exports.EpsilonSegment = EpsilonSegment; - var State = (function () { - function State(charSpec) { - _classCallCheck(this, State); - - this.charSpec = charSpec; - this.nextStates = []; - } - - State.prototype.get = function get(charSpec) { - for (var _iterator2 = this.nextStates, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var child = _ref2; - - var isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; - - if (isEqual) { - return child; - } - } - }; - - State.prototype.put = function put(charSpec) { - var state = this.get(charSpec); - - if (state) { - return state; - } - - state = new State(charSpec); - - this.nextStates.push(state); - - if (charSpec.repeat) { - state.nextStates.push(state); - } - - return state; - }; - - State.prototype.match = function match(ch) { - var nextStates = this.nextStates, - results = [], - child, - charSpec, - chars; - - for (var i = 0, l = nextStates.length; i < l; i++) { - child = nextStates[i]; - - charSpec = child.charSpec; - - if (typeof (chars = charSpec.validChars) !== 'undefined') { - if (chars.indexOf(ch) !== -1) { - results.push(child); - } - } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { - if (chars.indexOf(ch) === -1) { - results.push(child); - } - } - } - - return results; - }; - - return State; - })(); - - exports.State = State; - ; - var RouteRecognizer = (function () { function RouteRecognizer() { _classCallCheck(this, RouteRecognizer); diff --git a/dist/aurelia-route-recognizer.d.ts b/dist/aurelia-route-recognizer.d.ts index b6a706b..ce4bf91 100644 --- a/dist/aurelia-route-recognizer.d.ts +++ b/dist/aurelia-route-recognizer.d.ts @@ -1,5 +1,5 @@ declare module 'aurelia-route-recognizer' { - import core from 'core-js'; + import * as core from 'core-js'; export interface RouteHandler { name: string; } @@ -22,6 +22,31 @@ declare module 'aurelia-route-recognizer' { repeat?: boolean; } + // A State has a character specification and (`charSpec`) and a list of possible + // subsequent states (`nextStates`). + // + // If a State is an accepting state, it will also have several additional + // properties: + // + // * `regex`: A regular expression that is used to extract parameters from paths + // that reached this accepting state. + // * `handlers`: Information on how to convert the list of captures into calls + // to registered handlers with the specified parameters. + // * `types`: How many static, dynamic, or star segments in this route. Used to + // decide which route to use if multiple registered routes match a path. + // + // Currently, State is implemented naively by looping over `nextStates` and + // comparing a character specification against a character. A more efficient + // implementation would use a hash of keys pointing at one or more next states. + export class State { + constructor(charSpec: CharSpec); + get(charSpec: CharSpec): State; + put(charSpec: CharSpec): State; + + // Find a list of child states matching the next character + match(ch: string): State[]; + } + // A Segment represents a segment in the original route description. // Each Segment type provides an `eachChar` and `regex` method. // @@ -40,53 +65,28 @@ declare module 'aurelia-route-recognizer' { // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class DynamicSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class StarSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class EpsilonSegment { - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } - // A State has a character specification and (`charSpec`) and a list of possible - // subsequent states (`nextStates`). - // - // If a State is an accepting state, it will also have several additional - // properties: - // - // * `regex`: A regular expression that is used to extract parameters from paths - // that reached this accepting state. - // * `handlers`: Information on how to convert the list of captures into calls - // to registered handlers with the specified parameters. - // * `types`: How many static, dynamic, or star segments in this route. Used to - // decide which route to use if multiple registered routes match a path. - // - // Currently, State is implemented naively by looping over `nextStates` and - // comparing a character specification against a character. A more efficient - // implementation would use a hash of keys pointing at one or more next states. - export class State { - constructor(charSpec: CharSpec); - get(charSpec: CharSpec): State; - put(charSpec: CharSpec): State; - - // Find a list of child states matching the next character - match(ch: string): State[]; - } - /** * Class that parses route patterns and matches path strings. * diff --git a/dist/aurelia-route-recognizer.js b/dist/aurelia-route-recognizer.js index 1002d55..b8937e2 100644 --- a/dist/aurelia-route-recognizer.js +++ b/dist/aurelia-route-recognizer.js @@ -1,30 +1,89 @@ -import core from 'core-js'; +import * as core from 'core-js'; -interface RouteHandler { - name:string; -} +// A State has a character specification and (`charSpec`) and a list of possible +// subsequent states (`nextStates`). +// +// If a State is an accepting state, it will also have several additional +// properties: +// +// * `regex`: A regular expression that is used to extract parameters from paths +// that reached this accepting state. +// * `handlers`: Information on how to convert the list of captures into calls +// to registered handlers with the specified parameters. +// * `types`: How many static, dynamic, or star segments in this route. Used to +// decide which route to use if multiple registered routes match a path. +// +// Currently, State is implemented naively by looping over `nextStates` and +// comparing a character specification against a character. A more efficient +// implementation would use a hash of keys pointing at one or more next states. -interface ConfigurableRoute { - path:string; - handler:RouteHandler; -} +export class State { + constructor(charSpec: CharSpec) { + this.charSpec = charSpec; + this.nextStates = []; + } -interface HandlerEntry { - handler:RouteHandler; - names:string[]; -} + get(charSpec: CharSpec): State { + for (let child of this.nextStates) { + var isEqual = child.charSpec.validChars === charSpec.validChars && + child.charSpec.invalidChars === charSpec.invalidChars; -interface RecognizedRoute { - handler:RouteHandler; - params:Object; - isDynamic:boolean; -} + if (isEqual) { + return child; + } + } + } -interface CharSpec { - invalidChars?:string; - validChars?:string; - repeat?:boolean; -} + put(charSpec: CharSpec): State { + var state = this.get(charSpec); + + // If the character specification already exists in a child of the current + // state, just return that state. + if (state) { + return state; + } + + // Make a new state for the character spec + state = new State(charSpec); + + // Insert the new state as a child of the current state + this.nextStates.push(state); + + // If this character specification repeats, insert the new state as a child + // of itself. Note that this will not trigger an infinite loop because each + // transition during recognition consumes a character. + if (charSpec.repeat) { + state.nextStates.push(state); + } + + // Return the new state + return state; + } + + // Find a list of child states matching the next character + match(ch: string): State[] { + var nextStates = this.nextStates, results = [], + child, charSpec, chars; + + for (var i = 0, l = nextStates.length; i < l; i++) { + child = nextStates[i]; + + charSpec = child.charSpec; + + if (typeof (chars = charSpec.validChars) !== 'undefined') { + if (chars.indexOf(ch) !== -1) { + results.push(child); + } + } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { + if (chars.indexOf(ch) === -1) { + results.push(child); + } + } + } + + return results; + } +}; const specials = [ '/', '.', '*', '+', '?', '|', @@ -55,149 +114,90 @@ export class StaticSegment { this.string = string; } - eachChar(callback:(spec:CharSpec) => void) { + eachChar(callback: (spec:CharSpec) => void): void { for (let ch of this.string) { callback({ validChars: ch }); } } - regex():string { + regex(): string { return this.string.replace(escapeRegex, '\\$1'); } - generate(params:Object, consumed:Object):string { + generate(params:Object, consumed:Object): string { return this.string; } } export class DynamicSegment { - constructor(name:string) { + constructor(name: string) { this.name = name; } - eachChar(callback:(spec:CharSpec) => void) { + eachChar(callback:(spec :CharSpec) => void): void { callback({ invalidChars: '/', repeat: true }); } - regex():string { + regex(): string { return '([^/]+)'; } - generate(params:Object, consumed:Object):string { + generate(params: Object, consumed: Object): string { consumed[this.name] = true; return params[this.name]; } } export class StarSegment { - constructor(name:string) { + constructor(name: string) { this.name = name; } - eachChar(callback:(spec:CharSpec) => void) { + eachChar(callback: (spec:CharSpec) => void): void { callback({ invalidChars: '', repeat: true }); } - regex():string { + regex(): string { return '(.+)'; } - generate(params:Object, consumed:Object):string { + generate(params: Object, consumed: Object): string { consumed[this.name] = true; return params[this.name]; } } export class EpsilonSegment { - eachChar(callback:(spec:CharSpec) => void) {} - regex():string { return ''; } - generate(params:Object, consumed:Object):string { return ''; } + eachChar(callback: (spec:CharSpec) => void): void {} + regex(): string { return ''; } + generate(params: Object, consumed: Object): string { return ''; } } -// A State has a character specification and (`charSpec`) and a list of possible -// subsequent states (`nextStates`). -// -// If a State is an accepting state, it will also have several additional -// properties: -// -// * `regex`: A regular expression that is used to extract parameters from paths -// that reached this accepting state. -// * `handlers`: Information on how to convert the list of captures into calls -// to registered handlers with the specified parameters. -// * `types`: How many static, dynamic, or star segments in this route. Used to -// decide which route to use if multiple registered routes match a path. -// -// Currently, State is implemented naively by looping over `nextStates` and -// comparing a character specification against a character. A more efficient -// implementation would use a hash of keys pointing at one or more next states. - -export class State { - constructor(charSpec:CharSpec) { - this.charSpec = charSpec; - this.nextStates = []; - } - - get(charSpec:CharSpec):State { - for (let child of this.nextStates) { - var isEqual = child.charSpec.validChars === charSpec.validChars && - child.charSpec.invalidChars === charSpec.invalidChars; - - if (isEqual) { - return child; - } - } - } - - put(charSpec:CharSpec):State { - var state = this.get(charSpec); - - // If the character specification already exists in a child of the current - // state, just return that state. - if (state) { - return state; - } - - // Make a new state for the character spec - state = new State(charSpec); - - // Insert the new state as a child of the current state - this.nextStates.push(state); - - // If this character specification repeats, insert the new state as a child - // of itself. Note that this will not trigger an infinite loop because each - // transition during recognition consumes a character. - if (charSpec.repeat) { - state.nextStates.push(state); - } - - // Return the new state - return state; - } - - // Find a list of child states matching the next character - match(ch:string):State[] { - var nextStates = this.nextStates, results = [], - child, charSpec, chars; +interface RouteHandler { + name: string; +} - for (var i = 0, l = nextStates.length; i < l; i++) { - child = nextStates[i]; +interface ConfigurableRoute { + path: string; + handler: RouteHandler; +} - charSpec = child.charSpec; +interface HandlerEntry { + handler: RouteHandler; + names: string[]; +} - if (typeof (chars = charSpec.validChars) !== 'undefined') { - if (chars.indexOf(ch) !== -1) { - results.push(child); - } - } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { - if (chars.indexOf(ch) === -1) { - results.push(child); - } - } - } +interface RecognizedRoute { + handler: RouteHandler; + params: Object; + isDynamic: boolean; +} - return results; - } -}; +interface CharSpec { + invalidChars?: string; + validChars?: string; + repeat?: boolean; +} /** * Class that parses route patterns and matches path strings. @@ -217,7 +217,7 @@ export class RouteRecognizer { * @method add * @param {Object} route The route to add. */ - add(route:ConfigurableRoute|ConfigurableRoute[]):State { + add(route: ConfigurableRoute|ConfigurableRoute[]): State { if (Array.isArray(route)) { for (let r of route) { this.add(r); @@ -276,7 +276,7 @@ export class RouteRecognizer { * @param {String} name The name of the route. * @return {Array} The handlers. */ - handlersFor(name:string):HandlerEntry[] { + handlersFor(name: string): HandlerEntry[] { var route = this.names[name], result = []; @@ -298,7 +298,7 @@ export class RouteRecognizer { * @param {String} name The name of the route. * @return {Boolean} True if the named route is recognized. */ - hasRoute(name:string):boolean { + hasRoute(name: string): boolean { return !!this.names[name]; } @@ -311,7 +311,7 @@ export class RouteRecognizer { * Properties not required by the pattern will be appended to the query string. * @return {String} The generated absolute path and query string. */ - generate(name:string, params:Object):string { + generate(name: string, params: Object): string { params = Object.assign({}, params); var route = this.names[name], @@ -360,7 +360,7 @@ export class RouteRecognizer { * @param {Object} params Object containing the keys and values to be used. * @return {String} The generated query string, including leading '?'. */ - generateQueryString(params:Object):string { + generateQueryString(params: Object): string { var pairs = [], keys = [], encode = encodeURIComponent, encodeKey = k => encode(k).replace('%24', '$'); @@ -402,7 +402,7 @@ export class RouteRecognizer { * @param {String} The query string to parse. * @return {Object} Object with keys and values mapped from the query string. */ - parseQueryString(queryString:string):Object { + parseQueryString(queryString: string): Object { var queryParams = {}; if (!queryString || typeof queryString !== 'string') { return queryParams; @@ -453,7 +453,7 @@ export class RouteRecognizer { * `isDynanic` values for the matched route(s), or undefined if no match * was found. */ - recognize(path:string):RecognizedRoute[] { + recognize(path: string): RecognizedRoute[] { var states = [ this.rootState ], pathLen, i, l, queryStart, queryParams = {}, isSlashDropped = false; @@ -506,7 +506,7 @@ export class RouteRecognizer { } class RecognizeResults { - constructor(queryParams:Object) { + constructor(queryParams: Object) { this.splice = Array.prototype.splice; this.slice = Array.prototype.slice; this.push = Array.prototype.push; diff --git a/dist/commonjs/aurelia-route-recognizer.d.ts b/dist/commonjs/aurelia-route-recognizer.d.ts index b6a706b..ce4bf91 100644 --- a/dist/commonjs/aurelia-route-recognizer.d.ts +++ b/dist/commonjs/aurelia-route-recognizer.d.ts @@ -1,5 +1,5 @@ declare module 'aurelia-route-recognizer' { - import core from 'core-js'; + import * as core from 'core-js'; export interface RouteHandler { name: string; } @@ -22,6 +22,31 @@ declare module 'aurelia-route-recognizer' { repeat?: boolean; } + // A State has a character specification and (`charSpec`) and a list of possible + // subsequent states (`nextStates`). + // + // If a State is an accepting state, it will also have several additional + // properties: + // + // * `regex`: A regular expression that is used to extract parameters from paths + // that reached this accepting state. + // * `handlers`: Information on how to convert the list of captures into calls + // to registered handlers with the specified parameters. + // * `types`: How many static, dynamic, or star segments in this route. Used to + // decide which route to use if multiple registered routes match a path. + // + // Currently, State is implemented naively by looping over `nextStates` and + // comparing a character specification against a character. A more efficient + // implementation would use a hash of keys pointing at one or more next states. + export class State { + constructor(charSpec: CharSpec); + get(charSpec: CharSpec): State; + put(charSpec: CharSpec): State; + + // Find a list of child states matching the next character + match(ch: string): State[]; + } + // A Segment represents a segment in the original route description. // Each Segment type provides an `eachChar` and `regex` method. // @@ -40,53 +65,28 @@ declare module 'aurelia-route-recognizer' { // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class DynamicSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class StarSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class EpsilonSegment { - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } - // A State has a character specification and (`charSpec`) and a list of possible - // subsequent states (`nextStates`). - // - // If a State is an accepting state, it will also have several additional - // properties: - // - // * `regex`: A regular expression that is used to extract parameters from paths - // that reached this accepting state. - // * `handlers`: Information on how to convert the list of captures into calls - // to registered handlers with the specified parameters. - // * `types`: How many static, dynamic, or star segments in this route. Used to - // decide which route to use if multiple registered routes match a path. - // - // Currently, State is implemented naively by looping over `nextStates` and - // comparing a character specification against a character. A more efficient - // implementation would use a hash of keys pointing at one or more next states. - export class State { - constructor(charSpec: CharSpec); - get(charSpec: CharSpec): State; - put(charSpec: CharSpec): State; - - // Find a list of child states matching the next character - match(ch: string): State[]; - } - /** * Class that parses route patterns and matches path strings. * diff --git a/dist/commonjs/aurelia-route-recognizer.js b/dist/commonjs/aurelia-route-recognizer.js index 56a2612..a785d34 100644 --- a/dist/commonjs/aurelia-route-recognizer.js +++ b/dist/commonjs/aurelia-route-recognizer.js @@ -2,13 +2,94 @@ exports.__esModule = true; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _coreJs = require('core-js'); -var _coreJs2 = _interopRequireDefault(_coreJs); +var core = _interopRequireWildcard(_coreJs); + +var State = (function () { + function State(charSpec) { + _classCallCheck(this, State); + + this.charSpec = charSpec; + this.nextStates = []; + } + + State.prototype.get = function get(charSpec) { + for (var _iterator = this.nextStates, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var child = _ref; + + var isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; + + if (isEqual) { + return child; + } + } + }; + + State.prototype.put = function put(charSpec) { + var state = this.get(charSpec); + + if (state) { + return state; + } + + state = new State(charSpec); + + this.nextStates.push(state); + + if (charSpec.repeat) { + state.nextStates.push(state); + } + + return state; + }; + + State.prototype.match = function match(ch) { + var nextStates = this.nextStates, + results = [], + child, + charSpec, + chars; + + for (var i = 0, l = nextStates.length; i < l; i++) { + child = nextStates[i]; + + charSpec = child.charSpec; + + if (typeof (chars = charSpec.validChars) !== 'undefined') { + if (chars.indexOf(ch) !== -1) { + results.push(child); + } + } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { + if (chars.indexOf(ch) === -1) { + results.push(child); + } + } + } + + return results; + }; + + return State; +})(); + +exports.State = State; +; var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; @@ -22,19 +103,19 @@ var StaticSegment = (function () { } StaticSegment.prototype.eachChar = function eachChar(callback) { - for (var _iterator = this.string, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; + for (var _iterator2 = this.string, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; } - var ch = _ref; + var ch = _ref2; callback({ validChars: ch }); } @@ -123,87 +204,6 @@ var EpsilonSegment = (function () { exports.EpsilonSegment = EpsilonSegment; -var State = (function () { - function State(charSpec) { - _classCallCheck(this, State); - - this.charSpec = charSpec; - this.nextStates = []; - } - - State.prototype.get = function get(charSpec) { - for (var _iterator2 = this.nextStates, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var child = _ref2; - - var isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; - - if (isEqual) { - return child; - } - } - }; - - State.prototype.put = function put(charSpec) { - var state = this.get(charSpec); - - if (state) { - return state; - } - - state = new State(charSpec); - - this.nextStates.push(state); - - if (charSpec.repeat) { - state.nextStates.push(state); - } - - return state; - }; - - State.prototype.match = function match(ch) { - var nextStates = this.nextStates, - results = [], - child, - charSpec, - chars; - - for (var i = 0, l = nextStates.length; i < l; i++) { - child = nextStates[i]; - - charSpec = child.charSpec; - - if (typeof (chars = charSpec.validChars) !== 'undefined') { - if (chars.indexOf(ch) !== -1) { - results.push(child); - } - } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { - if (chars.indexOf(ch) === -1) { - results.push(child); - } - } - } - - return results; - }; - - return State; -})(); - -exports.State = State; -; - var RouteRecognizer = (function () { function RouteRecognizer() { _classCallCheck(this, RouteRecognizer); diff --git a/dist/es6/aurelia-route-recognizer.d.ts b/dist/es6/aurelia-route-recognizer.d.ts index b6a706b..ce4bf91 100644 --- a/dist/es6/aurelia-route-recognizer.d.ts +++ b/dist/es6/aurelia-route-recognizer.d.ts @@ -1,5 +1,5 @@ declare module 'aurelia-route-recognizer' { - import core from 'core-js'; + import * as core from 'core-js'; export interface RouteHandler { name: string; } @@ -22,6 +22,31 @@ declare module 'aurelia-route-recognizer' { repeat?: boolean; } + // A State has a character specification and (`charSpec`) and a list of possible + // subsequent states (`nextStates`). + // + // If a State is an accepting state, it will also have several additional + // properties: + // + // * `regex`: A regular expression that is used to extract parameters from paths + // that reached this accepting state. + // * `handlers`: Information on how to convert the list of captures into calls + // to registered handlers with the specified parameters. + // * `types`: How many static, dynamic, or star segments in this route. Used to + // decide which route to use if multiple registered routes match a path. + // + // Currently, State is implemented naively by looping over `nextStates` and + // comparing a character specification against a character. A more efficient + // implementation would use a hash of keys pointing at one or more next states. + export class State { + constructor(charSpec: CharSpec); + get(charSpec: CharSpec): State; + put(charSpec: CharSpec): State; + + // Find a list of child states matching the next character + match(ch: string): State[]; + } + // A Segment represents a segment in the original route description. // Each Segment type provides an `eachChar` and `regex` method. // @@ -40,53 +65,28 @@ declare module 'aurelia-route-recognizer' { // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class DynamicSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class StarSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class EpsilonSegment { - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } - // A State has a character specification and (`charSpec`) and a list of possible - // subsequent states (`nextStates`). - // - // If a State is an accepting state, it will also have several additional - // properties: - // - // * `regex`: A regular expression that is used to extract parameters from paths - // that reached this accepting state. - // * `handlers`: Information on how to convert the list of captures into calls - // to registered handlers with the specified parameters. - // * `types`: How many static, dynamic, or star segments in this route. Used to - // decide which route to use if multiple registered routes match a path. - // - // Currently, State is implemented naively by looping over `nextStates` and - // comparing a character specification against a character. A more efficient - // implementation would use a hash of keys pointing at one or more next states. - export class State { - constructor(charSpec: CharSpec); - get(charSpec: CharSpec): State; - put(charSpec: CharSpec): State; - - // Find a list of child states matching the next character - match(ch: string): State[]; - } - /** * Class that parses route patterns and matches path strings. * diff --git a/dist/es6/aurelia-route-recognizer.js b/dist/es6/aurelia-route-recognizer.js index 1002d55..b8937e2 100644 --- a/dist/es6/aurelia-route-recognizer.js +++ b/dist/es6/aurelia-route-recognizer.js @@ -1,30 +1,89 @@ -import core from 'core-js'; +import * as core from 'core-js'; -interface RouteHandler { - name:string; -} +// A State has a character specification and (`charSpec`) and a list of possible +// subsequent states (`nextStates`). +// +// If a State is an accepting state, it will also have several additional +// properties: +// +// * `regex`: A regular expression that is used to extract parameters from paths +// that reached this accepting state. +// * `handlers`: Information on how to convert the list of captures into calls +// to registered handlers with the specified parameters. +// * `types`: How many static, dynamic, or star segments in this route. Used to +// decide which route to use if multiple registered routes match a path. +// +// Currently, State is implemented naively by looping over `nextStates` and +// comparing a character specification against a character. A more efficient +// implementation would use a hash of keys pointing at one or more next states. -interface ConfigurableRoute { - path:string; - handler:RouteHandler; -} +export class State { + constructor(charSpec: CharSpec) { + this.charSpec = charSpec; + this.nextStates = []; + } -interface HandlerEntry { - handler:RouteHandler; - names:string[]; -} + get(charSpec: CharSpec): State { + for (let child of this.nextStates) { + var isEqual = child.charSpec.validChars === charSpec.validChars && + child.charSpec.invalidChars === charSpec.invalidChars; -interface RecognizedRoute { - handler:RouteHandler; - params:Object; - isDynamic:boolean; -} + if (isEqual) { + return child; + } + } + } -interface CharSpec { - invalidChars?:string; - validChars?:string; - repeat?:boolean; -} + put(charSpec: CharSpec): State { + var state = this.get(charSpec); + + // If the character specification already exists in a child of the current + // state, just return that state. + if (state) { + return state; + } + + // Make a new state for the character spec + state = new State(charSpec); + + // Insert the new state as a child of the current state + this.nextStates.push(state); + + // If this character specification repeats, insert the new state as a child + // of itself. Note that this will not trigger an infinite loop because each + // transition during recognition consumes a character. + if (charSpec.repeat) { + state.nextStates.push(state); + } + + // Return the new state + return state; + } + + // Find a list of child states matching the next character + match(ch: string): State[] { + var nextStates = this.nextStates, results = [], + child, charSpec, chars; + + for (var i = 0, l = nextStates.length; i < l; i++) { + child = nextStates[i]; + + charSpec = child.charSpec; + + if (typeof (chars = charSpec.validChars) !== 'undefined') { + if (chars.indexOf(ch) !== -1) { + results.push(child); + } + } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { + if (chars.indexOf(ch) === -1) { + results.push(child); + } + } + } + + return results; + } +}; const specials = [ '/', '.', '*', '+', '?', '|', @@ -55,149 +114,90 @@ export class StaticSegment { this.string = string; } - eachChar(callback:(spec:CharSpec) => void) { + eachChar(callback: (spec:CharSpec) => void): void { for (let ch of this.string) { callback({ validChars: ch }); } } - regex():string { + regex(): string { return this.string.replace(escapeRegex, '\\$1'); } - generate(params:Object, consumed:Object):string { + generate(params:Object, consumed:Object): string { return this.string; } } export class DynamicSegment { - constructor(name:string) { + constructor(name: string) { this.name = name; } - eachChar(callback:(spec:CharSpec) => void) { + eachChar(callback:(spec :CharSpec) => void): void { callback({ invalidChars: '/', repeat: true }); } - regex():string { + regex(): string { return '([^/]+)'; } - generate(params:Object, consumed:Object):string { + generate(params: Object, consumed: Object): string { consumed[this.name] = true; return params[this.name]; } } export class StarSegment { - constructor(name:string) { + constructor(name: string) { this.name = name; } - eachChar(callback:(spec:CharSpec) => void) { + eachChar(callback: (spec:CharSpec) => void): void { callback({ invalidChars: '', repeat: true }); } - regex():string { + regex(): string { return '(.+)'; } - generate(params:Object, consumed:Object):string { + generate(params: Object, consumed: Object): string { consumed[this.name] = true; return params[this.name]; } } export class EpsilonSegment { - eachChar(callback:(spec:CharSpec) => void) {} - regex():string { return ''; } - generate(params:Object, consumed:Object):string { return ''; } + eachChar(callback: (spec:CharSpec) => void): void {} + regex(): string { return ''; } + generate(params: Object, consumed: Object): string { return ''; } } -// A State has a character specification and (`charSpec`) and a list of possible -// subsequent states (`nextStates`). -// -// If a State is an accepting state, it will also have several additional -// properties: -// -// * `regex`: A regular expression that is used to extract parameters from paths -// that reached this accepting state. -// * `handlers`: Information on how to convert the list of captures into calls -// to registered handlers with the specified parameters. -// * `types`: How many static, dynamic, or star segments in this route. Used to -// decide which route to use if multiple registered routes match a path. -// -// Currently, State is implemented naively by looping over `nextStates` and -// comparing a character specification against a character. A more efficient -// implementation would use a hash of keys pointing at one or more next states. - -export class State { - constructor(charSpec:CharSpec) { - this.charSpec = charSpec; - this.nextStates = []; - } - - get(charSpec:CharSpec):State { - for (let child of this.nextStates) { - var isEqual = child.charSpec.validChars === charSpec.validChars && - child.charSpec.invalidChars === charSpec.invalidChars; - - if (isEqual) { - return child; - } - } - } - - put(charSpec:CharSpec):State { - var state = this.get(charSpec); - - // If the character specification already exists in a child of the current - // state, just return that state. - if (state) { - return state; - } - - // Make a new state for the character spec - state = new State(charSpec); - - // Insert the new state as a child of the current state - this.nextStates.push(state); - - // If this character specification repeats, insert the new state as a child - // of itself. Note that this will not trigger an infinite loop because each - // transition during recognition consumes a character. - if (charSpec.repeat) { - state.nextStates.push(state); - } - - // Return the new state - return state; - } - - // Find a list of child states matching the next character - match(ch:string):State[] { - var nextStates = this.nextStates, results = [], - child, charSpec, chars; +interface RouteHandler { + name: string; +} - for (var i = 0, l = nextStates.length; i < l; i++) { - child = nextStates[i]; +interface ConfigurableRoute { + path: string; + handler: RouteHandler; +} - charSpec = child.charSpec; +interface HandlerEntry { + handler: RouteHandler; + names: string[]; +} - if (typeof (chars = charSpec.validChars) !== 'undefined') { - if (chars.indexOf(ch) !== -1) { - results.push(child); - } - } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { - if (chars.indexOf(ch) === -1) { - results.push(child); - } - } - } +interface RecognizedRoute { + handler: RouteHandler; + params: Object; + isDynamic: boolean; +} - return results; - } -}; +interface CharSpec { + invalidChars?: string; + validChars?: string; + repeat?: boolean; +} /** * Class that parses route patterns and matches path strings. @@ -217,7 +217,7 @@ export class RouteRecognizer { * @method add * @param {Object} route The route to add. */ - add(route:ConfigurableRoute|ConfigurableRoute[]):State { + add(route: ConfigurableRoute|ConfigurableRoute[]): State { if (Array.isArray(route)) { for (let r of route) { this.add(r); @@ -276,7 +276,7 @@ export class RouteRecognizer { * @param {String} name The name of the route. * @return {Array} The handlers. */ - handlersFor(name:string):HandlerEntry[] { + handlersFor(name: string): HandlerEntry[] { var route = this.names[name], result = []; @@ -298,7 +298,7 @@ export class RouteRecognizer { * @param {String} name The name of the route. * @return {Boolean} True if the named route is recognized. */ - hasRoute(name:string):boolean { + hasRoute(name: string): boolean { return !!this.names[name]; } @@ -311,7 +311,7 @@ export class RouteRecognizer { * Properties not required by the pattern will be appended to the query string. * @return {String} The generated absolute path and query string. */ - generate(name:string, params:Object):string { + generate(name: string, params: Object): string { params = Object.assign({}, params); var route = this.names[name], @@ -360,7 +360,7 @@ export class RouteRecognizer { * @param {Object} params Object containing the keys and values to be used. * @return {String} The generated query string, including leading '?'. */ - generateQueryString(params:Object):string { + generateQueryString(params: Object): string { var pairs = [], keys = [], encode = encodeURIComponent, encodeKey = k => encode(k).replace('%24', '$'); @@ -402,7 +402,7 @@ export class RouteRecognizer { * @param {String} The query string to parse. * @return {Object} Object with keys and values mapped from the query string. */ - parseQueryString(queryString:string):Object { + parseQueryString(queryString: string): Object { var queryParams = {}; if (!queryString || typeof queryString !== 'string') { return queryParams; @@ -453,7 +453,7 @@ export class RouteRecognizer { * `isDynanic` values for the matched route(s), or undefined if no match * was found. */ - recognize(path:string):RecognizedRoute[] { + recognize(path: string): RecognizedRoute[] { var states = [ this.rootState ], pathLen, i, l, queryStart, queryParams = {}, isSlashDropped = false; @@ -506,7 +506,7 @@ export class RouteRecognizer { } class RecognizeResults { - constructor(queryParams:Object) { + constructor(queryParams: Object) { this.splice = Array.prototype.splice; this.slice = Array.prototype.slice; this.push = Array.prototype.push; diff --git a/dist/system/aurelia-route-recognizer.d.ts b/dist/system/aurelia-route-recognizer.d.ts index b6a706b..ce4bf91 100644 --- a/dist/system/aurelia-route-recognizer.d.ts +++ b/dist/system/aurelia-route-recognizer.d.ts @@ -1,5 +1,5 @@ declare module 'aurelia-route-recognizer' { - import core from 'core-js'; + import * as core from 'core-js'; export interface RouteHandler { name: string; } @@ -22,6 +22,31 @@ declare module 'aurelia-route-recognizer' { repeat?: boolean; } + // A State has a character specification and (`charSpec`) and a list of possible + // subsequent states (`nextStates`). + // + // If a State is an accepting state, it will also have several additional + // properties: + // + // * `regex`: A regular expression that is used to extract parameters from paths + // that reached this accepting state. + // * `handlers`: Information on how to convert the list of captures into calls + // to registered handlers with the specified parameters. + // * `types`: How many static, dynamic, or star segments in this route. Used to + // decide which route to use if multiple registered routes match a path. + // + // Currently, State is implemented naively by looping over `nextStates` and + // comparing a character specification against a character. A more efficient + // implementation would use a hash of keys pointing at one or more next states. + export class State { + constructor(charSpec: CharSpec); + get(charSpec: CharSpec): State; + put(charSpec: CharSpec): State; + + // Find a list of child states matching the next character + match(ch: string): State[]; + } + // A Segment represents a segment in the original route description. // Each Segment type provides an `eachChar` and `regex` method. // @@ -40,53 +65,28 @@ declare module 'aurelia-route-recognizer' { // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class DynamicSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class StarSegment { constructor(name: string); - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } export class EpsilonSegment { - eachChar(callback: (spec: CharSpec) => void): any; + eachChar(callback: ((spec: CharSpec) => void)): void; regex(): string; generate(params: Object, consumed: Object): string; } - // A State has a character specification and (`charSpec`) and a list of possible - // subsequent states (`nextStates`). - // - // If a State is an accepting state, it will also have several additional - // properties: - // - // * `regex`: A regular expression that is used to extract parameters from paths - // that reached this accepting state. - // * `handlers`: Information on how to convert the list of captures into calls - // to registered handlers with the specified parameters. - // * `types`: How many static, dynamic, or star segments in this route. Used to - // decide which route to use if multiple registered routes match a path. - // - // Currently, State is implemented naively by looping over `nextStates` and - // comparing a character specification against a character. A more efficient - // implementation would use a hash of keys pointing at one or more next states. - export class State { - constructor(charSpec: CharSpec); - get(charSpec: CharSpec): State; - put(charSpec: CharSpec): State; - - // Find a list of child states matching the next character - match(ch: string): State[]; - } - /** * Class that parses route patterns and matches path strings. * diff --git a/dist/system/aurelia-route-recognizer.js b/dist/system/aurelia-route-recognizer.js index f4c939a..3f29165 100644 --- a/dist/system/aurelia-route-recognizer.js +++ b/dist/system/aurelia-route-recognizer.js @@ -1,7 +1,7 @@ System.register(['core-js'], function (_export) { 'use strict'; - var core, specials, escapeRegex, StaticSegment, DynamicSegment, StarSegment, EpsilonSegment, State, RouteRecognizer, RecognizeResults; + var core, State, specials, escapeRegex, StaticSegment, DynamicSegment, StarSegment, EpsilonSegment, RouteRecognizer, RecognizeResults; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } @@ -117,9 +117,91 @@ System.register(['core-js'], function (_export) { } return { setters: [function (_coreJs) { - core = _coreJs['default']; + core = _coreJs; }], execute: function () { + State = (function () { + function State(charSpec) { + _classCallCheck(this, State); + + this.charSpec = charSpec; + this.nextStates = []; + } + + State.prototype.get = function get(charSpec) { + for (var _iterator = this.nextStates, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var child = _ref; + + var isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; + + if (isEqual) { + return child; + } + } + }; + + State.prototype.put = function put(charSpec) { + var state = this.get(charSpec); + + if (state) { + return state; + } + + state = new State(charSpec); + + this.nextStates.push(state); + + if (charSpec.repeat) { + state.nextStates.push(state); + } + + return state; + }; + + State.prototype.match = function match(ch) { + var nextStates = this.nextStates, + results = [], + child, + charSpec, + chars; + + for (var i = 0, l = nextStates.length; i < l; i++) { + child = nextStates[i]; + + charSpec = child.charSpec; + + if (typeof (chars = charSpec.validChars) !== 'undefined') { + if (chars.indexOf(ch) !== -1) { + results.push(child); + } + } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { + if (chars.indexOf(ch) === -1) { + results.push(child); + } + } + } + + return results; + }; + + return State; + })(); + + _export('State', State); + + ; + specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; escapeRegex = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); @@ -131,19 +213,19 @@ System.register(['core-js'], function (_export) { } StaticSegment.prototype.eachChar = function eachChar(callback) { - for (var _iterator = this.string, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; + for (var _iterator2 = this.string, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; } - var ch = _ref; + var ch = _ref2; callback({ validChars: ch }); } @@ -232,88 +314,6 @@ System.register(['core-js'], function (_export) { _export('EpsilonSegment', EpsilonSegment); - State = (function () { - function State(charSpec) { - _classCallCheck(this, State); - - this.charSpec = charSpec; - this.nextStates = []; - } - - State.prototype.get = function get(charSpec) { - for (var _iterator2 = this.nextStates, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var child = _ref2; - - var isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; - - if (isEqual) { - return child; - } - } - }; - - State.prototype.put = function put(charSpec) { - var state = this.get(charSpec); - - if (state) { - return state; - } - - state = new State(charSpec); - - this.nextStates.push(state); - - if (charSpec.repeat) { - state.nextStates.push(state); - } - - return state; - }; - - State.prototype.match = function match(ch) { - var nextStates = this.nextStates, - results = [], - child, - charSpec, - chars; - - for (var i = 0, l = nextStates.length; i < l; i++) { - child = nextStates[i]; - - charSpec = child.charSpec; - - if (typeof (chars = charSpec.validChars) !== 'undefined') { - if (chars.indexOf(ch) !== -1) { - results.push(child); - } - } else if (typeof (chars = charSpec.invalidChars) !== 'undefined') { - if (chars.indexOf(ch) === -1) { - results.push(child); - } - } - } - - return results; - }; - - return State; - })(); - - _export('State', State); - - ; - RouteRecognizer = (function () { function RouteRecognizer() { _classCallCheck(this, RouteRecognizer); diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 6402281..069af5f 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,16 @@ +### 0.6.2 (2015-08-14) + + +#### Bug Fixes + +* **route-recognizer:** Use correct import for core-js We were previously using `import core from core-j ([d37d1687](http://github.com/aurelia/route-recognizer/commit/d37d1687f7e4109e4175505ceaae8bccc356257c)) + + +#### Features + +* **all:** more type info ([e11312e3](http://github.com/aurelia/route-recognizer/commit/e11312e3ed7325a4ef4b9dd56fc9353d3adb610c)) + + ### 0.6.1 (2015-07-29) * improve output file name diff --git a/package.json b/package.json index 1f5341a..0fb12eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-route-recognizer", - "version": "0.6.1", + "version": "0.6.2", "description": "A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.", "keywords": [ "aurelia",