Skip to content

teeeemoji/js-type-escape

Repository files navigation

js-type-escape

Travis (.com) Codecov npm npm npm bundle size GitHub last commit NPM

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

src/index.js:15-21

process escape string to value with its data type

Parameters

  • str {string}

Returns (string | any | undefined | number)

processValue2EscapeStr

src/index.js:63-78

process value to escape string

Parameters

  • val {any}

Returns string

License

This project is licensed under the MIT license.

About

escape value to string with type

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published