Skip to content

transform string to typed value (number, boolean, float, null, undefined, ...)

License

Notifications You must be signed in to change notification settings

benevolarX/string-type-convertor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub license npm npm npm bundle size GitHub issues

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 `no-reply@my-website.com`;
}

const personnal = {
    test: myTest,
    convert: myConvert
}

typeConvertor("email", [personnal]); // return 'no-reply@my-website.com'

Contributing

I try to publish a small js helper. README generate by Google Translate (sorry for bad english)

License

MIT

About

transform string to typed value (number, boolean, float, null, undefined, ...)

Resources

License

Stars

Watchers

Forks

Packages

No packages published