@odata2ts/converter-v2-to-v4
Version:
A set of odata2ts compatible converters to convert certain OData V2 types to their V4 analog
38 lines • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToNumberConverter = void 0;
const odata_core_1 = require("@odata2ts/odata-core");
/**
* V2 maps certain number types to string values, while V4 maps all number types to number values.
* This converter converts those V2 string based numbers to JS numbers in order to align with V4.
*
* Since The JS number type is not sufficient to represent all possible Edm.Int64 and Edm.Decimal values,
* V4 also defines a technique, so that those data types can be retrieved as strings.
* Another converter would need to take care of that.
*/
exports.stringToNumberConverter = {
id: "stringToNumberConverter",
from: [
odata_core_1.ODataTypesV2.Byte,
odata_core_1.ODataTypesV2.SByte,
odata_core_1.ODataTypesV2.Single,
odata_core_1.ODataTypesV2.Double,
odata_core_1.ODataTypesV2.Int64,
odata_core_1.ODataTypesV2.Decimal,
],
to: "number",
convertFrom: function (value) {
if (typeof value !== "string") {
return value;
}
const val = Number(value);
return !isNaN(val) ? val : undefined;
},
convertTo: function (value) {
if (typeof value !== "number") {
return value;
}
return !isNaN(value) ? String(value) : undefined;
},
};
//# sourceMappingURL=StringToNumberConverter.js.map