{"_id":"typing","_rev":"92-9212c1d9f1dd91de0f519f7340fe715e","name":"typing","description":"A type checking and JSON schema validation library","dist-tags":{"latest":"0.1.9"},"versions":{"0.1.0":{"name":"typing","version":"0.1.0","description":"A simple and intuitive type definition and validation library for JavaScript","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","jsschema","js-schema","type","typing","validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"readme":"typing.js\n=========\n\nA simple and intuitive JSON schema validation library for JavaScript.\n\n###Usage:\n\n```Javascript\ntyping.check(<type-definition>, <data>);\n```\n\n###Example:\n\n```JavaScript\n// import module\nvar typing = require('typing');\n\n// import the built-in types\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n````\n\n**Define custom type with built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\n// matched\nassert(typing.check(t_employee, [123, 'todd', ['1355-0011-107', 'CA 5607']]));\n\n// not matched, id must be >= 1\nassert(false == typing.check(t_employee, [0, 'todd', ['1355-0011-107', 'CA 5607']]));\n```\n\n**Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n});\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n});\n\n// not matched, status.message is missing\nassert(typing.check(t_response, {\n    status : {\n        code : 300\n    }\n});\n```\n","readmeFilename":"README.md","_id":"typing@0.1.0","dist":{"shasum":"6538264d61d2b62f2ce21396d465f3b4e07e2b6b","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.0.tgz","integrity":"sha512-antNt1BsNNlHtvbbH+l3Of+N1LpYun1+E9HVx2DBMP9QC9nr5TjPIyJV5br68VkCm3ED9hFbGAOE4CexndRnGg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCYNyqNYgb4/G/peWvh9wUumPMSltdg18uSLenL3iJE6AIhANOOQWVUyxc1IGjHoUzsu0Rk6BPJwHE65rp2iWbk2eSi"}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.1":{"name":"typing","version":"0.1.1","description":"A simple and intuitive type definition and validation library for JavaScript","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"readme":"###Typing.js: A type checking and JSON schema validation library for JS\n\n####Usage:\n\n```Javascript\ntyping.check(<type>, <data>); //true: matched; false: not matched\n```\n\nwhere ```<type>``` can be:\n\n1) Function with ```__name__``` and ```__check__``` property, i.e. the built-in type bool is defined as:\n\n```Javascript\nfunction bool() {}\nbool.__name__ = 'bool';\nbool.__check__ = function(value) { return 'boolean' == typeof(value); }\n```\n\n```typing.check(<type>, <data>)``` will call ```<type>.__check__(<data>)``` in this case. You can define your own types this way, however be aware that typing comes with a set of built-in types, which can be used to construct complex types. i.e. \n\n```Javascript\ntuple(int(1,10000), str(1,50), tuple(str, str)) \n```\ncan be used to match employee record\n```Javascript\n[123, 'todd', ['1354-0013-628', 'CD 5037']]\n```\n\n2) JSON object, such as:\n\n```Javascript\n{\n    status : {\n        code : int,\n        message : str\n    },\n    data : table(int, str, tuple(str, str))\n}\n```\n\n```typing.check(<type>, <data>)``` will do pattern matching based on the structure and recursively check the type of each property. \n\n####Examples:\n\n```JavaScript\n// import module\nvar typing = require('typing');\n\n// import the built-in types\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n````\n\n**1. Define custom type with built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\n// matched\nassert(typing.check(t_employee, [123, 'todd', ['1355-0011-107', 'CD 5607']]));\n\n// not matched, id must be >= 1\nassert(false == typing.check(t_employee, [0, 'todd', ['1355-0011-107', 'CD 5607']]));\n```\n\n**2. Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n});\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n});\n\n// not matched, status.message is missing\nassert(typing.check(t_response, {\n    status : {\n        code : 300\n    }\n});\n```\n\n**3. Define recursive type** \n```Javascript\n// define a binary tree type\n// type(name): define a lazy resolved type\nvar t_tree = {\n    value : int,\n    left : nullable(type('tree')),\n    right : nullable(type('tree'))\n};\n\n// define type t_node under the name 'tree'\ntyping.define('tree', t_tree);\n\n// matched\nassert(typing.check('tree', {\n    value : 1,\n    left : {\n        value : 2,\n        left : { value : 3 }\n    },\n    right : {\n        value : 4,\n        right : { value : 5 }\n    }\n}));\n```\n","readmeFilename":"README.md","_id":"typing@0.1.1","dist":{"shasum":"df0711fb2b4fd2a1e6aa692ce78b2c8d61d4dfbc","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.1.tgz","integrity":"sha512-RypjavkOavC7tea7xTrIqBBdXyW4XKvvwBjsygb3q7rlr1hzsIviMfP9Rvs5A2XxosBaYDIx8tvGsANx8f/DSw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCpYafnTu/ks8PRSgZRo4rwmVZ3IGhrdtGIg6gUaA40ZAIhAI6revrByY3mTKQbYLwmWTw5jwxtV9b5KNzVUSYxKnkP"}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.2":{"name":"typing","version":"0.1.2","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"readme":"###Typing.js: a type checking and JSON schema validation library\n\n####Usage:\n\n```Javascript\ntyping.check(<type>, <data>); //true: matched; false: not matched\n```\n\nwhere ```<type>``` can be:\n\n1) Function with ```__name__``` and ```__check__``` property, i.e. the built-in type ```bool``` is defined as:\n\n```Javascript\nfunction bool() {}\nbool.__name__ = 'bool';\nbool.__check__ = function(value) { return 'boolean' == typeof(value); }\n```\n\n```typing.check(<type>, <data>)``` will call ```<type>.__check__(<data>)``` in this case. You can define your own types this way, however be aware that typing comes with a set of built-in types, which can be used to construct complex types. i.e. \n\n```Javascript\ntuple(int(1,10000), str(1,50), tuple(str, str)) \n```\ncan be used to match employee record\n```Javascript\n[123, 'todd', ['1354-0013-628', 'CD 5037']]\n```\n\n2) JSON object, i.e.:\n\n```Javascript\n{\n    status : {\n        code : int,\n        message : str\n    },\n    data : table(int, str, tuple(str, str))\n}\n```\n\n```typing.check(<type>, <data>)``` will perform pattern matching between type and data based on the structure and recursively check the type of each property. \n\n3) String, i.e.:\n\n```Javascript\n// define 3x3 matrix type under the name 'matrix_3x3'\ntyping.define('matrix_3x3', tuple(tuple(int, int, int), tuple(int, int, int), tuple(int, int, int)));\n\n// check type with the type name\nassert(typing.check('matrix_3x3', [[1, 2, 3], [4, 5, 6], [7, 8, 9]]));\n```\n\n####Examples:\n\n```JavaScript\n// import module\nvar typing = require('typing');\n\n// import the built-in types\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n````\n\n**1. Define custom type with the built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\n// matched\nassert(typing.check(t_employee, [123, 'todd', ['1355-0011-107', 'CD 5607']]));\n\n// not matched, id must be >= 1\nassert(false == typing.check(t_employee, [0, 'todd', ['1355-0011-107', 'CD 5607']]));\n```\n\n**2. Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n});\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n});\n\n// not matched, status.message is missing\nassert(typing.check(t_response, {\n    status : {\n        code : 300\n    }\n});\n```\n\n**3. Define recursive type** \n```Javascript\n// define a recursive binary tree type under the name 'tree'\n// nullalbe(type): extend the wrapped type to accept null value\n// type(name): define a lazy resolved type\ntyping.define('tree', {\n    value : int,\n    left : nullable(type('tree')),\n    right : nullable(type('tree'))\n});\n\n// matched\nassert(typing.check('tree', {\n    value : 1,\n    left : {\n        value : 2,\n        left : { value : 3 }\n    },\n    right : {\n        value : 4,\n        right : { value : 5 }\n    }\n}));\n```\n","readmeFilename":"README.md","_id":"typing@0.1.2","dist":{"shasum":"fcf9f6af7636d3a926d1332feea40ee47917db07","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.2.tgz","integrity":"sha512-N1gPNQMX/Zwblek6yRAjfBrWDhD04u9fT1Q5E0x7EbIWsGixj6fhuL8ROjv6zzjZ31aDk37ZXWL07r/lkhWqrg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCVCfR2gyjZ5NdnI6XhtMO8ZqT5GbbXknXsy7PDeWjbgAIgLFr2OMEOk143AegPDMO+HxBe2hcIK8956xZ1UYPHrfo="}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.3":{"name":"typing","version":"0.1.3","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"readme":"###Typing.js: a type checking and JSON schema validation library\n\n####Usage:\n\n```Javascript\ntyping.check(type, data); //true: matched; false: not matched\n```\n\nwhere ```type``` can be:\n\n1) Function with ```__name__``` and ```__check__``` property, i.e. the built-in type ```bool``` is defined as:\n\n```Javascript\nfunction bool() {}\nbool.__name__ = 'bool';\nbool.__check__ = function(value) { return 'boolean' == typeof(value); }\n```\n\n```typing.check(type, data)``` will call ```type.__check__(data)``` in this case. You can define your own types this way, however be aware that typing comes with a set of built-in types, which can be used to construct complex types. i.e. \n\n```Javascript\ntuple(int(1,10000), str(1,50), tuple(str, str)) \n```\ncan be used to match employee record\n```Javascript\n[123, 'todd', ['1354-0013-628', 'CD 5037']]\n```\n\n2) JSON object, i.e.:\n\n```Javascript\n{\n    status : {\n        code : int,\n        message : str\n    },\n    data : table(int, str, tuple(str, str))\n}\n```\n\n```typing.check(type, data)``` will perform pattern matching between type and data based on the structure and recursively check the type of each property. \n\n3) String, i.e.:\n\n```Javascript\n// define 3x3 matrix type under the name 'matrix_3x3'\ntyping.define('matrix_3x3', tuple(tuple(int, int, int), tuple(int, int, int), tuple(int, int, int)));\n\n// check type with the type name\nassert(typing.check('matrix_3x3', [[1, 2, 3], [4, 5, 6], [7, 8, 9]]));\n```\n\n####Examples:\n\n```JavaScript\n// import module\nvar typing = require('typing');\n\n// import the built-in types\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n````\n\n**1. Define custom type with the built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\n// matched\nassert(typing.check(t_employee, [123, 'todd', ['1355-0011-107', 'CD 5607']]));\n\n// not matched, id must be >= 1\nassert(false == typing.check(t_employee, [0, 'todd', ['1355-0011-107', 'CD 5607']]));\n```\n\n**2. Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n});\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n});\n\n// not matched, status.message is missing\nassert(typing.check(t_response, {\n    status : {\n        code : 300\n    }\n});\n```\n\n**3. Define recursive type** \n```Javascript\n// define a recursive binary tree type under the name 'tree'\n// nullalbe(type): extend the wrapped type to accept null value\n// type(name): define a lazy resolved type\ntyping.define('tree', {\n    value : int,\n    left : nullable(type('tree')),\n    right : nullable(type('tree'))\n});\n\n// matched\nassert(typing.check('tree', {\n    value : 1,\n    left : {\n        value : 2,\n        left : { value : 3 }\n    },\n    right : {\n        value : 4,\n        right : { value : 5 }\n    }\n}));\n```\n","readmeFilename":"README.md","_id":"typing@0.1.3","dist":{"shasum":"233bb86095cc9ab5cd307ec756b5d3ddc58e9364","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.3.tgz","integrity":"sha512-TcXB6PNOVL+WkzjCRkip0Sn5ERFv5/9s70ZXUCCdCiZyS/J+/CspceSrxD88sDsIoUkQwjZiCDdjw8aTyw4nLA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHeABH/240XoKFZKDTXUbKaQ9vgLXtL+rxTA0rmGZyW2AiEA8I7rnZXDy+eooUdnj689DPypZUiJ57UiO7SIwvqYz3o="}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.4":{"name":"typing","version":"0.1.4","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"readme":"#A Quick Guide to Typing.js\n\n##1. Overview\n\nTyping.js is a simple, intuitive and expressive type checking and JSON schema validation library for Node.js. It goes beyond the JSON schema validation, it actually looks like a runtime type system for JavaScript. \n\n**Features:**\n\n1. a set of commonly used built-in types, i.e. int, str, array, tuple, table;\n2. C++ template like type definition with array, tuple and table;\n3. structure based pattern matching\n4. recursive type\n\n##2. Sample: \n```JavaScript\n// import module and the built-in types\nvar typing = require('typing');\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n\n// primitive type checking\ntyping.check(str(3,10), 'hello')\n\n// composite type checking\ntyping.check(\n    tuple(int, str, tuple(str, str)), \n    [23, 'todd', ['82301588', 'todd@mail.com']]\n)\n\n// pattern matching\ntyping.check(\n    { \n        id : int, \n        male : bool, \n        name : str(1,50), \n        contact : { tel : str, email : str }\n    }, \n    { \n        id : 23, \n        male : true, \n        name : 'todd', \n        contact : { tel : '82301588', email : 'todd@mail.com' }\n    }\n)\n```\n\n##3. Usage:\n\n```Javascript\ntyping.check(type, data); //true: matched; false: not matched\n```\n\nwhere ```type``` can be:\n\n1) Function with ```__name__``` and ```__check__``` property. \n\nFor example, the built-in type ```bool``` is defined as:\n\n```Javascript\nfunction bool() {}\nbool.__name__ = 'bool';\nbool.__check__ = function(value) { return true === value || false === value; }\n```\n\n```typing.check(type, data)``` will call ```type.__check__(data)``` in this case. You can define your own types this way, however, be aware that typing comes with a set of built-in types, which can be used to construct complex types. \n\n2) JSON object.\n\nFor example, \n\n```Javascript\n{\n    status : {\n        code : int,\n        message : str\n    },\n    data : table(int, str, tuple(str, str))\n}\n```\n\n```typing.check(type, data)``` will perform pattern matching between type and data based on the structure and recursively check the type of each property. \n\n3) String.\n\nFor example, \n\n```Javascript\n// define 3x3 matrix type under the name 'matrix_3x2'\ntyping.define('matrix_3x2', tuple(tuple(int, int), tuple(int, int), tuple(int, int)));\n\n// check type with the type name\nassert(typing.check('matrix_3x3', [[11, 12], [21, 22], [31, 32]]));\n```\n\n**3.1. Define custom type with the built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\n// matched\nassert(typing.check(t_employee, [123, 'todd', ['1355-0011-107', 'CD 5607']]));\n\n// not matched, id must be >= 1\nassert(false == typing.check(t_employee, [0, 'todd', ['1355-0011-107', 'CD 5607']]));\n```\n\n**3.2. Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n});\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n});\n\n// not matched, status.message is missing\nassert(typing.check(t_response, {\n    status : {\n        code : 300\n    }\n});\n```\n\n**3.3. Define recursive type** \n```Javascript\n// define a recursive binary tree type under the name 'tree'\n// nullalbe(type): extend the wrapped type to accept null value\n// type(name): define a lazy resolved type\ntyping.define('tree', {\n    value : int,\n    left : nullable(type('tree')),\n    right : nullable(type('tree'))\n});\n\n// matched\nassert(typing.check('tree', {\n    value : 1,\n    left : {\n        value : 2,\n        left : { value : 3 }\n    },\n    right : {\n        value : 4,\n        right : { value : 5 }\n    }\n}));\n```\n\n##4. Built-in Types##\n\n**1. any**\n\n```any``` matches any value in JavaScript including null and undefined. Examples:\n\n```Javascript\ntyping.check(any, null); //true\ntyping.check(any, undefined); //true\ntyping.check(any, 123); //true\ntyping.check(any, 'hello typing.js'); //true\ntyping.check(any, {}); //true\ntyping.check(any, []); //true\ntyping.check(any, function(){}); //true\n```\n\n**2. bool**\n\n```bool``` matches ```true``` or ```false```. Examples:\n\n```JavaScript\ntyping.check(bool, true); //true\ntyping.check(bool, false); //true\n```\n\n**3. int**\n\n```int``` matches integers. You can specify the minimal and maximal value by ```int(min)``` or ```int(min,max)```. Examples:\n\n```JavaScript\ntyping.check(int, -103); //true, no min and max\ntyping.check(int, 'hello'); //false\ntyping.check(int(100), 99); //false, matches integer >= 100\ntyping.check(int(0,1000), 1000); //true, matches integer >= 0 and <= 1000\n```\n\n**4. str**\n\n```str``` matches strings. You can specify the minimal and maximal lenght by ```str(min)``` or ```str(min,max)```. Examples:\n\n```JavaScript\ntyping.check(str, null); //true\ntyping.check(str, ''); //true\ntyping.check(str(0), null); //true\ntyping.check(str(0), ''); //true\ntyping.check(str(3), 'foo'); //true, matches string with length >= 3\ntyping.check(str(4), 'foo'); //false\ntyping.check(str(1,3), ''); //false, matches string with length >= 1 and <= 3 \ntyping.check(str(1,3), 'hello'); //false, matches string with length >= 1 and <= 3 \n```\n","readmeFilename":"README.md","_id":"typing@0.1.4","dist":{"shasum":"ac09133f313dc2a4e84fa58b988934c168850ee9","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.4.tgz","integrity":"sha512-x0AtMXOaIdaBpvoLjHekrcciEzD9Xu0k+9PGpFPVXcoTCSG4o5UtnRuVSAMRlOM5Fsc4hFo5p35EV7duDeGd/w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCI4ruc10FWiU+Cb3y3JHDUKrXyXS+OBLaPpf8tObql+QIgej/rtlfNqs1o0N2dm2TV0/4FT22YtWJn+ZB869dh3M8="}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.5":{"name":"typing","version":"0.1.5","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"readme":"#A Quick Guide to Typing.js\n\n##1. Overview\n\nTyping.js is a simple, intuitive and expressive type checking and JSON schema validation library for Node.js. It goes beyond the JSON schema validation, it actually looks like a runtime type system for JavaScript. \n\n**Features:**\n\n1. a set of commonly used built-in types, i.e. int, str, array, tuple, table;\n2. C++ template like type definition with array, tuple and table;\n3. structure based pattern matching\n4. recursive type\n\n##2. Sample: \n```JavaScript\n// import module and the built-in types\nvar typing = require('typing');\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n\n// primitive type checking\ntyping(bool, true) //true\ntyping(int(0,10), 5) //true\ntyping(str(3,10), 'hello') //true\ntyping(enumeration('foo', 'bar'), 'foo') //true\n\n// composite type checking\ntyping(\n    tuple(int, str, tuple(str, str)), \n    [23, 'todd', ['82301588', 'todd@mail.com']]\n) //true\n\n// pattern matching\ntyping(\n    { \n        id : int, \n        male : bool, \n        name : str(1,50), \n        contact : { tel : str, email : str }\n    }, \n    { \n        id : 23, \n        male : true, \n        name : 'todd', \n        contact : { tel : '82301588', email : 'todd@mail.com' }\n    }\n) //true\n```\n\n##3. Usage:\n\n```Javascript\ntyping(type, data); //true: matched; false: not matched\n```\n\nwhere ```type``` can be:\n\n1) Function with ```__name__``` and ```__check__``` property. \n\nFor example, the built-in type ```bool``` is defined as:\n\n```Javascript\nfunction bool() {}\nbool.__name__ = 'bool';\nbool.__check__ = function(value) { return true === value || false === value; }\n```\n\n```typing(type, data)``` will call ```type.__check__(data)``` in this case. You can define your own types this way, however, be aware that typing comes with a set of built-in types, which can be used to construct complex types. \n\n2) JSON object.\n\nFor example, \n\n```Javascript\n{\n    status : {\n        code : int,\n        message : str\n    },\n    data : table(int, str, tuple(str, str))\n}\n```\n\n```typing(type, data)``` will perform pattern matching between type and data based on the structure and recursively check the type of each property. \n\n3) String.\n\nFor example, \n\n```Javascript\n// define 3x3 matrix type under the name 'matrix_3x2'\ntyping.define('matrix_3x2', tuple(tuple(int, int), tuple(int, int), tuple(int, int)));\n\n// check type with the type name\ntyping('matrix_3x2', [[11, 12], [21, 22], [31, 32]]); //true\n```\n\n**3.1. Define custom type with the built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\ntyping(t_employee, [123, 'todd', ['1355-0011-107', 'CD 5607']]); //true\n\ntyping(t_employee, [0, 'todd', ['1355-0011-107', 'CD 5607']]); //false\n```\n\n**3.2. Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\ntyping(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n}); //true\n\ntyping(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n}); //true\n\ntyping(t_response, {\n    status : {\n        code : 300\n    }\n}); //false, status.message is missing\n```\n\n**3.3. Define recursive type** \n```Javascript\n// define a recursive binary tree type under the name 'tree'\n// nullalbe(type): extend the wrapped type to accept null value\n// type(name): refers to a lazy resolved type\ntyping.define('tree', {\n    value : int,\n    left : nullable(type('tree')),\n    right : nullable(type('tree'))\n});\n\ntyping('tree', {\n    value : 1,\n    left : {\n        value : 2,\n        left : { value : 3 }\n    },\n    right : {\n        value : 4,\n        right : { value : 5 }\n    }\n}); //true\n```\n\n##4. Built-in Types##\n\n**1. any**\n\n```any``` matches any value in JavaScript including null and undefined. \n\n```Javascript\ntyping(any, null); //true\ntyping(any, undefined); //true\ntyping(any, 123); //true\ntyping(any, 'hello typing.js'); //true\ntyping(any, {}); //true\ntyping(any, []); //true\ntyping(any, function(){}); //true\n```\n\n**2. bool**\n\n```bool``` matches ```true``` or ```false```.\n\n```JavaScript\ntyping(bool, true); //true\ntyping(bool, false); //true\n```\n\n**3. int**\n\n```int``` matches integers. You can specify the minimal and maximal value by ```int(min)``` or ```int(min,max)```.\n\n```JavaScript\ntyping(int, -103); //true, no min and max\ntyping(int, 'hello'); //false\ntyping(int(100), 99); //false, matches integer >= 100\ntyping(int(0,1000), 1000); //true, matches integer >= 0 and <= 1000\n```\n\n**4. str**\n\n```str``` matches strings. You can specify the minimal and maximal lenght by ```str(min)``` or ```str(min,max)```.\n\n```JavaScript\ntyping(str, null); //true\ntyping(str, ''); //true\ntyping(str(0), null); //true\ntyping(str(0), ''); //true\ntyping(str(3), 'foo'); //true, matches string with length >= 3\ntyping(str(4), 'foo'); //false\ntyping(str(1,3), ''); //false, matches string with length >= 1 and <= 3 \ntyping(str(1,3), 'hello'); //false, matches string with length >= 1 and <= 3 \n```\n","readmeFilename":"README.md","_id":"typing@0.1.5","dist":{"shasum":"9c86c2aa5e411ac164d288bc5ba351f564595011","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.5.tgz","integrity":"sha512-0+aNtjIux3bpHqPn+geBXKrPoL+ZJF1OdqtpEKcp9vpW63Jf+3afUaZaEWbXCK1XoU2cWBjuhEudEJiGlUHUzw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDYpw3PtBehBte9VHHSD7rqWYLMgFvk4C0ALGgNwz+UdQIhAO0O8wHkR0qgqJ+8kUTr95p766d3rx/uHnvNIZX7glXs"}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.6":{"name":"typing","version":"0.1.6","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"_id":"typing@0.1.6","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"961f65a490b44a87645b416846142dade29c5a67","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.6.tgz","integrity":"sha512-OCURfyJe0hWpX3SKE/q0lz7urS+uIp/LUCwTdNYl1DvUVvFuJV88RjIwGXycof4x9XwIJGjU+wxRM7+RiwLJzQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDx6t1ZxUH9QLZu4nDYXaN7JpN6cpbiR+h2kCkr55/6UQIhAOSZWFgmtTVOUjRK//aZnY96njhv5ziYyLtnNgjMvClQ"}]},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.7":{"name":"typing","version":"0.1.7","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"_id":"typing@0.1.7","_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"702e2f9c894cfda69131e16219eb282595e875ab","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.7.tgz","integrity":"sha512-dePDqdfte9MKBKqtRHl7ClsPUAsuDXz9oP3A3h1zxJ2AkJwhkHhNneYrVDlLdfSL9Zk+M/BzhWxPCXtV5iUg2g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDbpdY8RXuQ2l3Fg9zg6L9RvSy7XO/sqtMLUVkOAi2W8AIgMACpqvKMNE+D3rXwFetYgv4Ulo1cFFHCUpBXh7UaF/E="}]},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.8":{"name":"typing","version":"0.1.8","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"#A Quick Guide to Typing.js\n\n##1. Overview\n\nTyping.js is an expressive and intuitive type checking and JSON schema validation library for Node.js. It goes beyond the JSON schema validation, it actually looks like a runtime type system for JavaScript. \n\n**Features:**\n\n1. a set of commonly used built-in types, i.e. int, str, array, tuple, table;\n2. C++ template style type definition;\n3. structure based pattern matching\n4. recursive type\n\n**Samples:** \n\n```JavaScript\n// import module and the built-in types\nvar typing = require('typing');\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n\n// primitive type checking\ntyping(bool, true) //true\ntyping(int(0,10), 5) //true\ntyping(char, 'q') //true\ntyping(str(3,10), 'hello') //true\ntyping(enumeration('foo', 'bar'), 'foo') //true\n\n// composite type checking\ntyping(\n    tuple(int, str, tuple(str, str)), \n    [23, 'todd', ['82301588', 'todd@mail.com']]\n) //true\n\n// pattern matching\ntyping(\n    { \n        id : int, \n        male : bool, \n        name : str(1,50), \n        contact : { tel : str, email : str }\n    }, \n    { \n        id : 23, \n        male : true, \n        name : 'todd', \n        contact : { tel : '82301588', email : 'todd@mail.com' }\n    }\n) //true\n```\n\n**Usage:**\n\n```Javascript\ntyping(type, data); //true: matched; false: not matched\n```\n\nwhere ```type``` can be:\n\n1) Function with ```__name__``` and ```__check__``` property. \n\nFor example, the built-in type ```bool``` is defined as:\n\n```Javascript\nfunction bool() {}\nbool.__name__ = 'bool';\nbool.__check__ = function(value) { return true === value || false === value; }\n```\n\n```typing(type, data)``` will call ```type.__check__(data)``` in this case. You can define your own types this way, however, be aware that typing comes with a set of built-in types, which can be used to construct complex types. \n\n2) JSON object.\n\nFor example, \n\n```Javascript\n{\n    status : {\n        code : int,\n        message : str\n    },\n    data : table(int, str, tuple(str, str))\n}\n```\n\n```typing(type, data)``` will perform pattern matching between type and data based on the structure and recursively check the type of each property. \n\n3) String.\n\nFor example, \n\n```Javascript\n// define 3x3 matrix type under the name 'matrix_3x2'\ntyping.define('matrix_3x2', tuple(tuple(int, int), tuple(int, int), tuple(int, int)));\n\n// check type with the type name\ntyping('matrix_3x2', [[11, 12], [21, 22], [31, 32]]); //true\n```\n\n##2. How to define types?\n\n**2.1. Define custom type with the built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\ntyping(t_employee, [123, 'todd', ['1355-0011-107', 'CD 5607']]); //true\n\ntyping(t_employee, [0, 'todd', ['1355-0011-107', 'CD 5607']]); //false\n```\n\n**2.2. Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\ntyping(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n}); //true\n\ntyping(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n}); //true\n\ntyping(t_response, {\n    status : {\n        code : 300\n    }\n}); //false, status.message is missing\n```\n\n**2.3. Define recursive type** \n```Javascript\n// define a recursive binary tree type under the name 'tree'\n// nullalbe(type): extend the wrapped type to accept null value\n// type(name): refers to a lazy resolved type\ntyping.define('tree', {\n    value : int,\n    left : nullable(type('tree')),\n    right : nullable(type('tree'))\n});\n\ntyping('tree', {\n    value : 1,\n    left : {\n        value : 2,\n        left : { value : 3 }\n    },\n    right : {\n        value : 4,\n        right : { value : 5 }\n    }\n}); //true\n```\n\n##3. Built-in Types##\n\n**1. any**\n\n```any``` matches any value in JavaScript including null and undefined. \n\n```Javascript\ntyping(any, null); //true\ntyping(any, undefined); //true\ntyping(any, 123); //true\ntyping(any, 'hello typing.js'); //true\ntyping(any, {}); //true\ntyping(any, []); //true\ntyping(any, function(){}); //true\n```\n\n**2. bool**\n\n```bool``` matches ```true``` or ```false```.\n\n```JavaScript\ntyping(bool, true); //true\ntyping(bool, false); //true\n```\n\n**3. int**\n\n```int``` matches integers. You can specify the minimal and maximal value by ```int(min)``` or ```int(min,max)```.\n\n```JavaScript\ntyping(int, -103); //true, no min and max\ntyping(int, 'hello'); //false\ntyping(int(100), 99); //false, matches integer >= 100\ntyping(int(0,1000), 1000); //true, matches integer >= 0 and <= 1000\n```\n\n**4. num**\n\n```num``` matches numbers. You can specify the minimal and maximal value by ```num(min)``` or ```num(min,max)```.\n\n```JavaScript\ntyping(num, -10.3); //true, no min and max\ntyping(num, 'hello'); //false\ntyping(num(100), 99.9); //false, matches num >= 100\ntyping(num(0,51), 25.9); //true, matches num >= 0 and <= 51 \n```\n\n**5. str**\n\n```str``` matches strings. You can specify the minimal and maximal lenght by ```str(min)``` or ```str(min,max)```.\n\n```JavaScript\ntyping(str, null); //true\ntyping(str, ''); //true\ntyping(str(0), null); //true\ntyping(str(0), ''); //true\ntyping(str(3), 'foo'); //true, matches string with length >= 3\ntyping(str(4), 'foo'); //false\ntyping(str(1,3), ''); //false, matches string with length >= 1 and <= 3 \ntyping(str(1,3), 'hello'); //false, matches string with length >= 1 and <= 3 \n```\n\n**6. enumeration**\n\n```enumeration``` matches one of the values.\n\n```JavaScript\ntyping(enumeration('Saturday', 'Sunday'), 'Sunday'); //true\ntyping(enumeration('Saturday', 'Sunday'), 'Friday'); //false\ntyping(enumeration(1, 2, 3), 2); //true\ntyping(enumeration(1, 2, 3), 5); //false\n```\n\n**7. array**\n\n```array``` matches array objects. You can specify the element type of the array.\n\n```JavaScript\ntyping(array, []); //true\ntyping(array, [1, 'foo', {}, null]); //true\ntyping(array(str(3,3)), ['foo', 'bar', 'pee', 'ijk']); //true\ntyping(array(array(str(3,3))), [['foo'], ['bar', 'pee', 'ijk']]); //true\ntyping(array({id : int, name : str}), [{id : 1, name : 'todd'}]); //true\ntyping(array, null); //false\ntyping(array(str(3,3)), ['fooo', 'barr', 'pee', 'ijk']); //false\ntyping(array(str(3,3)), [1, 'bar', 'pee', 'ijk']); //false\n```\n\n\n**8. tuple**\n\n```tuple``` matches array objects with specified number and type of elements.\n\n```JavaScript\ntyping(tuple(int, str), [123, 'todd']); //true\ntyping(tuple(int(1,100), str(1,100), tuple(str(11, 11), str(1))), \n    [100, 'foobar', ['13550013607', 'Tianfu Software Park C2']]); //true\ntyping(tuple(int(1,100), str(1,100), {phone : str, address : str}), \n    [23, 'todd', {phone : '13550013607', address : 'CD 5037'}]); //true\ntyping(tuple(str), null); //false\n```\n\n\n**9. table**\n\n```table(type1, type2 ...) is equivalent to array(tuple(type1, type2 ...), which matches tabular data.\n\n```JavaScript\ntyping(table(int(1,100), str(1,1), str), [[1, 'h', 'host'], [2, 'p', null]]); //true\ntyping(table(int(1,100), str(1,1), str), null); //false\ntyping(table(int(1,100), str(1,1), str), [[1, 'h', 'host'], [2, 'port', null]]); //false\n```\n","readmeFilename":"README.md","_id":"typing@0.1.8","dist":{"shasum":"148b7f297595f801490f4fc038e342b2bf6cb1ae","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.8.tgz","integrity":"sha512-bKqQ3b6wpRnx2qZRTO37jYtweHVINNsa/zvPd7G3Cn092/bskI/ZmARpYeIfSHPZo09tKPF3eRlWRnj+LpMoHQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkOhQim6JG3WIGbhbbyhlcV/ALVl4WCrTXWMmFX4dcWAIgB98UqWx0QCppVyTy2dbXzu4fQImszrSAJMufMC9cK6A="}]},"_from":".","_npmVersion":"1.3.4","_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"directories":{}},"0.1.9":{"name":"typing","version":"0.1.9","description":"A type checking and JSON schema validation library","main":"typeing.js","scripts":{"test":"test/test_typing.js"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"keywords":["schema","json schema","json-schema","jsschema","js-schema","schema validation","type","typing","type checking","type validation"],"author":{"name":"weidagang"},"license":"MIT","bugs":{"url":"https://github.com/weidagang/typing-js/issues"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"weidagang","email":"weidagang@gmail.com"},"_id":"typing@0.1.9","_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"1e6c95235852474d077c1363eaa48d9293ea9440","tarball":"https://registry.npmjs.org/typing/-/typing-0.1.9.tgz","integrity":"sha512-3RT70PeNU72memWBoeuRpRmWkE2+ercs6DMbXJnwRHNLy5X4p6s/vYiatqHPOK+OvzdMLaeLeWEYRGAtJ4jHGw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQClWQEtYlXG86q7VK6YMiSndMoTQtIxbd8FBccnBgSFuQIhAJvIvI/dWyyyTif/+iMNENp7vFIyvTC38gOr91/7RoDD"}]},"maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}]}},"readme":"typing.js\n=========\n\nA simple and intuitive JSON schema validation library for JavaScript.\n\n###Usage:\n\n```Javascript\ntyping.check(<type-definition>, <data>);\n```\n\n###Example:\n\n```JavaScript\n// import module\nvar typing = require('typing');\n\n// import the built-in types\nvar int = typing.int;\nvar str = typing.str;\n...\nvar tuple = typing.tuple;\nvar table = typing.table;\n````\n\n**Define custom type with built-in types**\n\n```JavaScript\n// int(1): integer >= 1;\n// str(1,50): string with length between 1 to 50;\n// tuple: array with specified type and number of elements\nvar t_employee = tuple(int(1), str(1,50), tuple(str,str));\n\n// matched\nassert(typing.check(t_employee, [123, 'todd', ['1355-0011-107', 'CA 5607']]));\n\n// not matched, id must be >= 1\nassert(false == typing.check(t_employee, [0, 'todd', ['1355-0011-107', 'CA 5607']]));\n```\n\n**Define custom type in JSON**\n\n```JavaScript\n// typing will do pattern matching based the type defined in JSON\n// nullable : null or the wrapped type\n// table: equivalent of array(tuple)\nvar t_response = {\n    status : {\n        code : int,\n        message : str\n    },\n    data : nullable(table(int(1), str(1,50), tuple(str,str)))\n};\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 200, \n        message : 'OK'\n    },\n    data : [\n        [1, 'Todd', ['1355-0011-107', 'CA 5607']],\n        [2, 'April', ['1582-0011-108', 'CA 5607']],\n        [3, 'Rex', ['1522-1011-138', 'CA 1008']]\n    ]\n});\n\n// matched\nassert(typing.check(t_response, {\n    status : { \n        code : 404, \n        message : 'NOT FOUND'\n    }\n});\n\n// not matched, status.message is missing\nassert(typing.check(t_response, {\n    status : {\n        code : 300\n    }\n});\n```\n","maintainers":[{"name":"weidagang","email":"weidagang@gmail.com"}],"time":{"modified":"2022-06-28T02:09:34.674Z","created":"2013-08-18T11:55:33.477Z","0.1.0":"2013-08-18T11:55:39.253Z","0.1.1":"2013-08-18T13:42:22.701Z","0.1.2":"2013-08-19T02:11:31.686Z","0.1.3":"2013-08-19T03:35:14.980Z","0.1.4":"2013-08-21T13:22:07.021Z","0.1.5":"2013-08-22T08:36:13.903Z","0.1.6":"2013-09-10T16:19:08.237Z","0.1.7":"2013-09-10T16:34:16.755Z","0.1.8":"2013-09-23T06:50:52.943Z","0.1.9":"2013-10-01T07:22:17.700Z"},"author":{"name":"weidagang"},"repository":{"type":"git","url":"git://github.com/weidagang/typing-js.git"},"users":{"weidagang":true}}