8 lines
215 B
TypeScript
8 lines
215 B
TypeScript
const toNumber: (
|
|
value: unknown,
|
|
parser?: 'parseFloat' | 'parseInt',
|
|
) => number = (value, parser = 'parseInt') =>
|
|
typeof value === 'number' ? value : Number[parser](String(value));
|
|
|
|
export default toNumber;
|