Skip to content

Commit ff4c554

Browse files
author
Forbes Lindesay
committedOct 31, 2014
Update and move to npm + browserify and minify JS and add source maps
1 parent 512dee1 commit ff4c554

19 files changed

+124
-9166
lines changed
 

‎.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ lib-cov
66
*.out
77
*.pid
88
*.gz
9-
109
pids
1110
logs
1211
results
13-
12+
npm-debug.log
1413
node_modules
15-
npm-debug.log

‎LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2014 Forbes Lindesay
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

‎README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
express-route-tester
22
====================
33

4-
Attempts to give you an idea of what urls will be accepted by an express route (please fork and extend it)
4+
Attempts to give you an idea of what urls will be accepted by an express route (please fork and extend it).
5+
6+
To build, run:
7+
8+
```
9+
npm install
10+
npm run build
11+
```

‎build.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/build.css

-1
This file was deleted.

‎build/build.js

-313
This file was deleted.

‎components/MatthewMueller-debounce/component.json

-13
This file was deleted.

‎components/MatthewMueller-debounce/index.js

-29
This file was deleted.

‎components/component-path-to-regexp/component.json

-15
This file was deleted.

‎components/component-path-to-regexp/index.js

-52
This file was deleted.

‎css/bootstrap-responsive.css

-1,040
This file was deleted.

‎css/bootstrap.css

-5,624
This file was deleted.

‎index.html

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
<title>Express Route Tester</title>
55
<!-- Bootstrap -->
66
<link href="css/bootstrap.min.css" rel="stylesheet">
7-
<meta name="viewport"
8-
content="width=device-width, initial-scale=1.0">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
98
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
10-
<link href="build/build.css" rel="stylesheet">
119
</head>
1210
<body>
1311
<div class="container-fluid">
@@ -22,14 +20,14 @@ <h1>Express Route Tester</h1>
2220
<div class="control-group">
2321
<label class="control-label" for="inputRoute">Route</label>
2422
<div class="controls">
25-
<input type="text" id="inputRoute"
23+
<input type="text" id="inputRoute"
2624
placeholder="/path/:key/">
2725
</div>
2826
</div>
2927
<div class="control-group">
3028
<label class="control-label" for="inputPath">Path</label>
3129
<div class="controls">
32-
<input type="text" id="inputPath"
30+
<input type="text" id="inputPath"
3331
placeholder="/path/value/">
3432
</div>
3533
</div>
@@ -65,8 +63,6 @@ <h2>Results</h2>
6563
</div><!--/span-->
6664
</div><!--/row-->
6765
</div><!--/container-->
68-
<script src="js/jquery.min.js"></script>
69-
<script src="js/bootstrap.min.js"></script>
70-
<script src="build/build.js"></script>
66+
<script src="build.js"></script>
7167
</body>
72-
</html>
68+
</html>

‎index.js

+55-31
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,56 @@
1-
$(function () {
2-
var pathRegexp = require('path-to-regexp');
3-
var debounce = require('debounce');
4-
$('#inputRoute, #inputPath').keyup(debounce(update, 200));
5-
function update() {
6-
var keys = [];
7-
var regexp = pathRegexp($('#inputRoute').val(), keys);
8-
$('#regexp-display').html(regexp.toString());
9-
if (keys.length) {
10-
$('#keys-display').html('<ol>' + keys.map(function wrap(key) {
11-
return '<li>' + key.name + (key.optional?' (optional)':'') + '</li>';
12-
}).join('') + '</ol>');
13-
} else {
14-
$('#keys-display').html('There are no keys captured by this route');
15-
}
1+
'use strict';
162

17-
var path = $('#inputPath').val();
18-
if (regexp.test(path)) {
19-
$('.is-not-match').hide();
20-
$('.is-match').show();
21-
var result = regexp.exec(path);
22-
$('#keys-results-display').html('<dl class="dl-horizontal">' + keys.map(function (key, i) {
23-
return '<dt>' + key.name + '</dt><dd>' +
24-
result[i + 1] + '</dd>';
25-
}).join('') + '</dl>');
26-
} else {
27-
$('.is-not-match').show();
28-
$('.is-match').hide();
29-
}
30-
}
31-
update();
32-
});
3+
var pathRegexp = require('path-to-regexp');
4+
var debounce = require('debounce');
5+
6+
var _ = document.querySelector.bind(document);
7+
8+
function escape(str) {
9+
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;');
10+
}
11+
function hide(selector) {
12+
var elements = document.querySelectorAll(selector);
13+
for (var i = 0; i < elements.length; i++) {
14+
elements[i].style.display = 'none';
15+
}
16+
}
17+
function show(selector) {
18+
var elements = document.querySelectorAll(selector);
19+
for (var i = 0; i < elements.length; i++) {
20+
elements[i].style.display = null;
21+
}
22+
}
23+
24+
_('#inputRoute').addEventListener('input', debounce(update, 100), false);
25+
_('#inputPath').addEventListener('input', debounce(updatePath, 100), false);
26+
27+
var keys, regexp;
28+
function update() {
29+
keys = [];
30+
regexp = pathRegexp(_('#inputRoute').value, keys);
31+
_('#regexp-display').textContent = regexp.toString();
32+
if (keys.length) {
33+
_('#keys-display').innerHTML = '<ol>' + keys.map(function wrap(key) {
34+
return '<li>' + escape(key.name) + (key.optional ? ' (optional)' : '') + '</li>';
35+
}).join('') + '</ol>';
36+
} else {
37+
_('#keys-display').innerHTML = 'There are no keys captured by this route';
38+
}
39+
updatePath();
40+
}
41+
function updatePath() {
42+
var path = _('#inputPath').value;
43+
if (regexp.test(path)) {
44+
hide('.is-not-match');
45+
show('.is-match');
46+
var result = regexp.exec(path);
47+
_('#keys-results-display').innerHTML = '<dl class="dl-horizontal">' + keys.map(function (key, i) {
48+
return '<dt>' + escape(key.name) + '</dt><dd>' +
49+
escape(result[i + 1]) + '</dd>';
50+
}).join('') + '</dl>';
51+
} else {
52+
show('.is-not-match');
53+
hide('.is-match');
54+
}
55+
}
56+
update();

‎js/bootstrap.js

-2,027
This file was deleted.

‎js/bootstrap.min.js

-6
This file was deleted.

‎js/jquery.min.js

-2
This file was deleted.

‎package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "express-route-tester",
3+
"version": "0.0.0",
4+
"description": "Demo app to easilly test express routes",
5+
"keywords": [],
6+
"dependencies": {
7+
"debounce": "^1.0.0",
8+
"path-to-regexp": "^1.0.1"
9+
},
10+
"devDependencies": {
11+
"browserify": "^5.13.1",
12+
"minifyify": "^4.4.0"
13+
},
14+
"scripts": {
15+
"build": "browserify index.js -d -p [minifyify --compressPath . --map build.js.map --output build.js.map] > build.js"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/ForbesLindesay/express-route-tester.git"
20+
},
21+
"author": "ForbesLindesay",
22+
"license": "MIT"
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.