# weak-type-wizard

> A small schema enforcer that attempts to cast the properties of an object to the types you want 'em to be.

Latest version **1.4.0** (published 2016-03-01) · 0 weekly downloads

## Install

```sh
npm install weak-type-wizard
pnpm add weak-type-wizard
yarn add weak-type-wizard
bun add weak-type-wizard
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2016-03-01 |
| First published | 2013-12-22 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | TehShrike |
| Maintainers | tehshrike |
| Keywords | typecast, deserialize |

## Links

- npm: https://www.npmjs.com/package/weak-type-wizard
- Repository: https://github.com/TehShrike/weak-type-wizard
- Homepage: https://github.com/TehShrike/weak-type-wizard#readme
- Issues: https://github.com/TehShrike/weak-type-wizard/issues
- npm.io page: https://npm.io/package/weak-type-wizard

## Dependencies (1)

- [xtend](https://npm.io/package/xtend.md) ^4.0.0

## Recent versions

- 1.4.0 (latest) — 2016-03-01
- 1.3.0 — 2015-06-12
- 1.2.4 — 2015-05-06
- 1.2.1 — 2014-10-25
- 1.2.0 — 2013-12-23
- 1.1.0 — 2013-12-22
- 1.0.0 — 2013-12-22

## README

A small schema enforcer that attempts to cast the properties of an object to the types you want 'em to be.

![Travis CI](https://travis-ci.org/TehShrike/weak-type-wizard.svg)

# Install

```sh
npm install weak-type-wizard
```

```
var Wizard = require('weak-type-wizard')
```

# Example

<!-- js
var Wizard = require('.')
-->

```js

var cast = new Wizard({
	boolean: 'sexy',
	number: 'devil',
	date: 'Tue May 05 2015 20:51:30 GMT-0500 (CDT)',
	string: ['one', 'two', 'cat']
})

cast({
	sexy: "true",
	devil: "667",
	one: 1,
	two: "200"
}) // => { sexy: true, devil: 667, one: '1', two: '200' }

```

The "primitive" types of boolean, number, date, and string are supported.  You can supply default values, or even add your own types, like so:

```js

var wizard = new Wizard({
	date: 'dateProperty',
	exciting: 'butts',
	number: ['someNumber', 'anotherNumber'],
	default: {
		someNumber: 666,
		anotherNumber: '1337'
	},
	cast: {
		exciting: function castToExciting(input) {
			return "!" + input + "!"
		}
	}
})

```

# LevelUP support

Use a wizard as a LevelUP encoding - serialize the objects to JSON, and get them back out with all of the parameters cast to whatever you like.  Example:

```js

var levelmem = require('level-mem')

var wizard = new Wizard({
	date: ['dateProperty'],
	number: 'someNumber'
})

var db = levelmem('test', {
	valueEncoding: wizard.getLevelUpEncoding()
})

```

License
=====

[WTFPL](http://wtfpl2.com/)

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