pax_global_header00006660000000000000000000000064125201702140014504gustar00rootroot0000000000000052 comment=0e53b2049f1d3390b577283ab913d4825ce67987 querystringify-0.0.3/000077500000000000000000000000001252017021400146105ustar00rootroot00000000000000querystringify-0.0.3/.gitignore000066400000000000000000000000441252017021400165760ustar00rootroot00000000000000node_modules coverage npm-debug.log querystringify-0.0.3/.travis.yml000066400000000000000000000010341252017021400167170ustar00rootroot00000000000000language: node_js node_js: - "0.12" - "0.11" - "0.10" - "0.9" - "0.8" - "iojs-v1.1" - "iojs-v1.0" before_install: - "npm install -g npm@1.4.x" script: - "npm run test-travis" after_script: - "npm install coveralls@2.11.x && cat coverage/lcov.info | coveralls" matrix: fast_finish: true allow_failures: - node_js: "0.11" - node_js: "0.9" - node_js: "iojs-v1.1" - node_js: "iojs-v1.0" notifications: irc: channels: - "irc.freenode.org#unshift" on_success: change on_failure: change querystringify-0.0.3/LICENSE000066400000000000000000000021331252017021400156140ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. querystringify-0.0.3/README.md000066400000000000000000000046231252017021400160740ustar00rootroot00000000000000# querystringify [![Made by unshift](https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square)](http://unshift.io)[![Version npm](http://img.shields.io/npm/v/querystringify.svg?style=flat-square)](http://browsenpm.org/package/querystringify)[![Build Status](http://img.shields.io/travis/unshiftio/querystringify/master.svg?style=flat-square)](https://travis-ci.org/unshiftio/querystringify)[![Dependencies](https://img.shields.io/david/unshiftio/querystringify.svg?style=flat-square)](https://david-dm.org/unshiftio/querystringify)[![Coverage Status](http://img.shields.io/coveralls/unshiftio/querystringify/master.svg?style=flat-square)](https://coveralls.io/r/unshiftio/querystringify?branch=master)[![IRC channel](http://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square)](http://webchat.freenode.net/?channels=unshift) A somewhat JSON compatible interface for query string parsing. This query string parser is dumb, don't expect to much from it as it only wants to parse simple query strings. If you want to parse complex, multi level and deeply nested query strings then you should ask your self. WTF am I doing? ## Installation This module is released in npm as `querystringify`. It's also compatible with `browserify` so it can be used on the server as well as on the client. To install it simply run the following command from your CLI: ``` npm install --save querystringify ``` ## Usage In the following examples we assume that you've already required the library as: ```js 'use strict'; var qs = require('querystringify'); ``` ### qs.parse() The parse method transforms a given query string in to an object. It does not care if your query string if prefixed with a `?` or not. It just extracts the parts between the `=` and `&`: ```js qs.parse('?foo=bar'); // { foo: 'bar' } qs.parse('foo=bar'); // { foo: 'bar' } qs.parse('foo=bar&bar=foo'); // { foo: 'bar', bar: 'foo' } ``` ### qs.stringify() This transforms a given object in to a query string. By default we return the query string without a `?` prefix. If you want to prefix it by default simply supply `true` as second argument. If it should be prefixed by something else simply supply a string with the prefix value as second argument: ```js qs.stringify({ foo: bar }); // foo=bar qs.stringify({ foo: bar }, true); // ?foo=bar qs.stringify({ foo: bar }, '&'); // &foo=bar ``` ## License MIT querystringify-0.0.3/index.js000066400000000000000000000024251252017021400162600ustar00rootroot00000000000000'use strict'; var has = Object.prototype.hasOwnProperty; /** * Simple query string parser. * * @param {String} query The query string that needs to be parsed. * @returns {Object} * @api public */ function querystring(query) { var parser = /([^=?&]+)=([^&]*)/g , result = {} , part; // // Little nifty parsing hack, leverage the fact that RegExp.exec increments // the lastIndex property so we can continue executing this loop until we've // parsed all results. // for (; part = parser.exec(query); result[decodeURIComponent(part[1])] = decodeURIComponent(part[2]) ); return result; } /** * Transform a query string to an object. * * @param {Object} obj Object that should be transformed. * @param {String} prefix Optional prefix. * @returns {String} * @api public */ function querystringify(obj, prefix) { prefix = prefix || ''; var pairs = []; // // Optionally prefix with a '?' if needed // if ('string' !== typeof prefix) prefix = '?'; for (var key in obj) { if (has.call(obj, key)) { pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key])); } } return pairs.length ? prefix + pairs.join('&') : ''; } // // Expose the module. // exports.stringify = querystringify; exports.parse = querystring; querystringify-0.0.3/package.json000066400000000000000000000020671252017021400171030ustar00rootroot00000000000000{ "name": "querystringify", "version": "0.0.3", "description": "Querystringify - Small, simple but powerful query string parser.", "main": "index.js", "scripts": { "test": "mocha --reporter spec --ui bdd test.js", "watch": "mocha --watch --reporter spec --ui bdd test.js", "coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter spec --ui bdd test.js", "test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --ui bdd test.js" }, "repository": { "type": "git", "url": "https://github.com/unshiftio/querystringify" }, "keywords": [ "query", "string", "query-string", "querystring", "qs", "stringify", "parse", "decode", "encode" ], "author": "Arnout Kazemier", "license": "MIT", "bugs": { "url": "https://github.com/unshiftio/querystringify/issues" }, "homepage": "https://github.com/unshiftio/querystringify", "devDependencies": { "assume": "1.2.x", "istanbul": "0.3.x", "mocha": "2.2.x", "pre-commit": "1.0.x" } } querystringify-0.0.3/test.js000066400000000000000000000030611252017021400161250ustar00rootroot00000000000000describe('querystringify', function () { 'use strict'; var assume = require('assume') , qs = require('./'); describe('#stringify', function () { var obj = { foo: 'bar', bar: 'foo' }; it('is exposed as method', function () { assume(qs.stringify).is.a('function'); }); it('transforms an object', function () { assume(qs.stringify(obj)).equals('foo=bar&bar=foo'); }); it('can optionally prefix', function () { assume(qs.stringify(obj, true)).equals('?foo=bar&bar=foo'); }); it('can prefix with custom things', function () { assume(qs.stringify(obj, '&')).equals('&foo=bar&bar=foo'); }); it('doesnt prefix empty query strings', function () { assume(qs.stringify({}, true)).equals(''); assume(qs.stringify({})).equals(''); }); it('works with nulled objects', function () { var obj = Object.create(null); obj.foo='bar'; assume(qs.stringify(obj)).equals('foo=bar'); }); }); describe('#parse', function () { it('is exposed as method', function () { assume(qs.parse).is.a('function'); }); it('will parse a querystring to an object', function () { var obj = qs.parse('foo=bar'); assume(obj).is.a('object'); assume(obj.foo).equals('bar'); }); it('will also work if querystring is prefixed with ?', function () { var obj = qs.parse('?foo=bar&shizzle=mynizzle'); assume(obj).is.a('object'); assume(obj.foo).equals('bar'); assume(obj.shizzle).equals('mynizzle'); }); }); });