1.0.1 • Published 4 years ago
js-type-escape v1.0.1
js-type-escape
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.
Installation
$ npm install js-type-escape
Usage
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
API
processEscapeStr2Value
process escape string to value with its data type
Parameters
str
{string}
Returns (string | any | undefined | number)
processValue2EscapeStr
process value to escape string
Parameters
val
{any}
Returns string
License
This project is licensed under the MIT license.