lion/packages/ajax/src/transformers.js
Thomas Allmer ec8da8f12c feat: release inital public lion version
Co-authored-by: Mikhail Bashkirov <mikhail.bashkirov@ing.com>
Co-authored-by: Thijs Louisse <thijs.louisse@ing.com>
Co-authored-by: Joren Broekema <joren.broekema@ing.com>
Co-authored-by: Gerjan van Geest <gerjan.van.geest@ing.com>
Co-authored-by: Erik Kroes <erik.kroes@ing.com>
Co-authored-by: Lars den Bakker <lars.den.bakker@ing.com>
2019-04-26 10:37:57 +02:00

16 lines
414 B
JavaScript

export function jsonPrefixTransformerFactory(prefix) {
return data => {
let result = data;
if (typeof result === 'string') {
if (prefix.length > 0 && result.indexOf(prefix) === 0) {
result = result.substring(prefix.length);
}
try {
result = JSON.parse(result);
} catch (e) {
/* ignore to allow non-JSON responses */
}
}
return result;
};
}