├── .editorconfig ├── .gitignore ├── .jshintignore ├── .jshintrc ├── changelog.markdown ├── license ├── package.json ├── queso.js └── readme.markdown /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | .DS_Store 4 | Thumbs.db 5 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | dist 4 | example 5 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "newcap": true, 5 | "noarg": true, 6 | "noempty": true, 7 | "nonew": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "trailing": true, 12 | "boss": true, 13 | "eqnull": true, 14 | "strict": true, 15 | "immed": true, 16 | "expr": true, 17 | "latedef": "nofunc", 18 | "quotmark": "single", 19 | "validthis": true, 20 | "indent": 2, 21 | "node": true, 22 | "browser": true 23 | } 24 | -------------------------------------------------------------------------------- /changelog.markdown: -------------------------------------------------------------------------------- 1 | # 1.0.0 IPO 2 | 3 | - Initial Public Release 4 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2015 Nicolas Bevacqua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "queso", 3 | "version": "1.0.0", 4 | "description": "Turn a plain object into a query string", 5 | "main": "queso.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/bevacqua/queso.git" 9 | }, 10 | "author": "Nicolas Bevacqua (http://bevacqua.io/)", 11 | "license": "MIT", 12 | "bugs": { 13 | "url": "https://github.com/bevacqua/queso/issues" 14 | }, 15 | "homepage": "https://github.com/bevacqua/queso", 16 | "dependencies": { 17 | }, 18 | "devDependencies": { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /queso.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function stringify (query, amp) { 4 | return Object.keys(query).reduce(pairs, ''); 5 | function pairs (q, key) { 6 | var prefix = amp !== true && q.length === 0 ? '?' : '&'; 7 | var left = q + prefix + key; 8 | var value = query[key]; 9 | if (value === true) { 10 | return left; 11 | } 12 | var encoded = encodeURIComponent(value); 13 | return left + '=' + encoded; 14 | } 15 | } 16 | 17 | module.exports = { 18 | stringify: stringify 19 | }; 20 | -------------------------------------------------------------------------------- /readme.markdown: -------------------------------------------------------------------------------- 1 | # queso 2 | 3 | > Turn a plain object into a query string 4 | 5 | # Install 6 | 7 | ```shell 8 | npm install queso --save 9 | ``` 10 | 11 | # Usage 12 | 13 | You can use `queso` to generate a full query string. 14 | 15 | ```js 16 | queso.stringify({ foo: 'bar', baz: true }); 17 | // <- ?foo=bar&baz 18 | ``` 19 | 20 | You can also demand that the prefix is always an ampersand `&`. 21 | 22 | ```js 23 | queso.stringify({ foo: 'bar', baz: true }, true); 24 | // <- &foo=bar&baz 25 | ``` 26 | 27 | # License 28 | 29 | MIT 30 | --------------------------------------------------------------------------------