decode.js
/**
 * Decode the specefied key
 *
 * @param {Object.<string, string>} object The object to hold the decoded data
 * @param {Object.<string, *>} cache The object to hold cache data
 * @param {string} key The key name to decode
 * @param {any} value The value to decode
 */
Decode the specefied key
@param {Object.} object The object to hold the decoded data
@param {Object.} cache The object to hold cache data
@param {string} key The key name to decode
@param {any} value The value to decode
Decode the specefied key @param { Object . } object The object to hold the decoded data @param { Object . } cache The object to hold cache data @param { string } key The key name to decode @param { any } value The value to decode
function decodeKey(object, cache, key, value) {
    var rBracket = /\[([^\[]*?)?\]$/;
    var rIndex = /(^0$)|(^[1-9]\d*$)/;
    var indexOrKeyOrEmpty;
    var parentKey;
    var arrayOrObject;
    var keyIsIndex;
    var keyIsEmpty;
    var valueIsInArray;
    var dataArray;
    var length;
    if ( rBracket.test(key) ) {
        indexOrKeyOrEmpty = RegExp.$1;
        parentKey = key.replace(rBracket, '');
        arrayOrObject = cache[parentKey];
        keyIsIndex = rIndex.test(indexOrKeyOrEmpty);
        keyIsEmpty = indexOrKeyOrEmpty === '';
        valueIsInArray = keyIsIndex || keyIsEmpty;
        if (arrayOrObject) {
            if ( (! valueIsInArray) && isArray(arrayOrObject) ) {
                dataArray = arrayOrObject;
                length = dataArray.length;
                arrayOrObject = {};
                while (length--) {
                    if (arrayOrObject[length] !== undefined) {
                        arrayOrObject[length] = dataArray[length];
                    }
                }
            }
        } else {
            arrayOrObject = valueIsInArray ? [] : {};
        }
        if ( keyIsEmpty && isArray(arrayOrObject) ) {
            arrayOrObject.push(value);
        } else {
            arrayOrObject[indexOrKeyOrEmpty] = value;
        }
        cache[parentKey] = arrayOrObject;
        decodeKey(object, cache, parentKey, arrayOrObject);
    } else {
        object[key] = value;
    }
}
function decodeKey ( object , cache , key , value ) { var rBracket = / \[([^\[]*?)?\]$ / ; var rIndex = / (^0$)|(^[1-9]\d*$) / ; var indexOrKeyOrEmpty ; var parentKey ; var arrayOrObject ; var keyIsIndex ; var keyIsEmpty ; var valueIsInArray ; var dataArray ; var length ; if ( rBracket . test ( key ) ) { indexOrKeyOrEmpty = RegExp . $1 ; parentKey = key . replace ( rBracket , '' ) ; arrayOrObject = cache [ parentKey ] ; keyIsIndex = rIndex . test ( indexOrKeyOrEmpty ) ; keyIsEmpty = indexOrKeyOrEmpty === '' ; valueIsInArray = keyIsIndex || keyIsEmpty ; if ( arrayOrObject ) { if ( ( ! valueIsInArray ) && isArray ( arrayOrObject ) ) { dataArray = arrayOrObject ; length = dataArray . length ; arrayOrObject = { } ; while ( length -- ) { if ( arrayOrObject [ length ] !== undefined ) { arrayOrObject [ length ] = dataArray [ length ] ; } } } } else { arrayOrObject = valueIsInArray ? [ ] : { } ; } if ( keyIsEmpty && isArray ( arrayOrObject ) ) { arrayOrObject . push ( value ) ; } else { arrayOrObject [ indexOrKeyOrEmpty ] = value ; } cache [ parentKey ] = arrayOrObject ; decodeKey ( object , cache , parentKey , arrayOrObject ) ; } else { object [ key ] = value ; } }
Decode the specefied key
 @param {Object.<string, string>} object The object to hold the decoded data
 @param {Object.<string, *>} cache The object to hold cache data
 @param {string} key The key name to decode
 @param {any} value The value to decode
Decode the specefied key @param { Object . <string string > } object The object to hold the decoded data @param { Object . <string * > } cache The object to hold cache data @param { string } key The key name to decode @param { any } value The value to decode
// check whether key is something like `person[name]` or `colors[]` or // `colors[1]` // convert the array to object // arrayOrObject is array or object here