├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── browser.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | tmp/ 4 | dist/ 5 | npm-debug.log* 6 | .DS_Store 7 | .nyc_output 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - "4" 3 | - "5" 4 | - "6" 5 | - "7" 6 | sudo: false 7 | language: node_js 8 | script: "npm run test" 9 | # after_success: "npm i -g codecov && npm run coverage && codecov" 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yoshua Wuyts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nanoquery [![stability][0]][1] 2 | [![npm version][2]][3] [![build status][4]][5] 3 | [![downloads][8]][9] [![js-standard-style][10]][11] 4 | 5 | Tiny querystring module for Node, Electron and browsers. 6 | 7 | ## Usage 8 | ```js 9 | var nanoquery = require('nanoquery') 10 | 11 | var kv = nanoquery(window.location.href) 12 | console.log(kv) 13 | ``` 14 | 15 | ## API 16 | ### `kv = nanoquery(url)` 17 | Destructure a url to an object containing the querystring mapping 18 | 19 | ## License 20 | [MIT](https://tldrlegal.com/license/mit-license) 21 | 22 | [0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square 23 | [1]: https://nodejs.org/api/documentation.html#documentation_stability_index 24 | [2]: https://img.shields.io/npm/v/nanoquery.svg?style=flat-square 25 | [3]: https://npmjs.org/package/nanoquery 26 | [4]: https://img.shields.io/travis/choojs/nanoquery/master.svg?style=flat-square 27 | [5]: https://travis-ci.org/choojs/nanoquery 28 | [6]: https://img.shields.io/codecov/c/github/choojs/nanoquery/master.svg?style=flat-square 29 | [7]: https://codecov.io/github/choojs/nanoquery 30 | [8]: http://img.shields.io/npm/dm/nanoquery.svg?style=flat-square 31 | [9]: https://npmjs.org/package/nanoquery 32 | [10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 33 | [11]: https://github.com/feross/standard 34 | -------------------------------------------------------------------------------- /browser.js: -------------------------------------------------------------------------------- 1 | var reg = /([^?=&]+)(=([^&]*))?/g 2 | var assert = require('assert') 3 | 4 | module.exports = qs 5 | 6 | function qs (url) { 7 | assert.equal(typeof url, 'string', 'nanoquery: url should be type string') 8 | 9 | var obj = {} 10 | url.replace(/^.*\?/, '').replace(reg, function (a0, a1, a2, a3) { 11 | var value = decodeURIComponent(a3) 12 | var key = decodeURIComponent(a1) 13 | if (obj.hasOwnProperty(key)) { 14 | if (Array.isArray(obj[key])) obj[key].push(value) 15 | else obj[key] = [obj[key], value] 16 | } else { 17 | obj[key] = value 18 | } 19 | }) 20 | 21 | return obj 22 | } 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | var Url = require('url') 3 | 4 | if (typeof window !== 'undefined') { 5 | module.exports = require('./browser') 6 | } else { 7 | module.exports = nanoquery 8 | } 9 | 10 | function nanoquery (url) { 11 | assert.equal(typeof url, 'string', 'nanoquery: url should be type string') 12 | return Url.parse(url, true).query 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nanoquery", 3 | "description": "Tiny querystring module", 4 | "repository": "choojs/nanoquery", 5 | "version": "1.3.0", 6 | "scripts": { 7 | "test": "standard" 8 | }, 9 | "browser": { 10 | "./index.js": "./browser.js", 11 | "assert": "nanoassert" 12 | }, 13 | "dependencies": { 14 | "nanoassert": "^1.1.0" 15 | }, 16 | "devDependencies": { 17 | "dependency-check": "^2.9.1", 18 | "standard": "^10.0.2", 19 | "tape": "^4.7.0" 20 | }, 21 | "keywords": [ 22 | "query", 23 | "querystring", 24 | "small", 25 | "browser" 26 | ], 27 | "license": "MIT" 28 | } 29 | --------------------------------------------------------------------------------