toStr(arg): string
Returns arg
as string (I know, durr).
81% faster than String(arg)
.
62% faster than `${arg}`
.
(Tested at https://jsbench.me/)
Examples
import {toStr} from '@writetome51/to-str';
toStr(1);
// --> '1'
toStr(0.001);
// --> '0.001'
toStr(-0.001);
// --> '-0.001'
toStr(-0);
// --> '0'
toStr(false);
// --> 'false'
toStr([]);
// --> ''
toStr([1, 2, 3, [4]]);
// --> '1,2,3,4'
toStr();
// --> 'undefined'
typeof toStr();
// --> 'string'
Installation
npm i @writetome51/to-str
Loading
import {toStr} from '@writetome51/to-str';