# parse-value

> Generic value parser for javascript

Latest version **0.1.2** (published 2016-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-value
pnpm add parse-value
yarn add parse-value
bun add parse-value
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2016-07-28 |
| First published | 2016-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Mattia |
| Maintainers | mguella |
| Keywords | parse-value, parse, value, parseInt, parseFloat |

## Links

- npm: https://www.npmjs.com/package/parse-value
- Repository: https://github.com/mguella/parse-value
- Issues: https://github.com/mguella/parse-value/issues
- npm.io page: https://npm.io/package/parse-value

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2016-07-28
- 0.1.1 — 2016-03-24
- 0.1.0 — 2016-03-24

## README

# ParseValue

## Installation

```
npm install --save parse-value
```

## Usage

```javascript
// require parseValue
var parseValue = require('parse-value');

// define type and value
var type = 'number',
    value = '3';

// parse value to requested type
var number = parseValue(type, value);
```


## Documentation

**parseValue(type, value)**:

*Parse value to given type*

params

- String `type`: *type to use*
    - 'string' (default), 'number', 'int', 'integer', 'float', 'date', 'bool', 'boolean', 'regex', 'regexp', 'null'
- Object `value`: *value to parse*

return

- Object: *parsed value*

## Examples

### String

```javascript
parseValue('string','test')
// 'test'
parseValue('string', 3)
// '3'
```


### Number

```javascript
parseValue('number','3')
// 3
parseValue('number','3.2')
// 3.2

parseValue('number', 'abc')
// NaN

parseValue('int','3')
// 3
parseValue('int','3.2')
// 3

parseValue('float','3.2')
// 3.2
```


### Date

```javascript
parseValue('date', '2000-01-01')
// Sat Jan 01 2000 01:00:00 GMT+0100 (CET)
parseValue('date', 946684800000)
// Sat Jan 01 2000 01:00:00 GMT+0100 (CET)

parseValue('date', 'abc')
// Invalid Date
```


### Bool

```javascript
parseValue('bool', true)
// true
parseValue('bool', 1)
// true
parseValue('bool', 'true')
// true
parseValue('bool', 't')
// true
parseValue('bool', 'yes')
// true
parseValue('bool', 'y')
// true

parseValue('bool', false)
// false
parseValue('bool', 0)
// false
parseValue('bool', 'false')
// false
parseValue('bool', 'f')
// false
parseValue('bool', 'no')
// false
parseValue('bool', 'n')
// false
parseValue('bool', null)
// false
```


### Regex

```javascript
parseValue('regex', 'a+b')
// /a+b/gm
parseValue('regex', '.*\\.js')
// /.*\.js/gm
```


### Null

```javascript
parseValue('null', 'anyValue')
// null
parseValue('null', 3)
// null
```



*LICENSE: MIT*

---
_Source: https://npm.io/package/parse-value · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
