ts-prime
Version:
A utility library for JavaScript and Typescript.
24 lines (23 loc) • 918 B
JavaScript
import { toDate, toFloat, toInt } from './parse';
test('should parse float', function () {
expect(toFloat('5.5')).toBe(5.5);
expect(toFloat('zcx5.5')).toBe(undefined);
expect(toFloat('zcx5.5', 0)).toBe(0);
expect(toFloat(22, 0)).toBe(22);
expect(toFloat(undefined, 0)).toBe(0);
expect(toFloat(undefined)).toBe(undefined);
});
test('should parse int', function () {
expect(toInt('5.5')).toBe(5);
expect(toInt('zcx5.5')).toBe(undefined);
expect(toInt('zcx5.5', 0)).toBe(0);
expect(toInt(22.2, 0)).toBe(22);
expect(toInt(undefined, 0)).toBe(0);
expect(toInt(undefined, 12.3)).toBe(12);
expect(toInt(undefined)).toBe(undefined);
});
test('should parse date', function () {
var _a;
expect(toDate('asd')).toBe(undefined);
expect((_a = toDate('2015-03-25')) === null || _a === void 0 ? void 0 : _a.toISOString()).toBe(new Date('2015-03-25').toISOString());
});