trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
47 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransformerUtil = void 0;
const class_transformer_1 = require("class-transformer");
const _entities_1 = require("../entities/core-entities/index.js");
class TransformerUtil {
/**
* Deserialize a plain object to an instance of the
* specified class.
* @param plainObject The plain object to deserialize
* @param targetClass The class to instantiate with the
* properties set according to the plain object provided
* @returns An instance of the specified class, TEntity,
* with the properties set according to the plain object
* provided
*/
static transform(plainObject, targetClass) {
try {
return (0, class_transformer_1.plainToInstance)(targetClass, plainObject, {
excludeExtraneousValues: true, // Change this to false if you want to keep all properties
exposeUnsetFields: false,
});
}
catch (err) {
throw new _entities_1.ConversionError(targetClass.name, err);
}
}
/**
* Deserialize an array of plain objects to an array of
* instances of the specified class.
* @param plainArray The array of plain objects to
* deserialize
* @param targetClass The class to instantiate with the
* properties set according to the plain objects provided
* @returns An array of instances of the specified class,
* TEntity, with the properties set according to the plain
* objects provided
*/
static transformArray(plainArray, targetClass) {
return (0, class_transformer_1.plainToInstance)(targetClass, plainArray, {
excludeExtraneousValues: true, // Change this to false if you want to keep all properties
exposeUnsetFields: false,
});
}
}
exports.TransformerUtil = TransformerUtil;
//# sourceMappingURL=transformer-util.js.map