https://github.com/ceccode/string-type-parser
Micro library guessing type from string content.
https://github.com/ceccode/string-type-parser
Last synced: 9 months ago
JSON representation
Micro library guessing type from string content.
- Host: GitHub
- URL: https://github.com/ceccode/string-type-parser
- Owner: ceccode
- License: mit
- Created: 2016-08-19T21:29:52.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-19T21:43:18.000Z (almost 10 years ago)
- Last Synced: 2025-09-02T08:53:01.603Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# string-type-parser
Micro library guessing type from string content. Usefull when importng from a csv or from JSON.parse().
[](https://travis-ci.org/ceccode/string-type-parser)
[](https://snyk.io/test/github/ceccode/string-type-parser)
[](https://david-dm.org/ceccode/string-type-parser.svg)
## Installation
```
npm install string-type-parser --save
```
## Usage
```
const stringTypeParser = require('string-type-parser');
const obj = {
date: '2016-08-17',
num: '12345',
string: 'I am a string'
timestamp: '1471640778',
date_malformed 'foo-bar 2014'
};
const result = stringTypeParser.parse(obj);
/*
* result.date // December 17, 1995 03:24:00; typeof Ddte
* result.num // 2345; typeof number
* result.string // 'I am a string'; typeof string
* result.timestamp // 1471640778 is a Number, timestamps are not converted in Date; typeof number
* result.date_malformed // return a Date on V8 while 'foo-bar 2014' in SpiderMonkey due nature of Date.parse(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
*/
```
## API
parse(obj)
### Usage
```
const stringTypeParser = require('string-type-parser');
const result = stringTypeParser.parse({age: '28'}); // {age: 28}
const result = stringTypeParser.parse(); // {}
```
## Test
```
npm test
```
## Coverage
```
npm run test-travis
```
## License
[MIT license](LICENSE)