index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { ClassTransformer } from './ClassTransformer';
  2. export { ClassTransformer } from './ClassTransformer';
  3. export * from './decorators';
  4. export * from './interfaces';
  5. export * from './enums';
  6. const classTransformer = new ClassTransformer();
  7. export function classToPlain(object, options) {
  8. return classTransformer.instanceToPlain(object, options);
  9. }
  10. export function instanceToPlain(object, options) {
  11. return classTransformer.instanceToPlain(object, options);
  12. }
  13. export function classToPlainFromExist(object, plainObject, options) {
  14. return classTransformer.classToPlainFromExist(object, plainObject, options);
  15. }
  16. export function plainToClass(cls, plain, options) {
  17. return classTransformer.plainToInstance(cls, plain, options);
  18. }
  19. export function plainToInstance(cls, plain, options) {
  20. return classTransformer.plainToInstance(cls, plain, options);
  21. }
  22. export function plainToClassFromExist(clsObject, plain, options) {
  23. return classTransformer.plainToClassFromExist(clsObject, plain, options);
  24. }
  25. export function instanceToInstance(object, options) {
  26. return classTransformer.instanceToInstance(object, options);
  27. }
  28. export function classToClassFromExist(object, fromObject, options) {
  29. return classTransformer.classToClassFromExist(object, fromObject, options);
  30. }
  31. export function serialize(object, options) {
  32. return classTransformer.serialize(object, options);
  33. }
  34. /**
  35. * Deserializes given JSON string to a object of the given class.
  36. *
  37. * @deprecated This function is being removed. Please use the following instead:
  38. * ```
  39. * instanceToClass(cls, JSON.parse(json), options)
  40. * ```
  41. */
  42. export function deserialize(cls, json, options) {
  43. return classTransformer.deserialize(cls, json, options);
  44. }
  45. /**
  46. * Deserializes given JSON string to an array of objects of the given class.
  47. *
  48. * @deprecated This function is being removed. Please use the following instead:
  49. * ```
  50. * JSON.parse(json).map(value => instanceToClass(cls, value, options))
  51. * ```
  52. *
  53. */
  54. export function deserializeArray(cls, json, options) {
  55. return classTransformer.deserializeArray(cls, json, options);
  56. }
  57. //# sourceMappingURL=index.js.map