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

Version Path
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js
entangled-0.0.12 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js
entangled-0.0.11 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js
entangled-0.0.10 spec/dummy/public/node_modules/bower/node_modules/mout/queryString/decode.js