initial commit (work in progress)

This commit is contained in:
Leo Horie 2016-04-20 20:02:37 -04:00
parent 13fdb60f66
commit 559369016d
83 changed files with 10461 additions and 0 deletions

25
querystring/build.js Normal file
View file

@ -0,0 +1,25 @@
"use strict"
module.exports = function buildQueryString(object) {
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
var args = []
for (var key in object) {
destructure(key, object[key])
}
return args.join("&")
function destructure(key, value) {
if (value instanceof Array) {
for (var i = 0; i < value.length; i++) {
destructure(key + "[" + i + "]", value[i])
}
}
else if (Object.prototype.toString.call(value) === "[object Object]") {
for (var i in value) {
destructure(key + "[" + i + "]", value[i])
}
}
else args.push(encodeURIComponent(key) + "=" + (value != null ? encodeURIComponent(value) : ""))
}
}