{"action":"created","comment":{"url":"https://api.github.com/repos/node-modules/parameter/pulls/comments/22594310","id":22594310,"diff_hunk":"@@ -1 +1,227 @@\n-module.exports = require('./lib/parameter');\n\\ No newline at end of file\n+/**\n+ * parameter - index.js\n+ *\n+ * Copyright(c) node-modules and other contributors.\n+ * MIT Licensed\n+ *\n+ * Authors:\n+ *  fengmk2 <fengmk2@gmail.com>\n+ *  dead_horse <dead_horse@qq.com>\n+ */\n+\n+'use strict';\n+\n+/**\n+ * Regexps\n+ */\n+\n+var DATE_TYPE_RE = /^\\d{4}\\-\\d{2}\\-\\d{2}$/;\n+var DATETIME_TYPE_RE = /^\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}$/;\n+var ID_RE = /^\\d+$/;\n+\n+/**\n+ * Simple type map\n+ */\n+\n+var TYPE_MAP = {\n+  number: checkNumber,\n+  int: checkInt,\n+  integer: checkInt,\n+  string: checkString,\n+  id: checkId,\n+  date: checkDate,\n+  dateTime: checkDateTime,\n+  boolean: checkBoolean,\n+  bool: checkBoolean,\n+  array: checkArray,\n+  object: checkObject,\n+  enum: checkEnum\n+};\n+\n+var TYPES = Object.keys(TYPE_MAP);\n+\n+module.exports = check;\n+\n+/**\n+ * [check description]\n+ * @return {[type]} [description]\n+ */\n+\n+function check(obj, rules) {\n+  if (typeof rules !== 'object') {\n+    throw new TypeError('need object type rule');\n+  }\n+\n+  var errors = [];\n+\n+  for (var key in rules) {\n+    var rule = getRule(rules[key]);\n+    var has = obj.hasOwnProperty(key);\n+    var data = obj[key];\n+    if (!has) {\n+      if (rule.required !== false) {\n+        errors.push({\n+          message: key + ' required',\n+          field: key,\n+          code: 'missing_field'\n+        });\n+      }\n+      continue;\n+    }\n+\n+    var checker = TYPE_MAP[rule.type];\n+    if (!checker) {\n+      throw new Error('rule type must be one of ' + TYPES.join(', '));","path":"index.js","position":76,"original_position":76,"commit_id":"5750c31f1e33857965e9bb785eb2e1e03a029fee","original_commit_id":"5750c31f1e33857965e9bb785eb2e1e03a029fee","user":{"login":"fengmk2","id":156269,"avatar_url":"https://avatars.githubusercontent.com/u/156269?v=3","gravatar_id":"","url":"https://api.github.com/users/fengmk2","html_url":"https://github.com/fengmk2","followers_url":"https://api.github.com/users/fengmk2/followers","following_url":"https://api.github.com/users/fengmk2/following{/other_user}","gists_url":"https://api.github.com/users/fengmk2/gists{/gist_id}","starred_url":"https://api.github.com/users/fengmk2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengmk2/subscriptions","organizations_url":"https://api.github.com/users/fengmk2/orgs","repos_url":"https://api.github.com/users/fengmk2/repos","events_url":"https://api.github.com/users/fengmk2/events{/privacy}","received_events_url":"https://api.github.com/users/fengmk2/received_events","type":"User","site_admin":false},"body":"TypeError better?","created_at":"2015-01-07T16:03:11Z","updated_at":"2015-01-07T16:03:11Z","html_url":"https://github.com/node-modules/parameter/pull/3#discussion_r22594310","pull_request_url":"https://api.github.com/repos/node-modules/parameter/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/node-modules/parameter/pulls/comments/22594310"},"html":{"href":"https://github.com/node-modules/parameter/pull/3#discussion_r22594310"},"pull_request":{"href":"https://api.github.com/repos/node-modules/parameter/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/node-modules/parameter/pulls/3","id":26965389,"html_url":"https://github.com/node-modules/parameter/pull/3","diff_url":"https://github.com/node-modules/parameter/pull/3.diff","patch_url":"https://github.com/node-modules/parameter/pull/3.patch","issue_url":"https://api.github.com/repos/node-modules/parameter/issues/3","number":3,"state":"open","locked":false,"title":"refactor: rewrite","user":{"login":"dead-horse","id":985607,"avatar_url":"https://avatars.githubusercontent.com/u/985607?v=3","gravatar_id":"","url":"https://api.github.com/users/dead-horse","html_url":"https://github.com/dead-horse","followers_url":"https://api.github.com/users/dead-horse/followers","following_url":"https://api.github.com/users/dead-horse/following{/other_user}","gists_url":"https://api.github.com/users/dead-horse/gists{/gist_id}","starred_url":"https://api.github.com/users/dead-horse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dead-horse/subscriptions","organizations_url":"https://api.github.com/users/dead-horse/orgs","repos_url":"https://api.github.com/users/dead-horse/repos","events_url":"https://api.github.com/users/dead-horse/events{/privacy}","received_events_url":"https://api.github.com/users/dead-horse/received_events","type":"User","site_admin":false},"body":"https://gist.github.com/dead-horse/a32a2eb2451f7d2b63d8","created_at":"2015-01-07T15:48:13Z","updated_at":"2015-01-07T16:03:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6f6d2bc2eb38b5215edc1489eb2d033e11f3d3f3","assignee":{"login":"fengmk2","id":156269,"avatar_url":"https://avatars.githubusercontent.com/u/156269?v=3","gravatar_id":"","url":"https://api.github.com/users/fengmk2","html_url":"https://github.com/fengmk2","followers_url":"https://api.github.com/users/fengmk2/followers","following_url":"https://api.github.com/users/fengmk2/following{/other_user}","gists_url":"https://api.github.com/users/fengmk2/gists{/gist_id}","starred_url":"https://api.github.com/users/fengmk2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengmk2/subscriptions","organizations_url":"https://api.github.com/users/fengmk2/orgs","repos_url":"https://api.github.com/users/fengmk2/repos","events_url":"https://api.github.com/users/fengmk2/events{/privacy}","received_events_url":"https://api.github.com/users/fengmk2/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/node-modules/parameter/pulls/3/commits","review_comments_url":"https://api.github.com/repos/node-modules/parameter/pulls/3/comments","review_comment_url":"https://api.github.com/repos/node-modules/parameter/pulls/comments/{number}","comments_url":"https://api.github.com/repos/node-modules/parameter/issues/3/comments","statuses_url":"https://api.github.com/repos/node-modules/parameter/statuses/5750c31f1e33857965e9bb785eb2e1e03a029fee","head":{"label":"node-modules:refactor","ref":"refactor","sha":"5750c31f1e33857965e9bb785eb2e1e03a029fee","user":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"repo":{"id":10960377,"name":"parameter","full_name":"node-modules/parameter","owner":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/node-modules/parameter","description":"A parameter verify tools.","fork":false,"url":"https://api.github.com/repos/node-modules/parameter","forks_url":"https://api.github.com/repos/node-modules/parameter/forks","keys_url":"https://api.github.com/repos/node-modules/parameter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/node-modules/parameter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/node-modules/parameter/teams","hooks_url":"https://api.github.com/repos/node-modules/parameter/hooks","issue_events_url":"https://api.github.com/repos/node-modules/parameter/issues/events{/number}","events_url":"https://api.github.com/repos/node-modules/parameter/events","assignees_url":"https://api.github.com/repos/node-modules/parameter/assignees{/user}","branches_url":"https://api.github.com/repos/node-modules/parameter/branches{/branch}","tags_url":"https://api.github.com/repos/node-modules/parameter/tags","blobs_url":"https://api.github.com/repos/node-modules/parameter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/node-modules/parameter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/node-modules/parameter/git/refs{/sha}","trees_url":"https://api.github.com/repos/node-modules/parameter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/node-modules/parameter/statuses/{sha}","languages_url":"https://api.github.com/repos/node-modules/parameter/languages","stargazers_url":"https://api.github.com/repos/node-modules/parameter/stargazers","contributors_url":"https://api.github.com/repos/node-modules/parameter/contributors","subscribers_url":"https://api.github.com/repos/node-modules/parameter/subscribers","subscription_url":"https://api.github.com/repos/node-modules/parameter/subscription","commits_url":"https://api.github.com/repos/node-modules/parameter/commits{/sha}","git_commits_url":"https://api.github.com/repos/node-modules/parameter/git/commits{/sha}","comments_url":"https://api.github.com/repos/node-modules/parameter/comments{/number}","issue_comment_url":"https://api.github.com/repos/node-modules/parameter/issues/comments/{number}","contents_url":"https://api.github.com/repos/node-modules/parameter/contents/{+path}","compare_url":"https://api.github.com/repos/node-modules/parameter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/node-modules/parameter/merges","archive_url":"https://api.github.com/repos/node-modules/parameter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/node-modules/parameter/downloads","issues_url":"https://api.github.com/repos/node-modules/parameter/issues{/number}","pulls_url":"https://api.github.com/repos/node-modules/parameter/pulls{/number}","milestones_url":"https://api.github.com/repos/node-modules/parameter/milestones{/number}","notifications_url":"https://api.github.com/repos/node-modules/parameter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/node-modules/parameter/labels{/name}","releases_url":"https://api.github.com/repos/node-modules/parameter/releases{/id}","created_at":"2013-06-26T06:36:32Z","updated_at":"2014-10-16T04:28:29Z","pushed_at":"2015-01-07T15:46:47Z","git_url":"git://github.com/node-modules/parameter.git","ssh_url":"git@github.com:node-modules/parameter.git","clone_url":"https://github.com/node-modules/parameter.git","svn_url":"https://github.com/node-modules/parameter","homepage":null,"size":187,"stargazers_count":18,"watchers_count":18,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":18,"default_branch":"master"}},"base":{"label":"node-modules:master","ref":"master","sha":"3a3b0174da3a51900a7a13859d1bc19c70491f2e","user":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"repo":{"id":10960377,"name":"parameter","full_name":"node-modules/parameter","owner":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/node-modules/parameter","description":"A parameter verify tools.","fork":false,"url":"https://api.github.com/repos/node-modules/parameter","forks_url":"https://api.github.com/repos/node-modules/parameter/forks","keys_url":"https://api.github.com/repos/node-modules/parameter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/node-modules/parameter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/node-modules/parameter/teams","hooks_url":"https://api.github.com/repos/node-modules/parameter/hooks","issue_events_url":"https://api.github.com/repos/node-modules/parameter/issues/events{/number}","events_url":"https://api.github.com/repos/node-modules/parameter/events","assignees_url":"https://api.github.com/repos/node-modules/parameter/assignees{/user}","branches_url":"https://api.github.com/repos/node-modules/parameter/branches{/branch}","tags_url":"https://api.github.com/repos/node-modules/parameter/tags","blobs_url":"https://api.github.com/repos/node-modules/parameter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/node-modules/parameter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/node-modules/parameter/git/refs{/sha}","trees_url":"https://api.github.com/repos/node-modules/parameter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/node-modules/parameter/statuses/{sha}","languages_url":"https://api.github.com/repos/node-modules/parameter/languages","stargazers_url":"https://api.github.com/repos/node-modules/parameter/stargazers","contributors_url":"https://api.github.com/repos/node-modules/parameter/contributors","subscribers_url":"https://api.github.com/repos/node-modules/parameter/subscribers","subscription_url":"https://api.github.com/repos/node-modules/parameter/subscription","commits_url":"https://api.github.com/repos/node-modules/parameter/commits{/sha}","git_commits_url":"https://api.github.com/repos/node-modules/parameter/git/commits{/sha}","comments_url":"https://api.github.com/repos/node-modules/parameter/comments{/number}","issue_comment_url":"https://api.github.com/repos/node-modules/parameter/issues/comments/{number}","contents_url":"https://api.github.com/repos/node-modules/parameter/contents/{+path}","compare_url":"https://api.github.com/repos/node-modules/parameter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/node-modules/parameter/merges","archive_url":"https://api.github.com/repos/node-modules/parameter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/node-modules/parameter/downloads","issues_url":"https://api.github.com/repos/node-modules/parameter/issues{/number}","pulls_url":"https://api.github.com/repos/node-modules/parameter/pulls{/number}","milestones_url":"https://api.github.com/repos/node-modules/parameter/milestones{/number}","notifications_url":"https://api.github.com/repos/node-modules/parameter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/node-modules/parameter/labels{/name}","releases_url":"https://api.github.com/repos/node-modules/parameter/releases{/id}","created_at":"2013-06-26T06:36:32Z","updated_at":"2014-10-16T04:28:29Z","pushed_at":"2015-01-07T15:46:47Z","git_url":"git://github.com/node-modules/parameter.git","ssh_url":"git@github.com:node-modules/parameter.git","clone_url":"https://github.com/node-modules/parameter.git","svn_url":"https://github.com/node-modules/parameter","homepage":null,"size":187,"stargazers_count":18,"watchers_count":18,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":18,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/node-modules/parameter/pulls/3"},"html":{"href":"https://github.com/node-modules/parameter/pull/3"},"issue":{"href":"https://api.github.com/repos/node-modules/parameter/issues/3"},"comments":{"href":"https://api.github.com/repos/node-modules/parameter/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/node-modules/parameter/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/node-modules/parameter/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/node-modules/parameter/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/node-modules/parameter/statuses/5750c31f1e33857965e9bb785eb2e1e03a029fee"}}}}