Skip to content

Commit

Permalink
feat(UrlMatcher): allow shorthand definitions
Browse files Browse the repository at this point in the history
When defining parameter configurations, `{ param: "default" }` is now equivalent to `{ param: { value: "default" }}`.
  • Loading branch information
nateabele committed Apr 17, 2014
1 parent 101012e commit 5b72430
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function UrlMatcher(pattern, config) {

function paramConfig(param) {
if (!config.params || !config.params[param]) return {};
return config.params[param];
var cfg = config.params[param];
return isObject(cfg) ? cfg : { value: cfg };
}

this.source = pattern;
Expand Down
7 changes: 7 additions & 0 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ describe("urlMatcherFactory", function () {
expect(m.exec('/users/2/bar')).toEqual({ id: 2, test: "bar" });
expect(m.exec('/users/bar/2')).toBeNull();
});

it("should allow shorthand definitions", function() {
var m = new UrlMatcher('/foo/:foo', {
params: { foo: "bar" }
});
expect(m.exec("/foo")).toEqual({ foo: "bar" });
});
});
});

Expand Down

0 comments on commit 5b72430

Please sign in to comment.