Skip to content

Commit

Permalink
feat: replace query-string with native URLSearchParams (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablopalacios authored Aug 5, 2021
1 parent 1213e9c commit 1648033
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

## 3.0.0

### Breaking Changes

- `routr` uses native `URLSearchParams` instead of `query-string`
library internally. If you need to support old browsers, you can
either add a `URLSearchParams` polyfill or inject `query-string`
when instantiating `routr`:

```js
router = new Routr(routes, {
queryLib: require('query-string'),
});
```

## 2.1.0

- [#37] Enhance makePath for routes with path array
Expand Down
24 changes: 23 additions & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@
'use strict';

var pathToRegexp = require('path-to-regexp');
var queryString = require('query-string');
var DEFAULT_METHOD = 'GET';
var cachedCompilers = {};

var queryString = {
parse: function (string) {
var obj = {};

var params = new URLSearchParams(string);
params.forEach(function (value, key) {
obj[key] = value;
});

return obj;
},
stringify: function (obj) {
var params = new URLSearchParams();
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
params.append(key, obj[key]);
}
}
params.sort();
return params.toString();
},
};

/**
* @class Route
* @param {String} name The name of the route
Expand Down
25 changes: 0 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
}
],
"dependencies": {
"path-to-regexp": "^1.1.1",
"query-string": "^5.0.0"
"path-to-regexp": "^1.1.1"
},
"devDependencies": {
"babel-eslint": "^10.0.2",
Expand Down

0 comments on commit 1648033

Please sign in to comment.