{"name":"typeforce","version":"1.15.1","description":"Another biased type checking solution for Javascript","keywords":["typeforce","types","typechecking","type","exceptions","force"],"homepage":"https://github.com/dcousens/typeforce","bugs":{"url":"https://github.com/dcousens/typeforce/issues"},"license":"MIT","author":{"name":"Daniel Cousens"},"main":"index.js","repository":{"type":"git","url":"git+https://github.com/dcousens/typeforce.git"},"scripts":{"coverage":"nyc --check-coverage --branches 100 --functions 100 node test/*.js","test":"npm run standard && npm run unit","standard":"standard","unit":"node test/*.js"},"dependencies":{},"devDependencies":{"nyc":"^6.4.0","standard":"^9.0.0","tape":"^4.6.1"},"gitHead":"aebd35e08fa645844c02c0f70e63072f290857c8","_id":"typeforce@1.15.1","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"dcousens","email":"npm@dcousens.com"},"dist":{"integrity":"sha512-RYgFG+2GXx4V7guHOhW0cvryg/iWAoopbF/WlOI25YoV9rsOQ0E8bKfYAEZbJL0LJ8yVqcwp77tDG+oebBSNNw==","shasum":"fe24533cb3dbff2b79a3556bb3a3d4854850b2a5","tarball":"http://registry-npm.ywwl.com/typeforce/download/typeforce-1.15.1.tgz","fileCount":7,"unpackedSize":17385,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbyVPiCRA9TVsSAnZWagAAkbwP/2PaY33IHYjqLRPLF2jD\n/8Fq90RQXIcHTPbtW9+G8PGm/EIINtflHuVUko4Ckk/l6mUw7sjNVZGoshzc\npu6ZlsJ1pAf29ouvAkRvZQ5MxgoVBiZkm2foFbGF5mMMyLCnlKwN4elyGS/c\n7mt4escV75PA/hUU1jsDQshsCD4qQwP7JGU/DZtEp7Q/GkNEmxkY3to5sReY\nNukHUxPln05HnlqHDI5M1UD1VLZWPZ4fF8qtNr6371Bsbp7dxp8kHsBinjLz\nubVe+LenNCWcl30g8BAgAlt0ygu3H0F7oGqVyffeYFua3l9Gmiph2jrJNHLO\nLEGH/l8F9yusdfxKFPSK/sIOV+SiBqUndPP/WRbvvqxB798q92lfyAiALxqT\njfJmLadQV/IpFzWollIvHD0tSM9yPf1ThtExoQqbJm0/ysglvmLLUM9spXgW\nj5ozSqSlYCcYjnzCjEwm8C+H91Ty4CT9zdUqhQ0vK1vbQ2G0Tdv6EnTNaHWd\nvCPYMCtcSP+Ls6aEKOxctD6peh+RNFRbpvDPcGeoSwpefXU/AugMJI6k6Imz\n51rlWWn1KMPiEhpQb7FYJUMtn5ZxtjDodKF6f9ZFWRdr4kv0LL/NNHIlPGGZ\nka3rRtFE2VOSIzYBHGhUk4jBted5g9X7h19WU7tvfCW2UoGe21i17sa8rl6v\nwm9Z\r\n=HINH\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC9xt1kTRmcJKDCUSN1fWBE2O9N996p0bbg10cn0iUv+AIhALJYeebFC7KvMSu9++FHccncsIdAOzAV2Nbyme6s/zO2"}],"size":5281,"noattachment":false,"key":"/typeforce/-/typeforce-1.15.1.tgz"},"maintainers":[{"name":"dcousens","email":"email@dcousens.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/typeforce_1.15.1_1539920865610_0.6713910290326677"},"_hasShrinkwrap":false,"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":1539920865771,"_cnpm_publish_time":1539920865771,"dist-tags":{"latest":"1.18.0"}}