lenye_base
Version:
基础方法
20 lines (16 loc) • 331 B
JavaScript
import isTypeof from './is_typeof.js';
var toJson = res => {
if (!res) return null;
if (typeof res === 'string') {
try {
return JSON.parse(res);
} catch (e) {
return res;
}
} else if (isTypeof(res.json, 'function')) {
return res.json();
} else {
return res;
}
};
export default toJson;