encode.js
/**
 * Encode the speceifed key in the object
 *
 * @param {string} key The key name
 * @param {any} data The data of the key
 * @param {string[]} keyValueArray The array to store the key value string
 * @param {boolean} keepArrayIndex Whether to keep array index
 */
Encode the speceifed key in the object
@param {string} key The key name
@param {any} data The data of the key
@param {string[]} keyValueArray The array to store the key value string
@param {boolean} keepArrayIndex Whether to keep array index
Encode the speceifed key in the object @param { string } key The key name @param { any } data The data of the key @param { string [] } keyValueArray The array to store the key value string @param { boolean } keepArrayIndex Whether to keep array index
function encodeKey(key, data, keyValueArray, keepArrayIndex) {
    var prop;
    var index;
    var length;
    var value;
    var subKey;
    if ( isObject(data) ) {
        for ( prop in data ) {
            if ( hasOwn.call(data, prop) ) {
                value = data[prop];
                subKey = key + '[' + prop + ']';
                encodeKey(subKey, value, keyValueArray, keepArrayIndex);
            }
        }
    } else if ( isArray(data) ) {
        index = 0;
        length = data.length;
        while (index < length) {
            value = data[index];
            if ( keepArrayIndex || isArray(value) || isObject(value) ) {
                subKey = key + '[' + index + ']';
            } else {
                subKey = key + '[]';
            }
            encodeKey(subKey, value, keyValueArray, keepArrayIndex);
            index += 1;
        }
    } else {
        key = encodeURIComponent(key);
        if (data === null) {
            value = key;
        } else {
            if (data === undefined) {
                data = '';
            } else if (typeof data !== 'string') {
                data = '' + data;
            }
            value = key + '=' + encodeURIComponent(data);
        }
        keyValueArray.push(value);
    }
}
function encodeKey ( key , data , keyValueArray , keepArrayIndex ) { var prop ; var index ; var length ; var value ; var subKey ; if ( isObject ( data ) ) { for ( prop in data ) { if ( hasOwn . call ( data , prop ) ) { value = data [ prop ] ; subKey = key + '[' + prop + ']' ; encodeKey ( subKey , value , keyValueArray , keepArrayIndex ) ; } } } else if ( isArray ( data ) ) { index = 0 ; length = data . length ; while ( index < length ) { value = data [ index ] ; if ( keepArrayIndex || isArray ( value ) || isObject ( value ) ) { subKey = key + '[' + index + ']' ; } else { subKey = key + '[]' ; } encodeKey ( subKey , value , keyValueArray , keepArrayIndex ) ; index += 1 ; } } else { key = encodeURIComponent ( key ) ; if ( data === null ) { value = key ; } else { if ( data === undefined ) { data = '' ; } else if ( typeof data !== 'string' ) { data = '' + data ; } value = key + '=' + encodeURIComponent ( data ) ; } keyValueArray . push ( value ) ; } }
Encode the speceifed key in the object
 @param {string} key The key name
 @param {any} data The data of the key
 @param {string[]} keyValueArray The array to store the key value string
 @param {boolean} keepArrayIndex Whether to keep array index
Encode the speceifed key in the object @param { string } key The key name @param { any } data The data of the key @param { string [] } keyValueArray The array to store the key value string @param { boolean } keepArrayIndex Whether to keep array index
// if data is null, no `=` is appended // if data is undefined, treat it as empty string // make sure that data is string