Convert JS value to escape string, and then you can convert back.
js-type-escape
's main API processValue2EscapeStr
converts Javascript Value to an escape string, and another API processEscapeStr2Value
converts escape string to Javascript Value with correct date type.
$ npm install js-type-escape
Important: Only primitive types, Object and Array are supported, function, Date are not supported.
import {processValue2EscapeStr} from 'js-type-escape'
processValue2EscapeStr('js-type-escape') // 1__js-type-escape
processValue2EscapeStr(1000) // 2__1000
processValue2EscapeStr([1,2,3,'4','a']) // 3__[1,2,3,'4','a']
processValue2EscapeStr({a: 1, b: 'c', d: [2, 'e'], f: {g: 'h'}}) // 3__"{"a":1,"b":"c","d":[2,"e"],"f":{"g":"h"}}"
processValue2EscapeStr(true) // 5__true
process escape string to value with its data type
str
{string}
Returns (string | any | undefined | number)
process value to escape string
val
{any}
Returns string
This project is licensed under the MIT license.