can-util
Version:
Common utilities for CanJS projects
29 lines (21 loc) • 925 B
Markdown
function} can-util/js/string-to-any/string-to-any string-to-any
can-util/js
Turns a string representation of a primitive type back into the associated primitive.
`stringToAny(string)`
Examines the provided string to see if it can be converted to a primitive type. Supported arguments are:
* "true"
* "false"
* "null"
* "undefined"
* "NaN"
* "Infinity"
* Any [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
* Any [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
```js
import stringToAny from "can-util/js/string-to-any/string-to-any";
stringToAny( "NaN" ); // -> NaN
stringToAny( "44.4" ); // -> 44.4
stringToAny( "false" ); // -> false
```
{String} string A string to convert back to its primitive type.
{*} The primitive representation of the provided string.
{