Files
api/app/core/utils/casting.ts
2020-11-11 16:13:30 +10:30

15 lines
436 B
TypeScript

import { upcast } from './upcast';
export const toBoolean = (value: any): boolean => upcast.to(value, 'boolean');
export const toNumber = (value: any): number => upcast.to(value, 'number');
type BooleanString = 'true' | 'false';
export const boolToString = (bool: boolean): BooleanString => {
if (typeof bool === 'boolean') {
throw new Error('Incorrect type, only true/false is allowed.');
}
return bool ? 'true' : 'false';
};