ts-prime
Version:
A utility library for JavaScript and Typescript.
26 lines (25 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var parse_1 = require("./parse");
test('should parse float', function () {
expect(parse_1.toFloat('5.5')).toBe(5.5);
expect(parse_1.toFloat('zcx5.5')).toBe(undefined);
expect(parse_1.toFloat('zcx5.5', 0)).toBe(0);
expect(parse_1.toFloat(22, 0)).toBe(22);
expect(parse_1.toFloat(undefined, 0)).toBe(0);
expect(parse_1.toFloat(undefined)).toBe(undefined);
});
test('should parse int', function () {
expect(parse_1.toInt('5.5')).toBe(5);
expect(parse_1.toInt('zcx5.5')).toBe(undefined);
expect(parse_1.toInt('zcx5.5', 0)).toBe(0);
expect(parse_1.toInt(22.2, 0)).toBe(22);
expect(parse_1.toInt(undefined, 0)).toBe(0);
expect(parse_1.toInt(undefined, 12.3)).toBe(12);
expect(parse_1.toInt(undefined)).toBe(undefined);
});
test('should parse date', function () {
var _a;
expect(parse_1.toDate('asd')).toBe(undefined);
expect((_a = parse_1.toDate('2015-03-25')) === null || _a === void 0 ? void 0 : _a.toISOString()).toBe(new Date('2015-03-25').toISOString());
});