Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doesdev/tiny-params
A tiny URL param parser, suitable for server or browser
https://github.com/doesdev/tiny-params
parameters querystrings url-parser
Last synced: about 20 hours ago
JSON representation
A tiny URL param parser, suitable for server or browser
- Host: GitHub
- URL: https://github.com/doesdev/tiny-params
- Owner: doesdev
- License: mit
- Created: 2017-02-25T19:11:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-13T23:04:59.000Z (over 4 years ago)
- Last Synced: 2024-11-11T21:20:33.669Z (8 days ago)
- Topics: parameters, querystrings, url-parser
- Language: JavaScript
- Homepage: http://tiny-params.doesdev.com/
- Size: 105 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-params
> A tiny URL param parser, suitable for server or browser
## highlights
- it's tiny (< 25 sloc)
- it's highly browser compatible (IE6 and everything else)
- it ships with both ES6 and CommonJS modules
- it makes repeated keys an array `?a=1&a=2` -> `{ a: [1, 2] }`
- it handles explicit arrays `?a[]=1` -> `{ a: [1] }`
- it handles flags (key with no value) `?a=b&flag` -> `{ a: 'b', flag: true }`
- it decodes `encodeURIComponent` encoded items
- it converts booleans and numbers from strings
- it converts the values `'null'` and `'undefined'` to `null`
- it respects the hash (as per [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3.4))
- it's competitively fast (not the fastest, not far from it)## lowlights
- it looks like code golf, kind of is
- it uses `decodeURIComponent` (sparingly) which is slow (but highly compatible)## install
```sh
$ npm install --save tiny-params
```## usage
```js
const tinyParams = require('tiny-params')
const url = 'http://localhost:80/base/res?name=andrew&zip=37615&zip=37601'
const params = tinyParams(url)
// params === { name: 'andrew', zip: [37615, 37601] }
```## License
MIT © [Andrew Carpenter](https://github.com/doesdev)