string-type-convertor
v1.2.0
Published
transform string to typed value (number, boolean, float, null, undefined, ...)
Downloads
26
Maintainers
Readme
string-type-convertor
string-type-convertor is a js library for transform string to typed value (number, boolean, float, null, undefined, ...) It is useful when creating a router to retrieve the typed parameters of the url.
Installation
Download nodejs first. Use npm to install string-type-convertor.
npm i string-type-convertor
Usage
const typeConvertor = require('string-type-convertor');
typeConvertor("undefined"); // return undefined
typeConvertor("null"); // return null
typeConvertor("true"); // return true
typeConvertor("false"); // return false
typeConvertor("37n"); // return 37n
typeConvertor("3.14"); // return 3.14
typeConvertor("150"); // return 150
typeConvertor("hello"); // return 'hello'
const myTest = (val) => {
return val === 'email';
}
const myConvert = (val) => {
return `[email protected]`;
}
const personnal = {
test: myTest,
convert: myConvert
}
typeConvertor("email", [personnal]); // return '[email protected]'
Contributing
I try to publish a small js helper. README generate by Google Translate (sorry for bad english)