@vbarbarosh/node-helpers 3.10.1 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.10.1",
5
+ "version": "3.11.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,21 @@
1
+ const querystring = require('querystring');
2
+
3
+ /**
4
+ * Replace unnecessary encodes symbols with chars. The returned url will be
5
+ * more human frieldy, at the same time it still be valid url.
6
+ */
7
+ function urlclean(url)
8
+ {
9
+ const i = url.indexOf('?') + 1;
10
+ if (i) {
11
+ const s = querystring.stringify(querystring.parse(url.slice(i)), '&', '=', {
12
+ encodeURIComponent: function (v) {
13
+ return encodeURIComponent(v).replaceAll('%3A', ':').replaceAll('%2F', '/');
14
+ },
15
+ });
16
+ return url.slice(0, i) + s;
17
+ }
18
+ return url;
19
+ }
20
+
21
+ module.exports = urlclean;
@@ -0,0 +1,18 @@
1
+ const assert = require('assert');
2
+ const urlclean = require('./urlclean');
3
+
4
+ const items = [
5
+ ['', ''],
6
+ ['http://127.0.0.1:3000/proxy', 'http://127.0.0.1:3000/proxy'],
7
+ ['http://127.0.0.1:3000/proxy?url=http://127.0.0.1:3000/static/&redirects=2', 'http://127.0.0.1:3000/proxy?url=http://127.0.0.1:3000/static/&redirects=2'],
8
+ ['http://127.0.0.1:3000/proxy?url=http%3A%2F%2F127.0.0.1%3A3000%2Fstatic%2F&redirects=1', 'http://127.0.0.1:3000/proxy?url=http://127.0.0.1:3000/static/&redirects=1'],
9
+ ];
10
+
11
+ describe('urlclean', function () {
12
+ items.forEach(function ([input, expected]) {
13
+ it(input, function () {
14
+ const actual = urlclean(input);
15
+ assert.strictEqual(actual, expected);
16
+ });
17
+ });
18
+ });