From 5c94f7ef16a911311f3349cf122383732f6b2d48 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 22 Mar 2016 16:13:47 -0400 Subject: [PATCH] chore(all): prepare release 1.0.0-beta.1.2.0 --- bower.json | 2 +- dist/amd/aurelia-route-recognizer.d.ts | 80 +++--- dist/amd/aurelia-route-recognizer.js | 63 +++-- dist/aurelia-route-recognizer.d.ts | 80 +++--- dist/commonjs/aurelia-route-recognizer.d.ts | 80 +++--- dist/commonjs/aurelia-route-recognizer.js | 59 ++--- .../aurelia-route-recognizer.d.ts | 80 +++--- .../aurelia-route-recognizer.js | 227 ++++-------------- dist/system/aurelia-route-recognizer.d.ts | 80 +++--- dist/system/aurelia-route-recognizer.js | 44 ++-- doc/CHANGELOG.md | 4 + doc/api.json | 54 ----- package.json | 2 +- 13 files changed, 348 insertions(+), 507 deletions(-) rename dist/{es6 => es2015}/aurelia-route-recognizer.d.ts (61%) rename dist/{es6 => es2015}/aurelia-route-recognizer.js (57%) diff --git a/bower.json b/bower.json index ccb8453..ea1b4dd 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-route-recognizer", - "version": "1.0.0-beta.1.1.3", + "version": "1.0.0-beta.1.2.0", "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 138404b..05fa378 100644 --- a/dist/amd/aurelia-route-recognizer.d.ts +++ b/dist/amd/aurelia-route-recognizer.d.ts @@ -1,5 +1,8 @@ declare module 'aurelia-route-recognizer' { - import { buildQueryString, parseQueryString } from 'aurelia-path'; + import { + buildQueryString, + parseQueryString + } from 'aurelia-path'; export interface RouteHandler { name: string; } @@ -22,47 +25,47 @@ 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. + // 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 + // 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. - // - // The `eachChar` method invokes the callback with one or more character - // specifications. A character specification consumes one or more input - // characters. - // - // The `regex` method returns a regex fragment for the segment. If the - // segment is a dynamic or star segment, the regex fragment also includes - // a capture. - // - // A character specification contains: - // - // * `validChars`: a String with a list of all valid characters, or - // * `invalidChars`: a String with a list of all invalid characters - // * `repeat`: true if the character specification can repeat + // A Segment represents a segment in the original route description. + // Each Segment type provides an `eachChar` and `regex` method. + // + // The `eachChar` method invokes the callback with one or more character + // specifications. A character specification consumes one or more input + // characters. + // + // The `regex` method returns a regex fragment for the segment. If the + // segment is a dynamic or star segment, the regex fragment also includes + // a capture. + // + // A character specification contains: + // + // * `validChars`: a String with a list of all valid characters, or + // * `invalidChars`: a String with a list of all invalid characters + // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); eachChar(callback: ((spec: CharSpec) => void)): void; @@ -87,6 +90,12 @@ declare module 'aurelia-route-recognizer' { generate(): string; } + /** + * Class that parses route patterns and matches path strings. + * + * @class RouteRecognizer + * @constructor + */ /** * Class that parses route patterns and matches path strings. * @@ -139,7 +148,4 @@ declare module 'aurelia-route-recognizer' { */ recognize(path: string): RecognizedRoute[]; } - class RecognizeResults { - constructor(queryParams: Object); - } } \ No newline at end of file diff --git a/dist/amd/aurelia-route-recognizer.js b/dist/amd/aurelia-route-recognizer.js index bc22f0c..53d619c 100644 --- a/dist/amd/aurelia-route-recognizer.js +++ b/dist/amd/aurelia-route-recognizer.js @@ -1,11 +1,18 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { 'use strict'; - exports.__esModule = true; - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.RouteRecognizer = exports.EpsilonSegment = exports.StarSegment = exports.DynamicSegment = exports.StaticSegment = exports.State = undefined; + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } - var State = (function () { + var State = exports.State = function () { function State(charSpec) { _classCallCheck(this, State); @@ -77,15 +84,13 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { }; return State; - })(); - - exports.State = State; + }(); var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; var escapeRegex = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); - var StaticSegment = (function () { + var StaticSegment = exports.StaticSegment = function () { function StaticSegment(string) { _classCallCheck(this, StaticSegment); @@ -109,11 +114,9 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { }; return StaticSegment; - })(); - - exports.StaticSegment = StaticSegment; + }(); - var DynamicSegment = (function () { + var DynamicSegment = exports.DynamicSegment = function () { function DynamicSegment(name) { _classCallCheck(this, DynamicSegment); @@ -134,11 +137,9 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { }; return DynamicSegment; - })(); + }(); - exports.DynamicSegment = DynamicSegment; - - var StarSegment = (function () { + var StarSegment = exports.StarSegment = function () { function StarSegment(name) { _classCallCheck(this, StarSegment); @@ -159,11 +160,9 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { }; return StarSegment; - })(); - - exports.StarSegment = StarSegment; + }(); - var EpsilonSegment = (function () { + var EpsilonSegment = exports.EpsilonSegment = function () { function EpsilonSegment() { _classCallCheck(this, EpsilonSegment); } @@ -179,11 +178,9 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { }; return EpsilonSegment; - })(); + }(); - exports.EpsilonSegment = EpsilonSegment; - - var RouteRecognizer = (function () { + var RouteRecognizer = exports.RouteRecognizer = function () { function RouteRecognizer() { _classCallCheck(this, RouteRecognizer); @@ -233,8 +230,8 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { if (routeName) { var routeNames = Array.isArray(routeName) ? routeName : [routeName]; - for (var i = 0; i < routeNames.length; i++) { - this.names[routeNames[i]] = { + for (var _i2 = 0; _i2 < routeNames.length; _i2++) { + this.names[routeNames[_i2]] = { segments: segments, handlers: handlers }; @@ -297,7 +294,7 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { delete routeParams[param]; } - var queryString = _aureliaPath.buildQueryString(routeParams); + var queryString = (0, _aureliaPath.buildQueryString)(routeParams); output += queryString ? '?' + queryString : ''; return output; @@ -313,7 +310,7 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { if (queryStart !== -1) { var queryString = normalizedPath.substr(queryStart + 1, normalizedPath.length); normalizedPath = normalizedPath.substr(0, queryStart); - queryParams = _aureliaPath.parseQueryString(queryString); + queryParams = (0, _aureliaPath.parseQueryString)(queryString); } normalizedPath = decodeURI(normalizedPath); @@ -336,9 +333,9 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { } var solutions = []; - for (var i = 0, l = states.length; i < l; i++) { - if (states[i].handlers) { - solutions.push(states[i]); + for (var _i3 = 0, _l = states.length; _i3 < _l; _i3++) { + if (states[_i3].handlers) { + solutions.push(states[_i3]); } } @@ -355,9 +352,7 @@ define(['exports', 'aurelia-path'], function (exports, _aureliaPath) { }; return RouteRecognizer; - })(); - - exports.RouteRecognizer = RouteRecognizer; + }(); var RecognizeResults = function RecognizeResults(queryParams) { _classCallCheck(this, RecognizeResults); diff --git a/dist/aurelia-route-recognizer.d.ts b/dist/aurelia-route-recognizer.d.ts index 138404b..05fa378 100644 --- a/dist/aurelia-route-recognizer.d.ts +++ b/dist/aurelia-route-recognizer.d.ts @@ -1,5 +1,8 @@ declare module 'aurelia-route-recognizer' { - import { buildQueryString, parseQueryString } from 'aurelia-path'; + import { + buildQueryString, + parseQueryString + } from 'aurelia-path'; export interface RouteHandler { name: string; } @@ -22,47 +25,47 @@ 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. + // 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 + // 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. - // - // The `eachChar` method invokes the callback with one or more character - // specifications. A character specification consumes one or more input - // characters. - // - // The `regex` method returns a regex fragment for the segment. If the - // segment is a dynamic or star segment, the regex fragment also includes - // a capture. - // - // A character specification contains: - // - // * `validChars`: a String with a list of all valid characters, or - // * `invalidChars`: a String with a list of all invalid characters - // * `repeat`: true if the character specification can repeat + // A Segment represents a segment in the original route description. + // Each Segment type provides an `eachChar` and `regex` method. + // + // The `eachChar` method invokes the callback with one or more character + // specifications. A character specification consumes one or more input + // characters. + // + // The `regex` method returns a regex fragment for the segment. If the + // segment is a dynamic or star segment, the regex fragment also includes + // a capture. + // + // A character specification contains: + // + // * `validChars`: a String with a list of all valid characters, or + // * `invalidChars`: a String with a list of all invalid characters + // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); eachChar(callback: ((spec: CharSpec) => void)): void; @@ -87,6 +90,12 @@ declare module 'aurelia-route-recognizer' { generate(): string; } + /** + * Class that parses route patterns and matches path strings. + * + * @class RouteRecognizer + * @constructor + */ /** * Class that parses route patterns and matches path strings. * @@ -139,7 +148,4 @@ declare module 'aurelia-route-recognizer' { */ recognize(path: string): RecognizedRoute[]; } - class RecognizeResults { - constructor(queryParams: Object); - } } \ No newline at end of file diff --git a/dist/commonjs/aurelia-route-recognizer.d.ts b/dist/commonjs/aurelia-route-recognizer.d.ts index 138404b..05fa378 100644 --- a/dist/commonjs/aurelia-route-recognizer.d.ts +++ b/dist/commonjs/aurelia-route-recognizer.d.ts @@ -1,5 +1,8 @@ declare module 'aurelia-route-recognizer' { - import { buildQueryString, parseQueryString } from 'aurelia-path'; + import { + buildQueryString, + parseQueryString + } from 'aurelia-path'; export interface RouteHandler { name: string; } @@ -22,47 +25,47 @@ 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. + // 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 + // 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. - // - // The `eachChar` method invokes the callback with one or more character - // specifications. A character specification consumes one or more input - // characters. - // - // The `regex` method returns a regex fragment for the segment. If the - // segment is a dynamic or star segment, the regex fragment also includes - // a capture. - // - // A character specification contains: - // - // * `validChars`: a String with a list of all valid characters, or - // * `invalidChars`: a String with a list of all invalid characters - // * `repeat`: true if the character specification can repeat + // A Segment represents a segment in the original route description. + // Each Segment type provides an `eachChar` and `regex` method. + // + // The `eachChar` method invokes the callback with one or more character + // specifications. A character specification consumes one or more input + // characters. + // + // The `regex` method returns a regex fragment for the segment. If the + // segment is a dynamic or star segment, the regex fragment also includes + // a capture. + // + // A character specification contains: + // + // * `validChars`: a String with a list of all valid characters, or + // * `invalidChars`: a String with a list of all invalid characters + // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); eachChar(callback: ((spec: CharSpec) => void)): void; @@ -87,6 +90,12 @@ declare module 'aurelia-route-recognizer' { generate(): string; } + /** + * Class that parses route patterns and matches path strings. + * + * @class RouteRecognizer + * @constructor + */ /** * Class that parses route patterns and matches path strings. * @@ -139,7 +148,4 @@ declare module 'aurelia-route-recognizer' { */ recognize(path: string): RecognizedRoute[]; } - class RecognizeResults { - constructor(queryParams: Object); - } } \ No newline at end of file diff --git a/dist/commonjs/aurelia-route-recognizer.js b/dist/commonjs/aurelia-route-recognizer.js index f6dee74..03eea33 100644 --- a/dist/commonjs/aurelia-route-recognizer.js +++ b/dist/commonjs/aurelia-route-recognizer.js @@ -1,12 +1,15 @@ 'use strict'; -exports.__esModule = true; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.RouteRecognizer = exports.EpsilonSegment = exports.StarSegment = exports.DynamicSegment = exports.StaticSegment = exports.State = undefined; var _aureliaPath = require('aurelia-path'); -var State = (function () { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var State = exports.State = function () { function State(charSpec) { _classCallCheck(this, State); @@ -78,15 +81,13 @@ var State = (function () { }; return State; -})(); - -exports.State = State; +}(); var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; var escapeRegex = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); -var StaticSegment = (function () { +var StaticSegment = exports.StaticSegment = function () { function StaticSegment(string) { _classCallCheck(this, StaticSegment); @@ -110,11 +111,9 @@ var StaticSegment = (function () { }; return StaticSegment; -})(); - -exports.StaticSegment = StaticSegment; +}(); -var DynamicSegment = (function () { +var DynamicSegment = exports.DynamicSegment = function () { function DynamicSegment(name) { _classCallCheck(this, DynamicSegment); @@ -135,11 +134,9 @@ var DynamicSegment = (function () { }; return DynamicSegment; -})(); +}(); -exports.DynamicSegment = DynamicSegment; - -var StarSegment = (function () { +var StarSegment = exports.StarSegment = function () { function StarSegment(name) { _classCallCheck(this, StarSegment); @@ -160,11 +157,9 @@ var StarSegment = (function () { }; return StarSegment; -})(); - -exports.StarSegment = StarSegment; +}(); -var EpsilonSegment = (function () { +var EpsilonSegment = exports.EpsilonSegment = function () { function EpsilonSegment() { _classCallCheck(this, EpsilonSegment); } @@ -180,11 +175,9 @@ var EpsilonSegment = (function () { }; return EpsilonSegment; -})(); +}(); -exports.EpsilonSegment = EpsilonSegment; - -var RouteRecognizer = (function () { +var RouteRecognizer = exports.RouteRecognizer = function () { function RouteRecognizer() { _classCallCheck(this, RouteRecognizer); @@ -234,8 +227,8 @@ var RouteRecognizer = (function () { if (routeName) { var routeNames = Array.isArray(routeName) ? routeName : [routeName]; - for (var i = 0; i < routeNames.length; i++) { - this.names[routeNames[i]] = { + for (var _i2 = 0; _i2 < routeNames.length; _i2++) { + this.names[routeNames[_i2]] = { segments: segments, handlers: handlers }; @@ -298,7 +291,7 @@ var RouteRecognizer = (function () { delete routeParams[param]; } - var queryString = _aureliaPath.buildQueryString(routeParams); + var queryString = (0, _aureliaPath.buildQueryString)(routeParams); output += queryString ? '?' + queryString : ''; return output; @@ -314,7 +307,7 @@ var RouteRecognizer = (function () { if (queryStart !== -1) { var queryString = normalizedPath.substr(queryStart + 1, normalizedPath.length); normalizedPath = normalizedPath.substr(0, queryStart); - queryParams = _aureliaPath.parseQueryString(queryString); + queryParams = (0, _aureliaPath.parseQueryString)(queryString); } normalizedPath = decodeURI(normalizedPath); @@ -337,9 +330,9 @@ var RouteRecognizer = (function () { } var solutions = []; - for (var i = 0, l = states.length; i < l; i++) { - if (states[i].handlers) { - solutions.push(states[i]); + for (var _i3 = 0, _l = states.length; _i3 < _l; _i3++) { + if (states[_i3].handlers) { + solutions.push(states[_i3]); } } @@ -356,9 +349,7 @@ var RouteRecognizer = (function () { }; return RouteRecognizer; -})(); - -exports.RouteRecognizer = RouteRecognizer; +}(); var RecognizeResults = function RecognizeResults(queryParams) { _classCallCheck(this, RecognizeResults); diff --git a/dist/es6/aurelia-route-recognizer.d.ts b/dist/es2015/aurelia-route-recognizer.d.ts similarity index 61% rename from dist/es6/aurelia-route-recognizer.d.ts rename to dist/es2015/aurelia-route-recognizer.d.ts index 138404b..05fa378 100644 --- a/dist/es6/aurelia-route-recognizer.d.ts +++ b/dist/es2015/aurelia-route-recognizer.d.ts @@ -1,5 +1,8 @@ declare module 'aurelia-route-recognizer' { - import { buildQueryString, parseQueryString } from 'aurelia-path'; + import { + buildQueryString, + parseQueryString + } from 'aurelia-path'; export interface RouteHandler { name: string; } @@ -22,47 +25,47 @@ 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. + // 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 + // 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. - // - // The `eachChar` method invokes the callback with one or more character - // specifications. A character specification consumes one or more input - // characters. - // - // The `regex` method returns a regex fragment for the segment. If the - // segment is a dynamic or star segment, the regex fragment also includes - // a capture. - // - // A character specification contains: - // - // * `validChars`: a String with a list of all valid characters, or - // * `invalidChars`: a String with a list of all invalid characters - // * `repeat`: true if the character specification can repeat + // A Segment represents a segment in the original route description. + // Each Segment type provides an `eachChar` and `regex` method. + // + // The `eachChar` method invokes the callback with one or more character + // specifications. A character specification consumes one or more input + // characters. + // + // The `regex` method returns a regex fragment for the segment. If the + // segment is a dynamic or star segment, the regex fragment also includes + // a capture. + // + // A character specification contains: + // + // * `validChars`: a String with a list of all valid characters, or + // * `invalidChars`: a String with a list of all invalid characters + // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); eachChar(callback: ((spec: CharSpec) => void)): void; @@ -87,6 +90,12 @@ declare module 'aurelia-route-recognizer' { generate(): string; } + /** + * Class that parses route patterns and matches path strings. + * + * @class RouteRecognizer + * @constructor + */ /** * Class that parses route patterns and matches path strings. * @@ -139,7 +148,4 @@ declare module 'aurelia-route-recognizer' { */ recognize(path: string): RecognizedRoute[]; } - class RecognizeResults { - constructor(queryParams: Object); - } } \ No newline at end of file diff --git a/dist/es6/aurelia-route-recognizer.js b/dist/es2015/aurelia-route-recognizer.js similarity index 57% rename from dist/es6/aurelia-route-recognizer.js rename to dist/es2015/aurelia-route-recognizer.js index 2efd447..03b5380 100644 --- a/dist/es6/aurelia-route-recognizer.js +++ b/dist/es2015/aurelia-route-recognizer.js @@ -1,32 +1,14 @@ -import {buildQueryString,parseQueryString} from 'aurelia-path'; - -// 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) { +import { buildQueryString, parseQueryString } from 'aurelia-path'; + +export let State = class State { + constructor(charSpec) { this.charSpec = charSpec; this.nextStates = []; } - get(charSpec: CharSpec): State { + get(charSpec) { for (let child of this.nextStates) { - let isEqual = child.charSpec.validChars === charSpec.validChars - && child.charSpec.invalidChars === charSpec.invalidChars; + let isEqual = child.charSpec.validChars === charSpec.validChars && child.charSpec.invalidChars === charSpec.invalidChars; if (isEqual) { return child; @@ -34,34 +16,25 @@ export class State { } } - put(charSpec: CharSpec): State { + put(charSpec) { let 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[] { + match(ch) { let nextStates = this.nextStates; let results = []; @@ -82,38 +55,18 @@ export class State { return results; } -} +}; -const specials = [ - '/', '.', '*', '+', '?', '|', - '(', ')', '[', ']', '{', '}', '\\' -]; +const specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; const escapeRegex = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); -// A Segment represents a segment in the original route description. -// Each Segment type provides an `eachChar` and `regex` method. -// -// The `eachChar` method invokes the callback with one or more character -// specifications. A character specification consumes one or more input -// characters. -// -// The `regex` method returns a regex fragment for the segment. If the -// segment is a dynamic or star segment, the regex fragment also includes -// a capture. -// -// A character specification contains: -// -// * `validChars`: a String with a list of all valid characters, or -// * `invalidChars`: a String with a list of all invalid characters -// * `repeat`: true if the character specification can repeat - -export class StaticSegment { - constructor(string: string) { +export let StaticSegment = class StaticSegment { + constructor(string) { this.string = string; } - eachChar(callback: (spec: CharSpec) => void): void { + eachChar(callback) { let s = this.string; for (let i = 0, ii = s.length; i < ii; ++i) { let ch = s[i]; @@ -121,110 +74,72 @@ export class StaticSegment { } } - regex(): string { + regex() { return this.string.replace(escapeRegex, '\\$1'); } - generate(): string { + generate() { return this.string; } -} +}; -export class DynamicSegment { - constructor(name: string) { +export let DynamicSegment = class DynamicSegment { + constructor(name) { this.name = name; } - eachChar(callback: (spec: CharSpec) => void): void { + eachChar(callback) { callback({ invalidChars: '/', repeat: true }); } - regex(): string { + regex() { return '([^/]+)'; } - generate(params: Object, consumed: Object): string { + generate(params, consumed) { consumed[this.name] = true; return params[this.name]; } -} +}; -export class StarSegment { - constructor(name: string) { +export let StarSegment = class StarSegment { + constructor(name) { this.name = name; } - eachChar(callback: (spec: CharSpec) => void): void { + eachChar(callback) { callback({ invalidChars: '', repeat: true }); } - regex(): string { + regex() { return '(.+)'; } - generate(params: Object, consumed: Object): string { + generate(params, consumed) { consumed[this.name] = true; return params[this.name]; } -} +}; -export class EpsilonSegment { - eachChar(): void { - } +export let EpsilonSegment = class EpsilonSegment { + eachChar() {} - regex(): string { + regex() { return ''; } - generate(): string { + generate() { return ''; } -} - -interface RouteHandler { - name: string; -} - -interface ConfigurableRoute { - path: string; - handler: RouteHandler; -} +}; -interface HandlerEntry { - handler: RouteHandler; - names: string[]; -} - -interface RecognizedRoute { - handler: RouteHandler; - params: Object; - isDynamic: boolean; -} - -interface CharSpec { - invalidChars?: string; - validChars?: string; - repeat?: boolean; -} - -/** -* Class that parses route patterns and matches path strings. -* -* @class RouteRecognizer -* @constructor -*/ -export class RouteRecognizer { +export let RouteRecognizer = class RouteRecognizer { constructor() { this.rootState = new State(); this.names = {}; } - /** - * Parse a route pattern and add it to the collection of recognized routes. - * - * @param route The route to add. - */ - add(route: ConfigurableRoute|ConfigurableRoute[]): State { + add(route) { if (Array.isArray(route)) { route.forEach(r => this.add(r)); return undefined; @@ -246,11 +161,9 @@ export class RouteRecognizer { isEmpty = false; - // Add a '/' for the new segment currentState = currentState.put({ validChars: '/' }); regex += '/'; - // Add a representation of the segment to the NFA and regex currentState = addSegment(currentState, segment); regex += segment.regex(); } @@ -279,45 +192,25 @@ export class RouteRecognizer { return currentState; } - /** - * Retrieve the handlers registered for the named route. - * - * @param name The name of the route. - * @returns The handlers. - */ - handlersFor(name: string): HandlerEntry[] { + handlersFor(name) { let route = this.names[name]; if (!route) { - throw new Error(`There is no route named ${name}`); + throw new Error(`There is no route named ${ name }`); } return [...route.handlers]; } - /** - * Check if this RouteRecognizer recognizes a named route. - * - * @param name The name of the route. - * @returns True if the named route is recognized. - */ - hasRoute(name: string): boolean { + hasRoute(name) { return !!this.names[name]; } - /** - * Generate a path and query string from a route name and params object. - * - * @param name The name of the route. - * @param params The route params to use when populating the pattern. - * Properties not required by the pattern will be appended to the query string. - * @returns The generated absolute path and query string. - */ - generate(name: string, params: Object): string { + generate(name, params) { let routeParams = Object.assign({}, params); let route = this.names[name]; if (!route) { - throw new Error(`There is no route named ${name}`); + throw new Error(`There is no route named ${ name }`); } let segments = route.segments; @@ -334,7 +227,7 @@ export class RouteRecognizer { output += '/'; let segmentValue = segment.generate(routeParams, consumed); if (segmentValue === null || segmentValue === undefined) { - throw new Error(`A value is required for route parameter '${segment.name}' in route '${name}'.`); + throw new Error(`A value is required for route parameter '${ segment.name }' in route '${ name }'.`); } output += segmentValue; @@ -344,26 +237,17 @@ export class RouteRecognizer { output = '/' + output; } - // remove params used in the path and add the rest to the querystring for (let param in consumed) { delete routeParams[param]; } let queryString = buildQueryString(routeParams); - output += queryString ? `?${queryString}` : ''; + output += queryString ? `?${ queryString }` : ''; return output; } - /** - * Match a path string against registered route patterns. - * - * @param path The path to attempt to match. - * @returns Array of objects containing `handler`, `params`, and - * `isDynanic` values for the matched route(s), or undefined if no match - * was found. - */ - recognize(path: string): RecognizedRoute[] { + recognize(path) { let states = [this.rootState]; let queryParams = {}; let isSlashDropped = false; @@ -406,8 +290,6 @@ export class RouteRecognizer { let state = solutions[0]; if (state && state.handlers) { - // if a trailing slash was dropped and a star segment is the last segment - // specified, put the trailing slash back if (isSlashDropped && state.regex.source.slice(-5) === '(.+)$') { normalizedPath = normalizedPath + '/'; } @@ -415,21 +297,20 @@ export class RouteRecognizer { return findHandler(state, normalizedPath, queryParams); } } -} +}; -class RecognizeResults { - constructor(queryParams: Object) { +let RecognizeResults = class RecognizeResults { + constructor(queryParams) { this.splice = Array.prototype.splice; this.slice = Array.prototype.slice; this.push = Array.prototype.push; this.length = 0; this.queryParams = queryParams || {}; } -} +}; + function parse(route, names, types) { - // normalize route as not starting with a '/'. Recognition will - // also normalize. let normalizedRoute = route; if (route.charAt(0) === '/') { normalizedRoute = route.substr(1); @@ -464,16 +345,6 @@ function parse(route, names, types) { return results; } -// This is a somewhat naive strategy, but should work in a lot of cases -// A better strategy would properly resolve /posts/:id/new and /posts/edit/:id. -// -// This strategy generally prefers more static and less dynamic matching. -// Specifically, it -// -// * prefers fewer stars to more, then -// * prefers using stars for less of the match to more, then -// * prefers fewer dynamic segments to more, then -// * prefers more static segments to more function sortSolutions(states) { return states.sort((a, b) => { if (a.types.stars !== b.types.stars) { @@ -541,4 +412,4 @@ function addSegment(currentState, segment) { }); return state; -} +} \ No newline at end of file diff --git a/dist/system/aurelia-route-recognizer.d.ts b/dist/system/aurelia-route-recognizer.d.ts index 138404b..05fa378 100644 --- a/dist/system/aurelia-route-recognizer.d.ts +++ b/dist/system/aurelia-route-recognizer.d.ts @@ -1,5 +1,8 @@ declare module 'aurelia-route-recognizer' { - import { buildQueryString, parseQueryString } from 'aurelia-path'; + import { + buildQueryString, + parseQueryString + } from 'aurelia-path'; export interface RouteHandler { name: string; } @@ -22,47 +25,47 @@ 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. + // 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 + // 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. - // - // The `eachChar` method invokes the callback with one or more character - // specifications. A character specification consumes one or more input - // characters. - // - // The `regex` method returns a regex fragment for the segment. If the - // segment is a dynamic or star segment, the regex fragment also includes - // a capture. - // - // A character specification contains: - // - // * `validChars`: a String with a list of all valid characters, or - // * `invalidChars`: a String with a list of all invalid characters - // * `repeat`: true if the character specification can repeat + // A Segment represents a segment in the original route description. + // Each Segment type provides an `eachChar` and `regex` method. + // + // The `eachChar` method invokes the callback with one or more character + // specifications. A character specification consumes one or more input + // characters. + // + // The `regex` method returns a regex fragment for the segment. If the + // segment is a dynamic or star segment, the regex fragment also includes + // a capture. + // + // A character specification contains: + // + // * `validChars`: a String with a list of all valid characters, or + // * `invalidChars`: a String with a list of all invalid characters + // * `repeat`: true if the character specification can repeat export class StaticSegment { constructor(string: string); eachChar(callback: ((spec: CharSpec) => void)): void; @@ -87,6 +90,12 @@ declare module 'aurelia-route-recognizer' { generate(): string; } + /** + * Class that parses route patterns and matches path strings. + * + * @class RouteRecognizer + * @constructor + */ /** * Class that parses route patterns and matches path strings. * @@ -139,7 +148,4 @@ declare module 'aurelia-route-recognizer' { */ recognize(path: string): RecognizedRoute[]; } - class RecognizeResults { - constructor(queryParams: Object); - } } \ No newline at end of file diff --git a/dist/system/aurelia-route-recognizer.js b/dist/system/aurelia-route-recognizer.js index 1ae2d2e..fa2b5f8 100644 --- a/dist/system/aurelia-route-recognizer.js +++ b/dist/system/aurelia-route-recognizer.js @@ -1,9 +1,13 @@ -System.register(['aurelia-path'], function (_export) { - 'use strict'; +'use strict'; +System.register(['aurelia-path'], function (_export, _context) { var buildQueryString, parseQueryString, 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'); } } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } function parse(route, names, types) { var normalizedRoute = route; @@ -114,7 +118,7 @@ System.register(['aurelia-path'], function (_export) { parseQueryString = _aureliaPath.parseQueryString; }], execute: function () { - State = (function () { + _export('State', State = function () { function State(charSpec) { _classCallCheck(this, State); @@ -186,14 +190,14 @@ System.register(['aurelia-path'], function (_export) { }; return State; - })(); + }()); _export('State', State); specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; escapeRegex = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); - StaticSegment = (function () { + _export('StaticSegment', StaticSegment = function () { function StaticSegment(string) { _classCallCheck(this, StaticSegment); @@ -217,11 +221,11 @@ System.register(['aurelia-path'], function (_export) { }; return StaticSegment; - })(); + }()); _export('StaticSegment', StaticSegment); - DynamicSegment = (function () { + _export('DynamicSegment', DynamicSegment = function () { function DynamicSegment(name) { _classCallCheck(this, DynamicSegment); @@ -242,11 +246,11 @@ System.register(['aurelia-path'], function (_export) { }; return DynamicSegment; - })(); + }()); _export('DynamicSegment', DynamicSegment); - StarSegment = (function () { + _export('StarSegment', StarSegment = function () { function StarSegment(name) { _classCallCheck(this, StarSegment); @@ -267,11 +271,11 @@ System.register(['aurelia-path'], function (_export) { }; return StarSegment; - })(); + }()); _export('StarSegment', StarSegment); - EpsilonSegment = (function () { + _export('EpsilonSegment', EpsilonSegment = function () { function EpsilonSegment() { _classCallCheck(this, EpsilonSegment); } @@ -287,11 +291,11 @@ System.register(['aurelia-path'], function (_export) { }; return EpsilonSegment; - })(); + }()); _export('EpsilonSegment', EpsilonSegment); - RouteRecognizer = (function () { + _export('RouteRecognizer', RouteRecognizer = function () { function RouteRecognizer() { _classCallCheck(this, RouteRecognizer); @@ -341,8 +345,8 @@ System.register(['aurelia-path'], function (_export) { if (routeName) { var routeNames = Array.isArray(routeName) ? routeName : [routeName]; - for (var i = 0; i < routeNames.length; i++) { - this.names[routeNames[i]] = { + for (var _i2 = 0; _i2 < routeNames.length; _i2++) { + this.names[routeNames[_i2]] = { segments: segments, handlers: handlers }; @@ -444,9 +448,9 @@ System.register(['aurelia-path'], function (_export) { } var solutions = []; - for (var i = 0, l = states.length; i < l; i++) { - if (states[i].handlers) { - solutions.push(states[i]); + for (var _i3 = 0, _l = states.length; _i3 < _l; _i3++) { + if (states[_i3].handlers) { + solutions.push(states[_i3]); } } @@ -463,7 +467,7 @@ System.register(['aurelia-path'], function (_export) { }; return RouteRecognizer; - })(); + }()); _export('RouteRecognizer', RouteRecognizer); diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index cde1ec2..5879312 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,7 @@ +### 1.0.0-beta.1.2.0 (2016-03-22) + +* Update to Babel 6 + ### 1.0.0-beta.1.1.3 (2016-03-02) diff --git a/doc/api.json b/doc/api.json index d5c3c8d..36ea66f 100644 --- a/doc/api.json +++ b/doc/api.json @@ -295,59 +295,6 @@ } ] }, - { - "id": 104, - "name": "RecognizeResults", - "kind": 128, - "kindString": "Class", - "flags": {}, - "children": [ - { - "id": 105, - "name": "constructor", - "kind": 512, - "kindString": "Constructor", - "flags": {}, - "signatures": [ - { - "id": 106, - "name": "new RecognizeResults", - "kind": 16384, - "kindString": "Constructor signature", - "flags": {}, - "parameters": [ - { - "id": 107, - "name": "queryParams", - "kind": 32768, - "kindString": "Parameter", - "flags": {}, - "type": { - "type": "reference", - "name": "Object" - } - } - ], - "type": { - "type": "reference", - "name": "RecognizeResults", - "id": 104, - "moduleName": "\"aurelia-route-recognizer\"" - } - } - ] - } - ], - "groups": [ - { - "title": "Constructors", - "kind": 512, - "children": [ - 105 - ] - } - ] - }, { "id": 85, "name": "RouteRecognizer", @@ -1487,7 +1434,6 @@ "children": [ 46, 78, - 104, 85, 62, 19, diff --git a/package.json b/package.json index d4dd030..87cc0a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-route-recognizer", - "version": "1.0.0-beta.1.1.3", + "version": "1.0.0-beta.1.2.0", "description": "A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.", "keywords": [ "aurelia",