diff options
author | James Lal <james@lightsofapollo.com> | 2013-05-02 14:02:07 -0700 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2013-05-02 14:02:07 -0700 |
commit | c81e925aa6dada192db75dccd4287ab1e9e09ab2 (patch) | |
tree | 5e7e4ee8dcc3cb01d48b4b88ab14039bc50cf034 /lib/caldav/querystring.js | |
parent | 9b6e2c616154f2c20fe6272dca083868c02f98f4 (diff) | |
parent | 8857b80ae0dd7be54d0d731000c9f8edb0434336 (diff) | |
download | jsCalDAV-c81e925aa6dada192db75dccd4287ab1e9e09ab2.tar.gz |
Merge pull request #14 from lightsofapollo/oauth
Bug 867747 - Google OAuth implementation
Diffstat (limited to 'lib/caldav/querystring.js')
-rw-r--r-- | lib/caldav/querystring.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/caldav/querystring.js b/lib/caldav/querystring.js new file mode 100644 index 0000000..bea349a --- /dev/null +++ b/lib/caldav/querystring.js @@ -0,0 +1,82 @@ +// Copyright Joyent, Inc. and other Node 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. + +// Query String Utilities + +(function(module, ns) { + + var QueryString = {}; + + QueryString.escape = function(str) { + return encodeURIComponent(str); + }; + + var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; + } + }; + + + QueryString.stringify = QueryString.encode = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; + } + + if (typeof obj === 'object') { + return Object.keys(obj).map(function(k) { + var ks = QueryString.escape(stringifyPrimitive(k)) + eq; + if (Array.isArray(obj[k])) { + return obj[k].map(function(v) { + return ks + QueryString.escape(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + QueryString.escape(stringifyPrimitive(obj[k])); + } + }).join(sep); + + } + + if (!name) return ''; + return QueryString.escape(stringifyPrimitive(name)) + eq + + QueryString.escape(stringifyPrimitive(obj)); + }; + + module.exports = QueryString; + +}.apply( + this, + (this.Caldav) ? + [Caldav('querystring'), Caldav] : + [module, require('./caldav')] +)); |