{"name":"typeforce","version":"1.1.2","description":"Another biased type checking solution for Javascript","main":"index.js","author":{"name":"Daniel Cousens"},"license":"MIT","scripts":{"coverage":"istanbul cover _mocha -- test/*.js","coveralls":"npm run coverage && coveralls < coverage/lcov.info","standard":"standard","test":"npm run standard && npm run unit","unit":"mocha"},"repository":{"type":"git","url":"git+https://github.com/dcousens/typeforce.git"},"bugs":{"url":"https://github.com/dcousens/typeforce/issues"},"homepage":"https://github.com/dcousens/typeforce","devDependencies":{"coveralls":"^2.11.2","istanbul":"^0.3.7","mocha":"*","standard":"*"},"dependencies":{},"gitHead":"bc4bf451a602ba00ee67c588278fefa3b0b74cc5","_id":"typeforce@1.1.2","_shasum":"7d47a844d2b5d8ddafb92d19552eeffb3315183b","_from":".","_npmVersion":"2.11.2","_nodeVersion":"0.12.4","_npmUser":{"name":"dcousens","email":"email@dcousens.com"},"dist":{"shasum":"7d47a844d2b5d8ddafb92d19552eeffb3315183b","tarball":"http://registry-npm.ywwl.com/typeforce/download/typeforce-1.1.2.tgz","integrity":"sha512-X0eaG2w/FQ3i01B8mUf0qiNbYdyfRrde4SIlUo6rIzCm7XzLvdnBNXqNMTa6vKD7x7eASvdteqkS/24/8iSbLQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD6wx9vRJVz1TPVCWbe+QwAfRny3tSIyY4ZF+AjIxgpugIhANiNSJLak0jc4EVSicoS2R3TaN7L9Q9eLY1Sw5yxBOga"}],"size":3877,"noattachment":false,"key":"/typeforce/-/typeforce-1.1.2.tgz"},"maintainers":[{"name":"dcousens","email":"email@dcousens.com"}],"directories":{},"readme":"# typeforce\n[![build status](https://secure.travis-ci.org/dcousens/typeforce.png)](http://travis-ci.org/dcousens/typeforce)\n[![Version](https://img.shields.io/npm/v/typeforce.svg)](https://www.npmjs.org/package/typeforce)\n\nAnother biased type checking solution for Javascript.\n\nException messages may change between patch versions,  as often the patch will change some behaviour that was unexpected and naturally it results in a different error message.\n\n## Examples\n\n``` javascript\nvar typeforce = require('typeforce')\n\nvar element = { prop: 'foo' }\nvar elementNumber = { prop: 2 }\nvar array = [element, element, elementNumber]\n\n// supported primitives 'Array', 'Boolean', 'Buffer', 'Number', 'Object', 'String'\ntypeforce('Array', array)\n\ntypeforce('Number', array)\n// TypeError: Expected Number, got Array\n\n// array types\ntypeforce(['Object'], array)\ntypeforce(typeforce.arrayOf('Object'), array)\n\n// supports recursive type templating\ntypeforce({ prop: 'Number' }, elementNumber)\n\n// maybe types\ntypeforce('?Number', 2)\ntypeforce('?Number', null)\ntypeforce(typeforce.maybe(typeforce.Number), 2)\ntypeforce(typeforce.maybe(typeforce.Number), null)\n\n// sum types\ntypeforce(typeforce.anyOf('String', 'Number'), 2)\ntypeforce(typeforce.allOf({ x: typeforce.Number }, { y: typeforce.Number }), {\n  x: 1,\n  y: 2\n})\n\n// value types\ntypeforce(typeforce.value(3.14), 3.14)\n\n// custom types\nfunction LongString (value, strict) {\n  if (!typeforce.String(value)) return false\n  if (value.length !== 32) return false\n  return true\n}\n\ntypeforce(LongString, '00000000000000000000000000000000')\n// => OK!\n\ntypeforce(LongString, 'not long enough')\n// TypeError: Expected LongString, got String 'not long enough'\n```\n\n**Pro**tips:\n``` javascript\n// use precompiled primitives for high performance\ntypeforce(typeforce.Array, array)\n\n// or just precompile a template\nvar type = {\n  foo: 'Number',\n  bar: '?String'\n}\n\nvar fastType = typeforce.compile(type)\n// fastType => typeforce.object({\n//   foo: typeforce.Number,\n//   bar: typeforce.maybe(typeforce.String)\n// })\n\n// use strictness for recursive types to enforce whitelisting properties\ntypeforce({\n  x: 'Number'\n}, { x: 1 }, true)\n// OK!\n\ntypeforce({\n  x: 'Number'\n}, { x: 1, y: 2 }, true)\n// TypeError: Unexpected property 'y' of type Number\n```\n\n**Pro**tips (extended types):\n``` javascript\ntypeforce(typeforce.tuple('String', 'Number'), ['foo', 1])\n// OK!\n\ntypeforce(typeforce.tuple('Number', 'Number'), ['not a number', 1])\n// TypeError: Expected property \"0\" of type Number, got String 'not a number'\n\ntypeforce(typeforce.map('Number'), {\n  'anyKeyIsOK': 1\n})\n// OK!\n\ntypeforce(typeforce.map('Number', typeforce.HexN(8)), {\n  'deadbeef': 1,\n  'ffff0000': 2\n})\n// OK!\n\nfunction Foo () {\n  this.x = 2\n}\n\ntypeforce(typeforce.quacksLike('Foo'), new Foo())\n// OK!\n\n// Note, any Foo will do\ntypeforce(typeforce.quacksLike('Foo'), new (function Foo() {}))\n// OK!\n```\n\n**Pro**tips (no throw)\n``` javascript\nvar typeforce = require('typeforce/nothrow')\nvar value = 'foobar'\n\nif (typeforce(typeforce.Number, value)) {\n\t// didn't throw!\n\tconsole.log(`${value} is a number`) // never happens\n} else {\n\tconsole.log(`Oops, ${typeforce.error.message}`)\n\t// prints 'Oops, Expected Number, got String foobar'\n}\n```\n\n**Pro**tips (async)\n```\nvar typeforce = require('typeforce/async')\n\ntypeforce(typeforce.Number, value, function (err) {\n\tif (err) return console.log(`Oops, ${typeforce.error.message}`)\n\n\tconsole.log(`${value} is a number`) // never happens\n})\n```\n\n**WARNING**: Be very wary of using the `quacksLike` type, as it relies on the `Foo.name` property.\nIf that property is mangled by a transpiler,  such as `uglifyjs`,  you will have a bad time.\n\n## LICENSE [MIT](LICENSE)\n","publish_time":1434598300284,"_cnpm_publish_time":1434598300284,"dist-tags":{"latest":"1.18.0"}}