lib/converters/v1.0.0/converter-v1-to-v2.js
function (requestV1) {
        var modes = {
                urlencoded: 'urlencoded',
                params: 'formdata',
                raw: 'raw',
                binary: 'file'
            },
            data = {},
            rawModeData,
            dataMode = modes[requestV1.dataMode],
            retainEmpty = this.options.retainEmptyValues;

        // set null body if neither data|rawModeData nor dataMode is set, or if the dataMode is explicitly set to null
        // The explicit null check is added to ensure that body is not set in case the dataMode was set to null by the
        // app, but `data` or `rawModeData` was not empty
        if ((!dataMode && _.isEmpty(requestV1.data) && _.isEmpty(requestV1.rawModeData)) ||
            requestV1.dataMode === null) {
            return retainEmpty ? null : undefined;
        }

        // set `rawModeData` if its a string
        if (_.isString(requestV1.rawModeData)) {
            rawModeData = requestV1.rawModeData;
        }
        // check if `rawModeData` is an array like: ['rawModeData']
        else if (Array.isArray(requestV1.rawModeData) &&
            requestV1.rawModeData.length === 1 &&
            _.isString(requestV1.rawModeData[0])) {
            rawModeData = requestV1.rawModeData[0];
        }

        // set data.mode.
        // if dataMode is not set, infer from data or rawModeData
        // at this point either data or rawModeData is set
        if (dataMode) {
            data.mode = dataMode;
        }
        // set `formdata` if rawModeData is not set and data is an array
        // `data` takes higher precedence over `rawModeData`.
        else if (!rawModeData && Array.isArray(requestV1.data || requestV1.rawModeData)) {
            data.mode = 'formdata';
        }
        // set `raw` mode as default
        else {
            data.mode = 'raw';
        }

        if (data.mode === 'raw') {
            if (rawModeData) {
                data[data.mode] = rawModeData;
            }
            else if (_.isString(requestV1.data)) {
                data[data.mode] = requestV1.data;
            }
            else {
                data[data.mode] = ''; // empty string instead of retainEmpty check to have parity with other modes.
            }
        }
        else if (data.mode === 'file') {
            data[data.mode] = { src: rawModeData }; // rawModeData can be string or undefined.
        }
        else {
            // parse data for formdata or urlencoded data modes.
            // `rawModeData` is checked in case its of type `data`.
            data[data.mode] = parseFormData(requestV1.data || requestV1.rawModeData, retainEmpty);
        }

        if (requestV1.dataDisabled) { data.disabled = true; }
        else if (retainEmpty) { data.disabled = false; }

        return data;
    }
function (requestV1) {
        var modes = {
                urlencoded: 'urlencoded',
                params: 'formdata',
                raw: 'raw',
                binary: 'file'
            },
            data = {},
            rawModeData,
            dataMode = modes[requestV1.dataMode],
            retainEmpty = this.options.retainEmptyValues;

        // set null body if neither data|rawModeData nor dataMode is set, or if the dataMode is explicitly set to null
        // The explicit null check is added to ensure that body is not set in case the dataMode was set to null by the
        // app, but `data` or `rawModeData` was not empty
        if ((!dataMode && _.isEmpty(requestV1.data) && _.isEmpty(requestV1.rawModeData)) ||
            requestV1.dataMode === null) {
            return retainEmpty ? null : undefined;
        }

        // set `rawModeData` if its a string
        if (_.isString(requestV1.rawModeData)) {
            rawModeData = requestV1.rawModeData;
        }
        // check if `rawModeData` is an array like: ['rawModeData']
        else if (Array.isArray(requestV1.rawModeData) &&
            requestV1.rawModeData.length === 1 &&
            _.isString(requestV1.rawModeData[0])) {
            rawModeData = requestV1.rawModeData[0];
        }

        // set data.mode.
        // if dataMode is not set, infer from data or rawModeData
        // at this point either data or rawModeData is set
        if (dataMode) {
            data.mode = dataMode;
        }
        // set `formdata` if rawModeData is not set and data is an array
        // `data` takes higher precedence over `rawModeData`.
        else if (!rawModeData && Array.isArray(requestV1.data || requestV1.rawModeData)) {
            data.mode = 'formdata';
        }
        // set `raw` mode as default
        else {
            data.mode = 'raw';
        }

        if (data.mode === 'raw') {
            if (rawModeData) {
                data[data.mode] = rawModeData;
            }
            else if (_.isString(requestV1.data)) {
                data[data.mode] = requestV1.data;
            }
            else {
                data[data.mode] = ''; // empty string instead of retainEmpty check to have parity with other modes.
            }
        }
        else if (data.mode === 'file') {
            data[data.mode] = { src: rawModeData }; // rawModeData can be string or undefined.
        }
        else {
            // parse data for formdata or urlencoded data modes.
            // `rawModeData` is checked in case its of type `data`.
            data[data.mode] = parseFormData(requestV1.data || requestV1.rawModeData, retainEmpty);
        }

        if (requestV1.dataDisabled) { data.disabled = true; }
        else if (retainEmpty) { data.disabled = false; }

        return data;
    }
function ( requestV1 ) { var modes = { urlencoded : 'urlencoded' , params : 'formdata' , raw : 'raw' , binary : 'file' } , data = { } , rawModeData , dataMode = modes [ requestV1 . dataMode ] , retainEmpty = this . options . retainEmptyValues ; // set null body if neither data|rawModeData nor dataMode is set, or if the dataMode is explicitly set to null // The explicit null check is added to ensure that body is not set in case the dataMode was set to null by the // app, but `data` or `rawModeData` was not empty if ( ( ! dataMode && _ . isEmpty ( requestV1 . data ) && _ . isEmpty ( requestV1 . rawModeData ) ) || requestV1 . dataMode === null ) { return retainEmpty ? null : undefined ; } // set `rawModeData` if its a string if ( _ . isString ( requestV1 . rawModeData ) ) { rawModeData = requestV1 . rawModeData ; } // check if `rawModeData` is an array like: ['rawModeData'] else if ( Array . isArray ( requestV1 . rawModeData ) && requestV1 . rawModeData . length === 1 && _ . isString ( requestV1 . rawModeData [ 0 ] ) ) { rawModeData = requestV1 . rawModeData [ 0 ] ; } // set data.mode. // if dataMode is not set, infer from data or rawModeData // at this point either data or rawModeData is set if ( dataMode ) { data . mode = dataMode ; } // set `formdata` if rawModeData is not set and data is an array // `data` takes higher precedence over `rawModeData`. else if ( ! rawModeData && Array . isArray ( requestV1 . data || requestV1 . rawModeData ) ) { data . mode = 'formdata' ; } // set `raw` mode as default else { data . mode = 'raw' ; } if ( data . mode === 'raw' ) { if ( rawModeData ) { data [ data . mode ] = rawModeData ; } else if ( _ . isString ( requestV1 . data ) ) { data [ data . mode ] = requestV1 . data ; } else { data [ data . mode ] = '' ; // empty string instead of retainEmpty check to have parity with other modes. } } else if ( data . mode === 'file' ) { data [ data . mode ] = { src : rawModeData } ; // rawModeData can be string or undefined. } else { // parse data for formdata or urlencoded data modes. // `rawModeData` is checked in case its of type `data`. data [ data . mode ] = parseFormData ( requestV1 . data || requestV1 . rawModeData , retainEmpty ) ; } if ( requestV1 . dataDisabled ) { data . disabled = true ; } else if ( retainEmpty ) { data . disabled = false ; } return data ; }
Constructs a V2 Request compatible "body" object from a V1 Postman request

@param {Object} requestV1 - The v1 request to extract the body from.
@returns {{mode: *, content: (*|string)}}
Constructs a V2 Request compatible body object from a V1 Postman request