string-type-convertor

1.2.0 • Public • Published

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

Package Sidebar

Install

npm i string-type-convertor

Weekly Downloads

3

Version

1.2.0

License

MIT

Unpacked Size

4.97 kB

Total Files

4

Last publish

Collaborators

  • benevolar