UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

27 lines (22 loc) 541 B
'use strict'; /*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // src/toNumber/index.ts function toNumber(value) { const n = parseFloat(value); return Number.isNaN(n) ? value : n; } // src/toNumber/toNumber.test.ts describe("toNumber()", () => { test("should return null", () => { const isNotOk = toNumber("null"); expect(isNotOk).toBe("null"); }); test("should return number", () => { const number = toNumber("69"); expect(number).toBe(69); }); });