Sha256: ce1d3ecfb8f2ab5d7e3d6d15d2a2f6564360068e301f79750f588ee13bff1471
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
Contents
var typecast = require('../string/typecast'); var isString = require('../lang/isString'); var isArray = require('../lang/isArray'); var hasOwn = require('../object/hasOwn'); /** * Decode query string into an object of keys => vals. */ function decode(queryStr, shouldTypecast) { var queryArr = (queryStr || '').replace('?', '').split('&'), count = -1, length = queryArr.length, obj = {}, item, pValue, pName, toSet; while (++count < length) { item = queryArr[count].split('='); pName = item[0]; if (!pName || !pName.length){ continue; } pValue = shouldTypecast === false ? item[1] : typecast(item[1]); toSet = isString(pValue) ? decodeURIComponent(pValue) : pValue; if (hasOwn(obj,pName)){ if(isArray(obj[pName])){ obj[pName].push(toSet); } else { obj[pName] = [obj[pName],toSet]; } } else { obj[pName] = toSet; } } return obj; } module.exports = decode;
Version data entries
7 entries across 7 versions & 1 rubygems