string-type-parser
Parse json
Last updated 4 years ago by francesco .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install string-type-parser 
SYNC missed versions from official npm registry.

string-type-parser

Micro library guessing type from string content. Usefull when importng from a csv or from JSON.parse().

Build Status Known Vulnerabilities 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

Current Tags

  • 0.0.1                                ...           latest (4 years ago)

1 Versions

  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |