Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benevolarx/string-type-convertor
transform string to typed value (number, boolean, float, null, undefined, ...)
https://github.com/benevolarx/string-type-convertor
Last synced: 5 days ago
JSON representation
transform string to typed value (number, boolean, float, null, undefined, ...)
- Host: GitHub
- URL: https://github.com/benevolarx/string-type-convertor
- Owner: benevolarX
- License: mit
- Created: 2020-11-03T18:44:47.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-02T10:47:16.000Z (almost 4 years ago)
- Last Synced: 2024-10-11T21:20:59.233Z (about 1 month ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GitHub license](https://img.shields.io/github/license/benevolarX/string-type-convertor?style=for-the-badge)](https://github.com/benevolarX/string-type-convertor/blob/main/LICENSE)
[![npm](https://img.shields.io/npm/v/string-type-convertor?style=for-the-badge)](https://www.npmjs.com/package/string-type-convertor)
[![npm](https://img.shields.io/npm/dw/string-type-convertor?style=for-the-badge)](https://www.npmjs.com/package/string-type-convertor)
![npm bundle size](https://img.shields.io/bundlephobia/min/string-type-convertor?style=for-the-badge)
[![GitHub issues](https://img.shields.io/github/issues/benevolarX/string-type-convertor?style=for-the-badge)](https://github.com/benevolarX/string-type-convertor/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](https://nodejs.org/) first.
Use [npm](https://www.npmjs.com/package/npm) to install string-type-convertor.```bash
npm i string-type-convertor
```## Usage
```js
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)## License
[MIT](https://github.com/benevolarX/string-type-convertor/blob/main/LICENSE)