MCPcopy Create free account
hub / github.com/sql-js/sql.js / ajaxConvert

Function ajaxConvert

documentation/javascript/application.js:8824–8907  ·  view source on GitHub ↗
( s, response )

Source from the content-addressed store, hash-verified

8822
8823// Chain conversions given the request and the original response
8824function ajaxConvert( s, response ) {
8825
8826 var conv, conv2, current, tmp,
8827 // Work with a copy of dataTypes in case we need to modify it for conversion
8828 dataTypes = s.dataTypes.slice(),
8829 prev = dataTypes[ 0 ],
8830 converters = {},
8831 i = 0;
8832
8833 // Apply the dataFilter if provided
8834 if ( s.dataFilter ) {
8835 response = s.dataFilter( response, s.dataType );
8836 }
8837
8838 // Create converters map with lowercased keys
8839 if ( dataTypes[ 1 ] ) {
8840 for ( conv in s.converters ) {
8841 converters[ conv.toLowerCase() ] = s.converters[ conv ];
8842 }
8843 }
8844
8845 // Convert to each sequential dataType, tolerating list modification
8846 for ( ; (current = dataTypes[++i]); ) {
8847
8848 // There's only work to do if current dataType is non-auto
8849 if ( current !== "*" ) {
8850
8851 // Convert response if prev dataType is non-auto and differs from current
8852 if ( prev !== "*" && prev !== current ) {
8853
8854 // Seek a direct converter
8855 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
8856
8857 // If none found, seek a pair
8858 if ( !conv ) {
8859 for ( conv2 in converters ) {
8860
8861 // If conv2 outputs current
8862 tmp = conv2.split(" ");
8863 if ( tmp[ 1 ] === current ) {
8864
8865 // If prev can be converted to accepted input
8866 conv = converters[ prev + " " + tmp[ 0 ] ] ||
8867 converters[ "* " + tmp[ 0 ] ];
8868 if ( conv ) {
8869 // Condense equivalence converters
8870 if ( conv === true ) {
8871 conv = converters[ conv2 ];
8872
8873 // Otherwise, insert the intermediate dataType
8874 } else if ( converters[ conv2 ] !== true ) {
8875 current = tmp[ 0 ];
8876 dataTypes.splice( i--, 0, current );
8877 }
8878
8879 break;
8880 }
8881 }

Callers 1

doneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…