When parsing text files, like the ones coming out fromm scientific instruments, it is often useful to convert the obtained strings to their corresponding types.
Indeed when you parse the file while all the fields are text some of them represents in fact numbers or booleans.
This package will try to make the conversion for you using the following rules:
Number(string)) does not yield to NaN will be converted to numberThis package was optimized for speed and seems to work pretty well. Please don't hesitate to submit bug reports or contribute.
$ npm i dynamic-typing
import { parseString } from 'dynamic-typing';
const result = parseString('0x100');
// result is the number 256
More examples:
parseString('') ➡ ''parseString(' ') ➡ ' 'parseString('.') ➡ '.'parseString('0.') ➡ 0parseString('0.0') ➡ 0parseString('abc') ➡ 'abc'parseString('True') ➡ trueparseString('false') ➡ falseparseString('0') ➡ 0parseString('123') ➡ 123parseString('123.456') ➡ 123.456parseString('12e3') ➡ 12000parseString('0x10') ➡ 16parseString('0b10') ➡ 2