class-transformer#TransformationType TypeScript Examples

The following examples show how to use class-transformer#TransformationType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: transform-big-number.ts    From etherspot-sdk with MIT License 6 votes vote down vote up
/**
 * @ignore
 */
export function TransformBigNumber(): Function {
  return Transform((params) => {
    const { type, value } = params;

    let result: any = null;

    switch (type) {
      case TransformationType.PLAIN_TO_CLASS:
        result = value ? BigNumber.from(value) : null;
        break;

      case TransformationType.CLASS_TO_CLASS:
        result = value;
        break;

      case TransformationType.CLASS_TO_PLAIN:
        result = isBigNumber(value) ? BigNumber.from(value).toHexString() : '0x00';
        break;
    }

    return result;
  });
}