Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tj/node-querystring
base: 75574168f7
...
head fork: tj/node-querystring
compare: f59b25829d
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
5 History.md
@@ -1,4 +1,9 @@
+0.5.0 / 2012-05-04
+==================
+
+ * Added component support
+
0.4.2 / 2012-02-08
==================
View
3  Makefile
@@ -1,4 +1,7 @@
+test/browser/qs.js: querystring.js
+ component build package.json test/browser/qs
+
querystring.js: lib/head.js lib/querystring.js lib/tail.js
cat $^ > $@
View
2  lib/head.js
@@ -1 +1 @@
-(function(exports){
+;(function(){
View
12 lib/querystring.js
@@ -1,16 +1,4 @@
-/*!
- * querystring
- * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
- * MIT Licensed
- */
-
-/**
- * Library version.
- */
-
-exports.version = '0.4.2';
-
/**
* Object#toString() ref for stringify().
*/
View
2  lib/tail.js
@@ -1 +1 @@
-})('undefined' == typeof exports ? qs = {} : exports);
+})();
View
7 package.json
@@ -1,7 +1,7 @@
{
"name": "qs",
"description": "querystring parser",
- "version": "0.4.2",
+ "version": "0.5.0",
"repository": {
"type" : "git",
"url" : "git://github.com/visionmedia/node-querystring.git"
@@ -10,6 +10,11 @@
"mocha": "*"
, "expect.js": "*"
},
+ "component": {
+ "scripts": {
+ "querystring": "querystring.js"
+ }
+ },
"author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
"main": "index",
"engines": { "node": "*" }
View
15 querystring.js
@@ -1,15 +1,4 @@
-(function(exports){
-/*!
- * querystring
- * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
- * MIT Licensed
- */
-
-/**
- * Library version.
- */
-
-exports.version = '0.4.2';
+;(function(){
/**
* Object#toString() ref for stringify().
@@ -262,4 +251,4 @@ function lastBraceInKey(str) {
if ('=' == c && !brace) return i;
}
}
-})('undefined' == typeof exports ? qs = {} : exports);
+})();
View
2  test/browser/index.html
@@ -7,7 +7,7 @@
<script src="expect.js"></script>
<script src="mocha.js"></script>
<script>mocha.setup('bdd')</script>
- <script src="../../querystring.js"></script>
+ <script src="qs.js"></script>
<script src="../parse.js"></script>
<script src="../stringify.js"></script>
<script>onload = mocha.run;</script>
View
0  test/browser/qs.css
No changes.
View
351 test/browser/qs.js
@@ -0,0 +1,351 @@
+
+/**
+ * Require the given path.
+ *
+ * @param {String} path
+ * @return {Object} exports
+ * @api public
+ */
+
+function require(p, parent){
+ var path = require.resolve(p)
+ , mod = require.modules[path];
+ if (!mod) throw new Error('failed to require "' + p + '" in ' + parent);
+ if (!mod.exports) {
+ mod.exports = {};
+ mod.client = true;
+ mod.call(mod.exports, mod, mod.exports, require.relative(path));
+ }
+ return mod.exports;
+}
+
+/**
+ * Registered modules.
+ */
+
+require.modules = {};
+
+/**
+ * Resolve `path`.
+ *
+ * @param {String} path
+ * @return {Object} module
+ * @api public
+ */
+
+require.resolve = function(path){
+ var orig = path
+ , reg = path + '.js'
+ , index = path + '/index.js';
+ return require.modules[reg] && reg
+ || require.modules[index] && index
+ || orig;
+};
+
+/**
+ * Register module at `path` with callback `fn`.
+ *
+ * @param {String} path
+ * @param {Function} fn
+ * @api public
+ */
+
+require.register = function(path, fn){
+ require.modules[path] = fn;
+};
+
+/**
+ * Defines and executes anonymous module immediately, while preserving relative
+ * paths.
+ *
+ * @param {String} path
+ * @param {Function} require ref
+ * @api public
+ */
+
+require.exec = function (path, fn) {
+ fn.call(window, require.relative(path));
+};
+
+/**
+ * Return a require function relative to the `parent` path.
+ *
+ * @param {String} parent
+ * @return {Function}
+ * @api private
+ */
+
+require.relative = function(parent) {
+ return function(p){
+ if ('.' != p[0]) return require(p);
+
+ var path = parent.split('/')
+ , segs = p.split('/');
+ path.pop();
+
+ for (var i = 0; i < segs.length; i++) {
+ var seg = segs[i];
+ if ('..' == seg) path.pop();
+ else if ('.' != seg) path.push(seg);
+ }
+
+ return require(path.join('/'), parent);
+ };
+};
+// component qs: querystring
+require.register("querystring", function(module, exports, require){
+;(function(){
+
+/**
+ * Object#toString() ref for stringify().
+ */
+
+var toString = Object.prototype.toString;
+
+/**
+ * Cache non-integer test regexp.
+ */
+
+var isint = /^[0-9]+$/;
+
+function promote(parent, key) {
+ if (parent[key].length == 0) return parent[key] = {};
+ var t = {};
+ for (var i in parent[key]) t[i] = parent[key][i];
+ parent[key] = t;
+ return t;
+}
+
+function parse(parts, parent, key, val) {
+ var part = parts.shift();
+ // end
+ if (!part) {
+ if (Array.isArray(parent[key])) {
+ parent[key].push(val);
+ } else if ('object' == typeof parent[key]) {
+ parent[key] = val;
+ } else if ('undefined' == typeof parent[key]) {
+ parent[key] = val;
+ } else {
+ parent[key] = [parent[key], val];
+ }
+ // array
+ } else {
+ var obj = parent[key] = parent[key] || [];
+ if (']' == part) {
+ if (Array.isArray(obj)) {
+ if ('' != val) obj.push(val);
+ } else if ('object' == typeof obj) {
+ obj[Object.keys(obj).length] = val;
+ } else {
+ obj = parent[key] = [parent[key], val];
+ }
+ // prop
+ } else if (~part.indexOf(']')) {
+ part = part.substr(0, part.length - 1);
+ if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
+ parse(parts, obj, part, val);
+ // key
+ } else {
+ if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
+ parse(parts, obj, part, val);
+ }
+ }
+}
+
+/**
+ * Merge parent key/val pair.
+ */
+
+function merge(parent, key, val){
+ if (~key.indexOf(']')) {
+ var parts = key.split('[')
+ , len = parts.length
+ , last = len - 1;
+ parse(parts, parent, 'base', val);
+ // optimize
+ } else {
+ if (!isint.test(key) && Array.isArray(parent.base)) {
+ var t = {};
+ for (var k in parent.base) t[k] = parent.base[k];
+ parent.base = t;
+ }
+ set(parent.base, key, val);
+ }
+
+ return parent;
+}
+
+/**
+ * Parse the given obj.
+ */
+
+function parseObject(obj){
+ var ret = { base: {} };
+ Object.keys(obj).forEach(function(name){
+ merge(ret, name, obj[name]);
+ });
+ return ret.base;
+}
+
+/**
+ * Parse the given str.
+ */
+
+function parseString(str){
+ return String(str)
+ .split('&')
+ .reduce(function(ret, pair){
+ try{
+ pair = decodeURIComponent(pair.replace(/\+/g, ' '));
+ } catch(e) {
+ // ignore
+ }
+
+ var eql = pair.indexOf('=')
+ , brace = lastBraceInKey(pair)
+ , key = pair.substr(0, brace || eql)
+ , val = pair.substr(brace || eql, pair.length)
+ , val = val.substr(val.indexOf('=') + 1, val.length);
+
+ // ?foo
+ if ('' == key) key = pair, val = '';
+
+ return merge(ret, key, val);
+ }, { base: {} }).base;
+}
+
+/**
+ * Parse the given query `str` or `obj`, returning an object.
+ *
+ * @param {String} str | {Object} obj
+ * @return {Object}
+ * @api public
+ */
+
+exports.parse = function(str){
+ if (null == str || '' == str) return {};
+ return 'object' == typeof str
+ ? parseObject(str)
+ : parseString(str);
+};
+
+/**
+ * Turn the given `obj` into a query string
+ *
+ * @param {Object} obj
+ * @return {String}
+ * @api public
+ */
+
+var stringify = exports.stringify = function(obj, prefix) {
+ if (Array.isArray(obj)) {
+ return stringifyArray(obj, prefix);
+ } else if ('[object Object]' == toString.call(obj)) {
+ return stringifyObject(obj, prefix);
+ } else if ('string' == typeof obj) {
+ return stringifyString(obj, prefix);
+ } else {
+ return prefix + '=' + obj;
+ }
+};
+
+/**
+ * Stringify the given `str`.
+ *
+ * @param {String} str
+ * @param {String} prefix
+ * @return {String}
+ * @api private
+ */
+
+function stringifyString(str, prefix) {
+ if (!prefix) throw new TypeError('stringify expects an object');
+ return prefix + '=' + encodeURIComponent(str);
+}
+
+/**
+ * Stringify the given `arr`.
+ *
+ * @param {Array} arr
+ * @param {String} prefix
+ * @return {String}
+ * @api private
+ */
+
+function stringifyArray(arr, prefix) {
+ var ret = [];
+ if (!prefix) throw new TypeError('stringify expects an object');
+ for (var i = 0; i < arr.length; i++) {
+ ret.push(stringify(arr[i], prefix + '['+i+']'));
+ }
+ return ret.join('&');
+}
+
+/**
+ * Stringify the given `obj`.
+ *
+ * @param {Object} obj
+ * @param {String} prefix
+ * @return {String}
+ * @api private
+ */
+
+function stringifyObject(obj, prefix) {
+ var ret = []
+ , keys = Object.keys(obj)
+ , key;
+
+ for (var i = 0, len = keys.length; i < len; ++i) {
+ key = keys[i];
+ ret.push(stringify(obj[key], prefix
+ ? prefix + '[' + encodeURIComponent(key) + ']'
+ : encodeURIComponent(key)));
+ }
+
+ return ret.join('&');
+}
+
+/**
+ * Set `obj`'s `key` to `val` respecting
+ * the weird and wonderful syntax of a qs,
+ * where "foo=bar&foo=baz" becomes an array.
+ *
+ * @param {Object} obj
+ * @param {String} key
+ * @param {String} val
+ * @api private
+ */
+
+function set(obj, key, val) {
+ var v = obj[key];
+ if (undefined === v) {
+ obj[key] = val;
+ } else if (Array.isArray(v)) {
+ v.push(val);
+ } else {
+ obj[key] = [v, val];
+ }
+}
+
+/**
+ * Locate last brace in `str` within the key.
+ *
+ * @param {String} str
+ * @return {Number}
+ * @api private
+ */
+
+function lastBraceInKey(str) {
+ var len = str.length
+ , brace
+ , c;
+ for (var i = 0; i < len; ++i) {
+ c = str[i];
+ if (']' == c) brace = false;
+ if ('[' == c) brace = true;
+ if ('=' == c && !brace) return i;
+ }
+}
+})();
+});
View
4 test/parse.js
@@ -1,5 +1,7 @@
-if ('function' == typeof require) {
+if (require.register) {
+ var qs = require('querystring');
+} else {
var qs = require('../')
, expect = require('expect.js');
}
View
4 test/stringify.js
@@ -1,5 +1,7 @@
-if ('function' == typeof require) {
+if (require.register) {
+ var qs = require('querystring');
+} else {
var qs = require('../')
, expect = require('expect.js');
}

No commit comments for this range

Something went wrong with that request. Please try again.