{"id":17771192,"url":"https://github.com/zhigalov/http-assert-value","last_synced_at":"2025-04-01T15:18:58.251Z","repository":{"id":57268059,"uuid":"119533511","full_name":"Zhigalov/http-assert-value","owner":"Zhigalov","description":"Assert values with status codes","archived":false,"fork":false,"pushed_at":"2018-11-01T06:23:51.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-07T18:03:15.213Z","etag":null,"topics":["assert","http","json-schema"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zhigalov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-30T12:34:06.000Z","updated_at":"2018-11-01T06:23:53.000Z","dependencies_parsed_at":"2022-09-02T02:50:10.217Z","dependency_job_id":null,"html_url":"https://github.com/Zhigalov/http-assert-value","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhigalov%2Fhttp-assert-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhigalov%2Fhttp-assert-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhigalov%2Fhttp-assert-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zhigalov%2Fhttp-assert-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zhigalov","download_url":"https://codeload.github.com/Zhigalov/http-assert-value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246660077,"owners_count":20813338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assert","http","json-schema"],"created_at":"2024-10-26T21:30:04.848Z","updated_at":"2025-04-01T15:18:58.225Z","avatar_url":"https://github.com/Zhigalov.png","language":"JavaScript","readme":"# http-assert of typed values\n\n## Install\n```bash\nnpm install http-assert-value --save\n```\n\n## Usage\n```js\nconst assert = require('http-assert-value');\n\n// Common assert interface\nassert(+0 === -0, 'Zeros are not equal', 500, 'ZNE', {\n    leftOperand: +0,\n    reghtOperand: -0,\n    operation: '==='\n});                                        // Ok\n\n// Assert typed values\nassert.identity('green-mile');             // Ok\nassert.float('3.14');                      // Ok\nassert.positiveInt('12');                  // Ok\nassert.text('The Green Mile');             // Ok\n\n// Assert by JSON schema\n// @see: http://json-schema.org/\nassert.bySchema('1', { type: 'integer' }); // Ok\n\n// All methods have duplicates with `try...`\nassert.text(undefined);                    // Error\nassert.tryText(undefined);                 // Ok\n\ntry {\n    assert.text('DROP DATABASE BOOKS;');\n} catch (error) {\n    error.message;    // 'Text is invalid'\n    error.statusCode; // 400\n    error.options;    // { value: 'DROP DATABASE BOOKS;', internalCode: '400_TVI' }\n}\n```\n\n## API\n\n### assert(value, message, code, shortMessage, options={})\nAssert value with http-specific error data\n\n* value `Any` - asserting value\n* message `String` - error text\n* code `Number` - error http-code\n* shortMessage `String` - three-letter error code\n* \\[options\\] `Object` - error additional information\n\n### assert.identity(value, field = 'Identity')\nAssert slug or unique identity value\n\n* value `String|Array\u003cString\u003e` - asserting value\n* \\[field\\] `String` - name of the parameter containing value\n\n### assert.float(value, field = 'Float')\nAssert float value\n\n* value `String|Array\u003cString\u003e` - asserting value\n* \\[field\\] `String` - name of the parameter containing value\n\n### assert.positiveInt(value, field = 'Positive integer')\nAssert positive integer value\n\n* value `String|Array\u003cString\u003e` - asserting value\n* \\[field\\] `String` - name of the parameter containing value\n\n### assert.text(value, field = 'Text')\nAssert text, like search request\n\n* value `String|Array\u003cString\u003e` - asserting value\n* \\[field\\] `String` - name of the parameter containing value\n\n### assert.bySchema(value, schema, options = {})\nAssert object by schema\n\n* value `Any|Array\u003cAny\u003e` - asserting value\n* schema `Object` - json-schema\n* \\[options\\] `Object` - ajv constructor options\n\n### assert.oneOf(value, expected = [], comparator)\nAssert value, that it is in array\n\n* value `Any` - asserting value\n* \\[expected\\] `Array` - array which contains expected values\n* \\[comparator\\] `Function` - function which compare values from array with asserting\nvalue. By default used comparator to compare primitive (`(lhs, rhs) =\u003e lhs === rhs`)\n\n### assert.id(value, field = 'Id')\nAlias for `assert.positiveInt`\n\n### assert.maxLength(value, maxLength = 0, field = 'Text')\nAssert that value length is less than passed maxLength\n\n* value `Any` - asserting value\n* \\[maxLength\\] `Number` - max allowed length of a string\n* \\[field\\] `String` - name of the parameter containing value\n\n\nEvery method has *try-version* method, which has same interface and assert value,\nwhen value is passed:\n\n- assert.tryIdentity\n- assert.tryFloat\n- assert.tryPositiveInt\n- assert.tryText\n- assert.tryBySchema\n- assert.oneOf\n- assert.id\n- assert.maxLength\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhigalov%2Fhttp-assert-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhigalov%2Fhttp-assert-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhigalov%2Fhttp-assert-value/lists"}