watcher-ts/packages/util/src/index.ts

33 lines
664 B
TypeScript
Raw Normal View History

//
// Copyright 2021 Vulcanize, Inc.
//
import Decimal from 'decimal.js';
import { ValueTransformer } from 'typeorm';
/**
* Method to wait for specified time.
* @param time Time to wait in milliseconds
*/
export const wait = async (time: number): Promise<void> => new Promise(resolve => setTimeout(resolve, time));
/**
* Transformer used by typeorm entity for Decimal type fields
*/
export const decimalTransformer: ValueTransformer = {
to: (value?: Decimal) => {
if (value) {
return value.toString();
}
return value;
},
from: (value?: string) => {
if (value) {
return new Decimal(value);
}
return value;
}
};