{"action":"created","comment":{"url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/comments/165353303","pull_request_review_id":93276462,"id":165353303,"diff_hunk":"@@ -0,0 +1,99 @@\n+const httpAssert = require('http-assert');\n+const Ajv = require('ajv');\n+\n+/**\n+ * Assert value with http-specific error data\n+ *\n+ * @param {String} value\n+ * @param {String} message - text of the error\n+ * @param {Number} code - http-code of the error\n+ * @param {String} shortMessage - three-letters code of the error\n+ * @param {Object} [options] - additional information of the error\n+ */\n+const assert = (value, message, code, shortMessage, options = {}) => {\n+    if (shortMessage) {\n+        options.internalCode = `${code}_${shortMessage}`;\n+    }\n+\n+    httpAssert(value, code, message, { options });\n+};\n+\n+const methods = {\n+    /**\n+     * Assert slug or unique identity value\n+     *\n+     * @param {String} value\n+     * @param {String} [field] - name of the parameter containing value\n+     */\n+    identity: (value, field = 'Identity') => {\n+        const isValid = /^[\\w\\.-]+$/.test(value);\n+\n+        assert(isValid, `${field} is invalid`, 400, 'III', { value });\n+    },\n+\n+    /**\n+     * Assert float value\n+     *\n+     * @param {String} value\n+     * @param {String} [field] - name of the parameter containing value\n+     */\n+    float: (value, field = 'Float') => {\n+        const isValid = /^-?\\d+(?:\\.\\d+)?$/.test(value);\n+\n+        assert(isValid, `${field} is invalid`, 400, 'FVI', { value });\n+    },\n+\n+    /**\n+     * Assert positive integer value\n+     *\n+     * @param {String} value\n+     * @param {String} [field] - name of the parameter containing value\n+     */\n+    positiveInt: (value, field = 'Positive integer') => {\n+        const isValid = /^\\d+$/.test(value) && Number(value) > 0;\n+\n+        assert(isValid, `${field} is invalid`, 400, 'PII', { value });\n+    },\n+\n+    /**\n+     * Assert text, like search request\n+     *\n+     * @param {String} value\n+     * @param {String} [field] - name of the parameter containing value\n+     */\n+    text: (value, field = 'Text') => {\n+        const isValid = /^[\\w\\s-]+$/i.test(value);\n+\n+        assert(isValid, `${field} is invalid`, 400, 'TVI', { value });\n+    },\n+\n+    /**\n+     * Assert object by schema\n+     *\n+     * @param {Object} value\n+     * @param {Object} schema\n+     * @param {Object} [options] - ajv constructor options\n+     */\n+    bySchema: (value, schema, options = {}) => {","path":"index.js","position":77,"original_position":77,"commit_id":"60c5d9b6fb487a778c5771572671313bbcdba1a7","original_commit_id":"60c5d9b6fb487a778c5771572671313bbcdba1a7","user":{"login":"Zhigalov","id":1654243,"avatar_url":"https://avatars2.githubusercontent.com/u/1654243?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhigalov","html_url":"https://github.com/Zhigalov","followers_url":"https://api.github.com/users/Zhigalov/followers","following_url":"https://api.github.com/users/Zhigalov/following{/other_user}","gists_url":"https://api.github.com/users/Zhigalov/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhigalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhigalov/subscriptions","organizations_url":"https://api.github.com/users/Zhigalov/orgs","repos_url":"https://api.github.com/users/Zhigalov/repos","events_url":"https://api.github.com/users/Zhigalov/events{/privacy}","received_events_url":"https://api.github.com/users/Zhigalov/received_events","type":"User","site_admin":false},"body":"Он есть\r\n```js\r\nassert.bySchema('1', { type: 'integer' }); // Ok\r\n```\r\nДумаешь недостаточно?\r\n","created_at":"2018-02-01T13:22:58Z","updated_at":"2018-02-01T13:29:17Z","html_url":"https://github.com/Zhigalov/http-assert-value/pull/1#discussion_r165353303","pull_request_url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/comments/165353303"},"html":{"href":"https://github.com/Zhigalov/http-assert-value/pull/1#discussion_r165353303"},"pull_request":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1"}},"in_reply_to_id":165349227},"pull_request":{"url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1","id":166528273,"html_url":"https://github.com/Zhigalov/http-assert-value/pull/1","diff_url":"https://github.com/Zhigalov/http-assert-value/pull/1.diff","patch_url":"https://github.com/Zhigalov/http-assert-value/pull/1.patch","issue_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/1","number":1,"state":"open","locked":false,"title":"Implementation","user":{"login":"Zhigalov","id":1654243,"avatar_url":"https://avatars2.githubusercontent.com/u/1654243?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhigalov","html_url":"https://github.com/Zhigalov","followers_url":"https://api.github.com/users/Zhigalov/followers","following_url":"https://api.github.com/users/Zhigalov/following{/other_user}","gists_url":"https://api.github.com/users/Zhigalov/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhigalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhigalov/subscriptions","organizations_url":"https://api.github.com/users/Zhigalov/orgs","repos_url":"https://api.github.com/users/Zhigalov/repos","events_url":"https://api.github.com/users/Zhigalov/events{/privacy}","received_events_url":"https://api.github.com/users/Zhigalov/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-02-01T12:49:45Z","updated_at":"2018-02-01T13:29:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ce195e62055f88fb14566997befd56fecea05fb0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/1/comments","statuses_url":"https://api.github.com/repos/Zhigalov/http-assert-value/statuses/60c5d9b6fb487a778c5771572671313bbcdba1a7","head":{"label":"Zhigalov:implementation","ref":"implementation","sha":"60c5d9b6fb487a778c5771572671313bbcdba1a7","user":{"login":"Zhigalov","id":1654243,"avatar_url":"https://avatars2.githubusercontent.com/u/1654243?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhigalov","html_url":"https://github.com/Zhigalov","followers_url":"https://api.github.com/users/Zhigalov/followers","following_url":"https://api.github.com/users/Zhigalov/following{/other_user}","gists_url":"https://api.github.com/users/Zhigalov/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhigalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhigalov/subscriptions","organizations_url":"https://api.github.com/users/Zhigalov/orgs","repos_url":"https://api.github.com/users/Zhigalov/repos","events_url":"https://api.github.com/users/Zhigalov/events{/privacy}","received_events_url":"https://api.github.com/users/Zhigalov/received_events","type":"User","site_admin":false},"repo":{"id":119533511,"name":"http-assert-value","full_name":"Zhigalov/http-assert-value","owner":{"login":"Zhigalov","id":1654243,"avatar_url":"https://avatars2.githubusercontent.com/u/1654243?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhigalov","html_url":"https://github.com/Zhigalov","followers_url":"https://api.github.com/users/Zhigalov/followers","following_url":"https://api.github.com/users/Zhigalov/following{/other_user}","gists_url":"https://api.github.com/users/Zhigalov/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhigalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhigalov/subscriptions","organizations_url":"https://api.github.com/users/Zhigalov/orgs","repos_url":"https://api.github.com/users/Zhigalov/repos","events_url":"https://api.github.com/users/Zhigalov/events{/privacy}","received_events_url":"https://api.github.com/users/Zhigalov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Zhigalov/http-assert-value","description":"Assert values with status codes","fork":false,"url":"https://api.github.com/repos/Zhigalov/http-assert-value","forks_url":"https://api.github.com/repos/Zhigalov/http-assert-value/forks","keys_url":"https://api.github.com/repos/Zhigalov/http-assert-value/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Zhigalov/http-assert-value/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Zhigalov/http-assert-value/teams","hooks_url":"https://api.github.com/repos/Zhigalov/http-assert-value/hooks","issue_events_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/events{/number}","events_url":"https://api.github.com/repos/Zhigalov/http-assert-value/events","assignees_url":"https://api.github.com/repos/Zhigalov/http-assert-value/assignees{/user}","branches_url":"https://api.github.com/repos/Zhigalov/http-assert-value/branches{/branch}","tags_url":"https://api.github.com/repos/Zhigalov/http-assert-value/tags","blobs_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/refs{/sha}","trees_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Zhigalov/http-assert-value/statuses/{sha}","languages_url":"https://api.github.com/repos/Zhigalov/http-assert-value/languages","stargazers_url":"https://api.github.com/repos/Zhigalov/http-assert-value/stargazers","contributors_url":"https://api.github.com/repos/Zhigalov/http-assert-value/contributors","subscribers_url":"https://api.github.com/repos/Zhigalov/http-assert-value/subscribers","subscription_url":"https://api.github.com/repos/Zhigalov/http-assert-value/subscription","commits_url":"https://api.github.com/repos/Zhigalov/http-assert-value/commits{/sha}","git_commits_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/commits{/sha}","comments_url":"https://api.github.com/repos/Zhigalov/http-assert-value/comments{/number}","issue_comment_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/comments{/number}","contents_url":"https://api.github.com/repos/Zhigalov/http-assert-value/contents/{+path}","compare_url":"https://api.github.com/repos/Zhigalov/http-assert-value/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Zhigalov/http-assert-value/merges","archive_url":"https://api.github.com/repos/Zhigalov/http-assert-value/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Zhigalov/http-assert-value/downloads","issues_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues{/number}","pulls_url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls{/number}","milestones_url":"https://api.github.com/repos/Zhigalov/http-assert-value/milestones{/number}","notifications_url":"https://api.github.com/repos/Zhigalov/http-assert-value/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Zhigalov/http-assert-value/labels{/name}","releases_url":"https://api.github.com/repos/Zhigalov/http-assert-value/releases{/id}","deployments_url":"https://api.github.com/repos/Zhigalov/http-assert-value/deployments","created_at":"2018-01-30T12:34:06Z","updated_at":"2018-01-30T12:34:06Z","pushed_at":"2018-02-01T12:49:45Z","git_url":"git://github.com/Zhigalov/http-assert-value.git","ssh_url":"git@github.com:Zhigalov/http-assert-value.git","clone_url":"https://github.com/Zhigalov/http-assert-value.git","svn_url":"https://github.com/Zhigalov/http-assert-value","homepage":null,"size":7,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"Zhigalov:master","ref":"master","sha":"d2ba883a93efccf8c2eb95875795f26b61c3c330","user":{"login":"Zhigalov","id":1654243,"avatar_url":"https://avatars2.githubusercontent.com/u/1654243?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhigalov","html_url":"https://github.com/Zhigalov","followers_url":"https://api.github.com/users/Zhigalov/followers","following_url":"https://api.github.com/users/Zhigalov/following{/other_user}","gists_url":"https://api.github.com/users/Zhigalov/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhigalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhigalov/subscriptions","organizations_url":"https://api.github.com/users/Zhigalov/orgs","repos_url":"https://api.github.com/users/Zhigalov/repos","events_url":"https://api.github.com/users/Zhigalov/events{/privacy}","received_events_url":"https://api.github.com/users/Zhigalov/received_events","type":"User","site_admin":false},"repo":{"id":119533511,"name":"http-assert-value","full_name":"Zhigalov/http-assert-value","owner":{"login":"Zhigalov","id":1654243,"avatar_url":"https://avatars2.githubusercontent.com/u/1654243?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhigalov","html_url":"https://github.com/Zhigalov","followers_url":"https://api.github.com/users/Zhigalov/followers","following_url":"https://api.github.com/users/Zhigalov/following{/other_user}","gists_url":"https://api.github.com/users/Zhigalov/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhigalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhigalov/subscriptions","organizations_url":"https://api.github.com/users/Zhigalov/orgs","repos_url":"https://api.github.com/users/Zhigalov/repos","events_url":"https://api.github.com/users/Zhigalov/events{/privacy}","received_events_url":"https://api.github.com/users/Zhigalov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Zhigalov/http-assert-value","description":"Assert values with status codes","fork":false,"url":"https://api.github.com/repos/Zhigalov/http-assert-value","forks_url":"https://api.github.com/repos/Zhigalov/http-assert-value/forks","keys_url":"https://api.github.com/repos/Zhigalov/http-assert-value/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Zhigalov/http-assert-value/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Zhigalov/http-assert-value/teams","hooks_url":"https://api.github.com/repos/Zhigalov/http-assert-value/hooks","issue_events_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/events{/number}","events_url":"https://api.github.com/repos/Zhigalov/http-assert-value/events","assignees_url":"https://api.github.com/repos/Zhigalov/http-assert-value/assignees{/user}","branches_url":"https://api.github.com/repos/Zhigalov/http-assert-value/branches{/branch}","tags_url":"https://api.github.com/repos/Zhigalov/http-assert-value/tags","blobs_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/refs{/sha}","trees_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Zhigalov/http-assert-value/statuses/{sha}","languages_url":"https://api.github.com/repos/Zhigalov/http-assert-value/languages","stargazers_url":"https://api.github.com/repos/Zhigalov/http-assert-value/stargazers","contributors_url":"https://api.github.com/repos/Zhigalov/http-assert-value/contributors","subscribers_url":"https://api.github.com/repos/Zhigalov/http-assert-value/subscribers","subscription_url":"https://api.github.com/repos/Zhigalov/http-assert-value/subscription","commits_url":"https://api.github.com/repos/Zhigalov/http-assert-value/commits{/sha}","git_commits_url":"https://api.github.com/repos/Zhigalov/http-assert-value/git/commits{/sha}","comments_url":"https://api.github.com/repos/Zhigalov/http-assert-value/comments{/number}","issue_comment_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/comments{/number}","contents_url":"https://api.github.com/repos/Zhigalov/http-assert-value/contents/{+path}","compare_url":"https://api.github.com/repos/Zhigalov/http-assert-value/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Zhigalov/http-assert-value/merges","archive_url":"https://api.github.com/repos/Zhigalov/http-assert-value/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Zhigalov/http-assert-value/downloads","issues_url":"https://api.github.com/repos/Zhigalov/http-assert-value/issues{/number}","pulls_url":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls{/number}","milestones_url":"https://api.github.com/repos/Zhigalov/http-assert-value/milestones{/number}","notifications_url":"https://api.github.com/repos/Zhigalov/http-assert-value/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Zhigalov/http-assert-value/labels{/name}","releases_url":"https://api.github.com/repos/Zhigalov/http-assert-value/releases{/id}","deployments_url":"https://api.github.com/repos/Zhigalov/http-assert-value/deployments","created_at":"2018-01-30T12:34:06Z","updated_at":"2018-01-30T12:34:06Z","pushed_at":"2018-02-01T12:49:45Z","git_url":"git://github.com/Zhigalov/http-assert-value.git","ssh_url":"git@github.com:Zhigalov/http-assert-value.git","clone_url":"https://github.com/Zhigalov/http-assert-value.git","svn_url":"https://github.com/Zhigalov/http-assert-value","homepage":null,"size":7,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1"},"html":{"href":"https://github.com/Zhigalov/http-assert-value/pull/1"},"issue":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/1"},"comments":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Zhigalov/http-assert-value/statuses/60c5d9b6fb487a778c5771572671313bbcdba1a7"}},"author_association":"OWNER"}}
{"actor":{"display_login":"Zhigalov"}}