Skip to content

Commit 0aa95b1

Browse files
authored
Release 1.1.2
* Fix typo in example code (#62) * Removes parenthesis around replaced params (#64)
1 parent dc9c3b8 commit 0aa95b1

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

lib/params-applier/rules-applier.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ export default (path = '', rules = []) => {
66
rules
77
.map(rule => applyRule(path, rule))
88
.reduce((result, item) => result.concat(item), [])
9+
.map(location => {
10+
// for each remaining (optional) param group that hasn't been removed, the optional group is removed from the location
11+
// /foo/bar(/:param) => /foo/bar
12+
location = location.replace(/\((.*:.*)\)/g, '');
13+
14+
// remove other parenthesis that might be wrapping params that have been replaced
15+
// /foo(/:bar) => /foo(/bar-value) => /foo/bar-value
16+
location = location.replace(/(\(|\))/g, '');
17+
18+
return location;
19+
})
920
);
1021

1122
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-router-sitemap",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Module to generate a sitemap for react-router configuration",
55
"repository": {
66
"type": "git",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default (
2121
<Route>
2222
<Route path='/' />
2323
<Route path='/about' />
24-
<Route path='/projects'>
24+
<Route path='/projects' />
2525
<Route path='/contacts' />
2626
<Route path='/auth' />
2727
</Route>

test/spec/params-applier/rules-applier.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,36 @@ describe('rules applier', () => {
1919

2020
});
2121

22+
it('replaces optional params in path by list rules', () => {
23+
24+
const path = '/path/:param-one(/:param-two)';
25+
const rules = [
26+
{ 'param-one': 1 },
27+
{ 'param-one': 1, 'param-two': 2 },
28+
];
29+
const etalon = [
30+
'/path/1',
31+
'/path/1/2',
32+
];
33+
34+
expect(applyRules(path, rules)).toHaveSameItems(etalon, true);
35+
36+
});
37+
38+
it('removes optional params in path by list rules whose value hasn\'t been provided', () => {
39+
40+
const path = '/path/:param-one(/:param-two)';
41+
const rules = [
42+
{},
43+
{ 'param-one': 1 },
44+
];
45+
const etalon = [
46+
'/path/:param-one',
47+
'/path/1',
48+
];
49+
50+
expect(applyRules(path, rules)).toHaveSameItems(etalon, true);
51+
52+
});
53+
2254
});

0 commit comments

Comments
 (0)