diff --git a/bower.json b/bower.json index 614ab14..6403dd2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-route-recognizer", - "version": "0.2.0", + "version": "0.2.1", "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/dsl.js b/dist/amd/dsl.js index 13fc904..5b49991 100644 --- a/dist/amd/dsl.js +++ b/dist/amd/dsl.js @@ -67,7 +67,8 @@ define(["exports"], function (exports) { function addRoute(routeArray, path, handler) { var len = 0; - for (var i = 0, l = routeArray.length; i < l; i++) { + for (var i = 0, + l = routeArray.length; i < l; i++) { len += routeArray[i].path.length; } diff --git a/dist/amd/index.js b/dist/amd/index.js index d7f20b0..07ce566 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -19,7 +19,8 @@ define(["exports", "./dsl"], function (exports, _dsl) { eachChar: function (callback) { var string = this.string, ch; - for (var i = 0, l = string.length; i < l; i++) { + for (var i = 0, + l = string.length; i < l; i++) { ch = string.charAt(i); callback({ validChars: ch }); } @@ -84,9 +85,11 @@ define(["exports", "./dsl"], function (exports, _dsl) { route = route.substr(1); } - var segments = route.split("/"), results = []; + var segments = route.split("/"), + results = []; - for (var i = 0, l = segments.length; i < l; i++) { + for (var i = 0, + l = segments.length; i < l; i++) { var segment = segments[i], match; if (match = segment.match(/^:([^\/]+)$/)) { @@ -117,7 +120,8 @@ define(["exports", "./dsl"], function (exports, _dsl) { get: function (charSpec) { var nextStates = this.nextStates; - for (var i = 0, l = nextStates.length; i < l; i++) { + for (var i = 0, + l = nextStates.length; i < l; i++) { var child = nextStates[i]; var isEqual = child.charSpec.validChars === charSpec.validChars; @@ -151,7 +155,8 @@ define(["exports", "./dsl"], function (exports, _dsl) { var returned = []; - for (var i = 0, l = nextStates.length; i < l; i++) { + for (var i = 0, + l = nextStates.length; i < l; i++) { child = nextStates[i]; charSpec = child.charSpec; @@ -201,7 +206,8 @@ define(["exports", "./dsl"], function (exports, _dsl) { function recognizeChar(states, ch) { var nextStates = []; - for (var i = 0, l = states.length; i < l; i++) { + for (var i = 0, + l = states.length; i < l; i++) { var state = states[i]; nextStates = nextStates.concat(state.match(ch)); @@ -228,14 +234,20 @@ define(["exports", "./dsl"], function (exports, _dsl) { }); function findHandler(state, path, queryParams) { - var handlers = state.handlers, regex = state.regex; - var captures = path.match(regex), currentCapture = 1; + var handlers = state.handlers, + regex = state.regex; + var captures = path.match(regex), + currentCapture = 1; var result = new RecognizeResults(queryParams); - for (var i = 0, l = handlers.length; i < l; i++) { - var handler = handlers[i], names = handler.names, params = {}; + for (var i = 0, + l = handlers.length; i < l; i++) { + var handler = handlers[i], + names = handler.names, + params = {}; - for (var j = 0, m = names.length; j < m; j++) { + for (var j = 0, + m = names.length; j < m; j++) { params[names[j]] = captures[currentCapture++]; } @@ -263,18 +275,26 @@ define(["exports", "./dsl"], function (exports, _dsl) { RouteRecognizer.prototype = { add: function (routes, options) { - var currentState = this.rootState, regex = "^", types = { statics: 0, dynamics: 0, stars: 0 }, handlers = [], allSegments = [], name; + var currentState = this.rootState, + regex = "^", + types = { statics: 0, dynamics: 0, stars: 0 }, + handlers = [], + allSegments = [], + name; var isEmpty = true; - for (var i = 0, l = routes.length; i < l; i++) { - var route = routes[i], names = []; + for (var i = 0, + l = routes.length; i < l; i++) { + var route = routes[i], + names = []; var segments = parse(route.path, names, types); allSegments = allSegments.concat(segments); - for (var j = 0, m = segments.length; j < m; j++) { + for (var j = 0, + m = segments.length; j < m; j++) { var segment = segments[j]; if (segment instanceof EpsilonSegment) { @@ -312,12 +332,14 @@ define(["exports", "./dsl"], function (exports, _dsl) { }, handlersFor: function (name) { - var route = this.names[name], result = []; + var route = this.names[name], + result = []; if (!route) { throw new Error("There is no route named " + name); } - for (var i = 0, l = route.handlers.length; i < l; i++) { + for (var i = 0, + l = route.handlers.length; i < l; i++) { result.push(route.handlers[i]); } @@ -329,14 +351,16 @@ define(["exports", "./dsl"], function (exports, _dsl) { }, generate: function (name, params) { - var route = this.names[name], output = ""; + var route = this.names[name], + output = ""; if (!route) { throw new Error("There is no route named " + name); } var segments = route.segments; - for (var i = 0, l = segments.length; i < l; i++) { + for (var i = 0, + l = segments.length; i < l; i++) { var segment = segments[i]; if (segment instanceof EpsilonSegment) { @@ -367,7 +391,8 @@ define(["exports", "./dsl"], function (exports, _dsl) { } } keys.sort(); - for (var i = 0, len = keys.length; i < len; i++) { + for (var i = 0, + len = keys.length; i < len; i++) { key = keys[i]; var value = params[key]; if (value === null) { @@ -375,7 +400,8 @@ define(["exports", "./dsl"], function (exports, _dsl) { } var pair = encodeURIComponent(key); if (isArray(value)) { - for (var j = 0, l = value.length; j < l; j++) { + for (var j = 0, + l = value.length; j < l; j++) { var arrayPair = key + "[]" + "=" + encodeURIComponent(value[j]); pairs.push(arrayPair); } @@ -393,9 +419,14 @@ define(["exports", "./dsl"], function (exports, _dsl) { }, parseQueryString: function (queryString) { - var pairs = queryString.split("&"), queryParams = {}; + var pairs = queryString.split("&"), + queryParams = {}; for (var i = 0; i < pairs.length; i++) { - var pair = pairs[i].split("="), key = decodeURIComponent(pair[0]), keyLength = key.length, isArray = false, value; + var pair = pairs[i].split("="), + key = decodeURIComponent(pair[0]), + keyLength = key.length, + isArray = false, + value; if (pair.length === 1) { value = "true"; } else { diff --git a/dist/commonjs/dsl.js b/dist/commonjs/dsl.js index 9410d82..0070fab 100644 --- a/dist/commonjs/dsl.js +++ b/dist/commonjs/dsl.js @@ -66,7 +66,8 @@ function generateMatch(startingPath, matcher, delegate) { function addRoute(routeArray, path, handler) { var len = 0; - for (var i = 0, l = routeArray.length; i < l; i++) { + for (var i = 0, + l = routeArray.length; i < l; i++) { len += routeArray[i].path.length; } diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index 8f91b7e..30b4290 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -18,7 +18,8 @@ StaticSegment.prototype = { eachChar: function (callback) { var string = this.string, ch; - for (var i = 0, l = string.length; i < l; i++) { + for (var i = 0, + l = string.length; i < l; i++) { ch = string.charAt(i); callback({ validChars: ch }); } @@ -83,9 +84,11 @@ function parse(route, names, types) { route = route.substr(1); } - var segments = route.split("/"), results = []; + var segments = route.split("/"), + results = []; - for (var i = 0, l = segments.length; i < l; i++) { + for (var i = 0, + l = segments.length; i < l; i++) { var segment = segments[i], match; if (match = segment.match(/^:([^\/]+)$/)) { @@ -116,7 +119,8 @@ State.prototype = { get: function (charSpec) { var nextStates = this.nextStates; - for (var i = 0, l = nextStates.length; i < l; i++) { + for (var i = 0, + l = nextStates.length; i < l; i++) { var child = nextStates[i]; var isEqual = child.charSpec.validChars === charSpec.validChars; @@ -150,7 +154,8 @@ State.prototype = { var returned = []; - for (var i = 0, l = nextStates.length; i < l; i++) { + for (var i = 0, + l = nextStates.length; i < l; i++) { child = nextStates[i]; charSpec = child.charSpec; @@ -200,7 +205,8 @@ function sortSolutions(states) { function recognizeChar(states, ch) { var nextStates = []; - for (var i = 0, l = states.length; i < l; i++) { + for (var i = 0, + l = states.length; i < l; i++) { var state = states[i]; nextStates = nextStates.concat(state.match(ch)); @@ -227,14 +233,20 @@ RecognizeResults.prototype = oCreate({ }); function findHandler(state, path, queryParams) { - var handlers = state.handlers, regex = state.regex; - var captures = path.match(regex), currentCapture = 1; + var handlers = state.handlers, + regex = state.regex; + var captures = path.match(regex), + currentCapture = 1; var result = new RecognizeResults(queryParams); - for (var i = 0, l = handlers.length; i < l; i++) { - var handler = handlers[i], names = handler.names, params = {}; + for (var i = 0, + l = handlers.length; i < l; i++) { + var handler = handlers[i], + names = handler.names, + params = {}; - for (var j = 0, m = names.length; j < m; j++) { + for (var j = 0, + m = names.length; j < m; j++) { params[names[j]] = captures[currentCapture++]; } @@ -262,18 +274,26 @@ var RouteRecognizer = exports.RouteRecognizer = function () { RouteRecognizer.prototype = { add: function (routes, options) { - var currentState = this.rootState, regex = "^", types = { statics: 0, dynamics: 0, stars: 0 }, handlers = [], allSegments = [], name; + var currentState = this.rootState, + regex = "^", + types = { statics: 0, dynamics: 0, stars: 0 }, + handlers = [], + allSegments = [], + name; var isEmpty = true; - for (var i = 0, l = routes.length; i < l; i++) { - var route = routes[i], names = []; + for (var i = 0, + l = routes.length; i < l; i++) { + var route = routes[i], + names = []; var segments = parse(route.path, names, types); allSegments = allSegments.concat(segments); - for (var j = 0, m = segments.length; j < m; j++) { + for (var j = 0, + m = segments.length; j < m; j++) { var segment = segments[j]; if (segment instanceof EpsilonSegment) { @@ -311,12 +331,14 @@ RouteRecognizer.prototype = { }, handlersFor: function (name) { - var route = this.names[name], result = []; + var route = this.names[name], + result = []; if (!route) { throw new Error("There is no route named " + name); } - for (var i = 0, l = route.handlers.length; i < l; i++) { + for (var i = 0, + l = route.handlers.length; i < l; i++) { result.push(route.handlers[i]); } @@ -328,14 +350,16 @@ RouteRecognizer.prototype = { }, generate: function (name, params) { - var route = this.names[name], output = ""; + var route = this.names[name], + output = ""; if (!route) { throw new Error("There is no route named " + name); } var segments = route.segments; - for (var i = 0, l = segments.length; i < l; i++) { + for (var i = 0, + l = segments.length; i < l; i++) { var segment = segments[i]; if (segment instanceof EpsilonSegment) { @@ -366,7 +390,8 @@ RouteRecognizer.prototype = { } } keys.sort(); - for (var i = 0, len = keys.length; i < len; i++) { + for (var i = 0, + len = keys.length; i < len; i++) { key = keys[i]; var value = params[key]; if (value === null) { @@ -374,7 +399,8 @@ RouteRecognizer.prototype = { } var pair = encodeURIComponent(key); if (isArray(value)) { - for (var j = 0, l = value.length; j < l; j++) { + for (var j = 0, + l = value.length; j < l; j++) { var arrayPair = key + "[]" + "=" + encodeURIComponent(value[j]); pairs.push(arrayPair); } @@ -392,9 +418,14 @@ RouteRecognizer.prototype = { }, parseQueryString: function (queryString) { - var pairs = queryString.split("&"), queryParams = {}; + var pairs = queryString.split("&"), + queryParams = {}; for (var i = 0; i < pairs.length; i++) { - var pair = pairs[i].split("="), key = decodeURIComponent(pair[0]), keyLength = key.length, isArray = false, value; + var pair = pairs[i].split("="), + key = decodeURIComponent(pair[0]), + keyLength = key.length, + isArray = false, + value; if (pair.length === 1) { value = "true"; } else { diff --git a/dist/system/dsl.js b/dist/system/dsl.js index 0f791cd..9eeed33 100644 --- a/dist/system/dsl.js +++ b/dist/system/dsl.js @@ -29,7 +29,8 @@ System.register([], function (_export) { function addRoute(routeArray, path, handler) { var len = 0; - for (var i = 0, l = routeArray.length; i < l; i++) { + for (var i = 0, + l = routeArray.length; i < l; i++) { len += routeArray[i].path.length; } diff --git a/dist/system/index.js b/dist/system/index.js index bf78528..8a06e92 100644 --- a/dist/system/index.js +++ b/dist/system/index.js @@ -31,9 +31,11 @@ System.register(["./dsl"], function (_export) { route = route.substr(1); } - var segments = route.split("/"), results = []; + var segments = route.split("/"), + results = []; - for (var i = 0, l = segments.length; i < l; i++) { + for (var i = 0, + l = segments.length; i < l; i++) { var segment = segments[i], match; if (match = segment.match(/^:([^\/]+)$/)) { @@ -89,7 +91,8 @@ System.register(["./dsl"], function (_export) { function recognizeChar(states, ch) { var nextStates = []; - for (var i = 0, l = states.length; i < l; i++) { + for (var i = 0, + l = states.length; i < l; i++) { var state = states[i]; nextStates = nextStates.concat(state.match(ch)); @@ -104,14 +107,20 @@ System.register(["./dsl"], function (_export) { function findHandler(state, path, queryParams) { - var handlers = state.handlers, regex = state.regex; - var captures = path.match(regex), currentCapture = 1; + var handlers = state.handlers, + regex = state.regex; + var captures = path.match(regex), + currentCapture = 1; var result = new RecognizeResults(queryParams); - for (var i = 0, l = handlers.length; i < l; i++) { - var handler = handlers[i], names = handler.names, params = {}; + for (var i = 0, + l = handlers.length; i < l; i++) { + var handler = handlers[i], + names = handler.names, + params = {}; - for (var j = 0, m = names.length; j < m; j++) { + for (var j = 0, + m = names.length; j < m; j++) { params[names[j]] = captures[currentCapture++]; } @@ -142,7 +151,8 @@ System.register(["./dsl"], function (_export) { eachChar: function (callback) { var string = this.string, ch; - for (var i = 0, l = string.length; i < l; i++) { + for (var i = 0, + l = string.length; i < l; i++) { ch = string.charAt(i); callback({ validChars: ch }); } @@ -191,7 +201,8 @@ System.register(["./dsl"], function (_export) { get: function (charSpec) { var nextStates = this.nextStates; - for (var i = 0, l = nextStates.length; i < l; i++) { + for (var i = 0, + l = nextStates.length; i < l; i++) { var child = nextStates[i]; var isEqual = child.charSpec.validChars === charSpec.validChars; @@ -225,7 +236,8 @@ System.register(["./dsl"], function (_export) { var returned = []; - for (var i = 0, l = nextStates.length; i < l; i++) { + for (var i = 0, + l = nextStates.length; i < l; i++) { child = nextStates[i]; charSpec = child.charSpec; @@ -266,18 +278,26 @@ System.register(["./dsl"], function (_export) { RouteRecognizer.prototype = { add: function (routes, options) { - var currentState = this.rootState, regex = "^", types = { statics: 0, dynamics: 0, stars: 0 }, handlers = [], allSegments = [], name; + var currentState = this.rootState, + regex = "^", + types = { statics: 0, dynamics: 0, stars: 0 }, + handlers = [], + allSegments = [], + name; var isEmpty = true; - for (var i = 0, l = routes.length; i < l; i++) { - var route = routes[i], names = []; + for (var i = 0, + l = routes.length; i < l; i++) { + var route = routes[i], + names = []; var segments = parse(route.path, names, types); allSegments = allSegments.concat(segments); - for (var j = 0, m = segments.length; j < m; j++) { + for (var j = 0, + m = segments.length; j < m; j++) { var segment = segments[j]; if (segment instanceof EpsilonSegment) { @@ -315,12 +335,14 @@ System.register(["./dsl"], function (_export) { }, handlersFor: function (name) { - var route = this.names[name], result = []; + var route = this.names[name], + result = []; if (!route) { throw new Error("There is no route named " + name); } - for (var i = 0, l = route.handlers.length; i < l; i++) { + for (var i = 0, + l = route.handlers.length; i < l; i++) { result.push(route.handlers[i]); } @@ -332,14 +354,16 @@ System.register(["./dsl"], function (_export) { }, generate: function (name, params) { - var route = this.names[name], output = ""; + var route = this.names[name], + output = ""; if (!route) { throw new Error("There is no route named " + name); } var segments = route.segments; - for (var i = 0, l = segments.length; i < l; i++) { + for (var i = 0, + l = segments.length; i < l; i++) { var segment = segments[i]; if (segment instanceof EpsilonSegment) { @@ -370,7 +394,8 @@ System.register(["./dsl"], function (_export) { } } keys.sort(); - for (var i = 0, len = keys.length; i < len; i++) { + for (var i = 0, + len = keys.length; i < len; i++) { key = keys[i]; var value = params[key]; if (value === null) { @@ -378,7 +403,8 @@ System.register(["./dsl"], function (_export) { } var pair = encodeURIComponent(key); if (isArray(value)) { - for (var j = 0, l = value.length; j < l; j++) { + for (var j = 0, + l = value.length; j < l; j++) { var arrayPair = key + "[]" + "=" + encodeURIComponent(value[j]); pairs.push(arrayPair); } @@ -396,9 +422,14 @@ System.register(["./dsl"], function (_export) { }, parseQueryString: function (queryString) { - var pairs = queryString.split("&"), queryParams = {}; + var pairs = queryString.split("&"), + queryParams = {}; for (var i = 0; i < pairs.length; i++) { - var pair = pairs[i].split("="), key = decodeURIComponent(pair[0]), keyLength = key.length, isArray = false, value; + var pair = pairs[i].split("="), + key = decodeURIComponent(pair[0]), + keyLength = key.length, + isArray = false, + value; if (pair.length === 1) { value = "true"; } else { diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index d598e6a..eb2e7f7 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.2.1 (2015-01-12) + +* Update compiled output. + ## 0.2.0 (2015-01-06) diff --git a/package.json b/package.json index 9be4d1b..96aeaa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-route-recognizer", - "version": "0.2.0", + "version": "0.2.1", "description": "A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.", "keywords": [ "aurelia",