{"id":22693324,"url":"https://github.com/softvisio-node/result","last_synced_at":"2025-04-13T00:12:45.778Z","repository":{"id":57161349,"uuid":"373385110","full_name":"softvisio-node/result","owner":"softvisio-node","description":"Result object","archived":false,"fork":false,"pushed_at":"2025-03-26T01:44:04.000Z","size":167,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T00:12:04.749Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://softvisio-node.github.io/result/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softvisio-node.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-03T04:55:10.000Z","updated_at":"2025-03-26T01:44:08.000Z","dependencies_parsed_at":"2024-04-15T17:48:45.074Z","dependency_job_id":"74fb9109-a3c6-46d9-af63-e6d003fde98a","html_url":"https://github.com/softvisio-node/result","commit_stats":{"total_commits":188,"total_committers":1,"mean_commits":188.0,"dds":0.0,"last_synced_commit":"110d8179cb77e3070271db9dae0c6f6849811f91"},"previous_names":[],"tags_count":117,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvisio-node%2Fresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvisio-node%2Fresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvisio-node%2Fresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvisio-node%2Fresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softvisio-node","download_url":"https://codeload.github.com/softvisio-node/result/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647278,"owners_count":21139086,"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":[],"created_at":"2024-12-10T02:10:08.453Z","updated_at":"2025-04-13T00:12:45.762Z","avatar_url":"https://github.com/softvisio-node.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- !!! DO NOT EDIT, THIS FILE IS GENERATED AUTOMATICALLY !!!  --\u003e\n\n\u003e :information_source: Please, see the full project documentation here:\u003cbr\u003e\u003chttps://softvisio-node.github.io/result/\u003e\n\n# Introduction\n\nSerializable result object, that encapsulates operation status, statusText and returned data.\n\n## Install\n\n```sh\nnpm install @softvisio/result\n```\n\nUnder `node` environment it also register itself as `global.result`, so you don;t need to import it into all modules;\n\n## Usage\n\n```javascript\nimport result from \"@softvisio/result\";\n\nvar res = result( 200 );\n\nres = result( [ 200, \"Completed\" ] ); // custom status text\n\nres = result( 200, { data } ); // with some data\n\ntry {\n    res = result.try( await someFunctionCall() );\n}\ncatch ( e ) {\n    res = result.catch( e );\n}\n```\n\n### result( status, data?, meta? )\n\n- `status` {integer|Array|Error} Status code, {Error} object, result-like object (has `status` and `statusText` properties, for example, `node-fetch` result) or {Array}:\n    - {integer} Status code.\n    - {string} Status text.\n- `data?` {any} arbitrary Data that represents returned value. This data is accesible via `result.data` property.\n- `meta?` {Object} Additional meta properties, that will be stored in the result object.\n- Returns: {Result}.\n\nCreates new result object.\n\nExample:\n\n```javascript\nconst res = result( 500, { \"a\": 1 }, { \"meta\": \"some data\" } );\n\nconsole.log( res.ok ); // false\nconsole.log( res.status ); // 500\nconsole.log( res.statustext ); // internal server error\nconsole.log( res.data ); // {\"a\": 1}\nconsole.log( res.meta ); // \"some data\"\n```\n\n### result.exception( status, data?, meta? )\n\n- `status` {integer|Array} Status code or {Array} \\[status code, status text].\n- `data?` {any} arbitrary Data that represents returned value. This data is accesible via `result.data` property.\n- `meta?` {Object} Additional meta properties, that will be stored in the result object.\n- Returns: {Result}.\n\nCreates new result exception object. Same, as [`result( status, data, properties )`](#result-status-data-properties-), but also set `result.exception` to the `true` in case if result is not successuful.\n\n### result.try( res?, options? )\n\n- `res?` {any} Value to check.\n- `options?` {Object}:\n    - `allowUndefined` {boolean} Returns error if set to `false`. **Default:** `false`.\n    - `keepError` {boolean} If `res` is instance of the {Error} set error message as result `statusText`.\n- Returns: {Result}.\n\nChecks, that `res` is instance of {Result}. If `res` is:\n\n- {undefined}: returns `result( 200 )`.\n- {Result}: returns `res` as is.\n- Result-like object (object, that has `status` and `statusText` properties): returns `result( [res.status, res.statusText] )`.\n- {Error}: returns `result( [500, error.message] )`.\n- Any other value: returns `result( 500 )`.\n\n### result.catch( res, options? )\n\n- `res` {any} Value to check.\n- `options?` {Object}:\n    - `keepError` {boolean} If `res` is instance of {Error} set error message as result `statusText`.\n    - `log` {boolean} Do not print error to the console.\n- Returns: {Result}.\n\nChecks, that `res` is instance of {Result}. If `res` is:\n\n- {Result}: returns `res` as is;\n- Result-like object (object, that has `status` and `statusText` properties): returns `result( [res.status, res.statusText] )`.\n- {Error}: returns `result( [500, error.message] )`.\n- Any other value converted to the {Error} object (`Error( res )`) and processed as described above.\n\n### result.fromJson( res )\n\n- `res` {Object} Result object data, produced by `Result.toJSON()`.\n- Returns: {Result}.\n\n### result.fromJsonRpc)\n\n- `msg` {Object} JSON RPC 2.0 message.\n- Returns: {Result}.\n\nConverts JSON RPC response message to the {Result} object.\n\n### result.getHttpStatus( status )\n\n- `status` {integer} Status code.\n- Returns: {integer} Status code.\n\nReturns status code in range, supported by `HTTP` protocol.\n\n### result.getStatusText( status )\n\n- `status` {integer} Status code.\n- Returns: {string} Status text.\n\nResolves status text by the status code.\n\n### Class: Result\n\n#### result.status\n\n- {integer} Status code.\n\n#### result.statusText\n\n- {string} Status text.\n\n#### result.isException\n\n- {boolean} Returns `true` if result is exception.\n\n#### result.ok\n\n- {boolean} Returns `true` if result is successful, otherwise returns `false`.\n\n#### result.error\n\n- {boolean} Returns `true` if result is error.\n\n#### result.is1xx\n\n- {boolean} Returns `true` if result code is in range: `100` - `199`.\n\n#### result.is2xx\n\n- {boolean} Returns `true` if result code is in range: `200` - `299`.\n\n#### result.is3xx\n\n- {boolean} Returns `true` if result code is in range: `300` - `399`.\n\n#### result.is4xx\n\n- {boolean} Returns `true` if result code is in range: `400` - `499`.\n\n#### result.is5xx\n\n- {boolean} Returns `true` if result code \u003e= `500`.\n\n#### result.toString()\n\n- Returns: {string}.\n\n#### result.toJSON()\n\n- Returns: {string}.\n\n#### result.toJsonRpc( id )\n\n- `id` {integer} JSON RPC message id.\n- Returns: {Object} JSON RPC response.\n\nConverts result object to the JSON RPC response.\n\n## Status codes\n\n### RPC status codes\n\n#### RPC request errors\n\n| Status Code | Status Text                                          |\n| ----------: | ---------------------------------------------------- |\n|      -32800 | RPC calls are not supported                          |\n|      -32802 | Too many requests                                    |\n|      -32803 | Unsupported content type                             |\n|      -32804 | HTTP method not allowed                              |\n|      -32807 | Unable to decode RPC message body                    |\n|      -32808 | Parameters validation error                          |\n|      -32809 | API method not found                                 |\n|      -32810 | Persistent connection is required to call API method |\n|      -32811 | Access denied                                        |\n|      -32812 | Authorization is required                            |\n|      -32813 | Session is disabled                                  |\n|      -32814 | Backend is down                                      |\n|      -32815 | Session was deleted                                  |\n|      -32816 | Service is shutting down                             |\n|      -32817 | Request aborted                                      |\n\n### HTTP status codes\n\n#### Informational\n\n| Status Code | Status Text         |\n| ----------: | ------------------- |\n|         100 | Continue            |\n|         101 | Switching Protocols |\n|         102 | Processing          |\n|         103 | Early Hints         |\n\n#### Success\n\n| Status Code | Status Text                   |\n| ----------: | ----------------------------- |\n|         200 | OK                            |\n|         201 | Created                       |\n|         202 | Accepted                      |\n|         203 | Non-Authoritative Information |\n|         204 | No Content                    |\n|         205 | Reset Content                 |\n|         206 | Partial Content               |\n|         207 | Multi-Status                  |\n|         208 | Already Reported              |\n|         226 | IM Used                       |\n\n#### Redirect\n\n| Status Code | Status Text        |\n| ----------: | ------------------ |\n|         300 | Multiple Choices   |\n|         301 | Moved Permanently  |\n|         302 | Found              |\n|         303 | See Other          |\n|         304 | Not Modified       |\n|         305 | Use Proxy          |\n|         307 | Temporary Redirect |\n|         308 | Permanent Redirect |\n\n#### Client error\n\n| Status Code | Status Text                     |\n| ----------: | ------------------------------- |\n|         400 | Bad Request                     |\n|         401 | Unauthorized                    |\n|         402 | Payment Required                |\n|         403 | Forbidden                       |\n|         404 | Not Found                       |\n|         405 | Method Not Allowed              |\n|         406 | Not Acceptable                  |\n|         407 | Proxy Authentication Required   |\n|         408 | Request Timeout                 |\n|         409 | Conflict                        |\n|         410 | Gone                            |\n|         411 | Length Required                 |\n|         412 | Precondition Failed             |\n|         413 | Payload Too Large               |\n|         414 | URI Too Long                    |\n|         415 | Unsupported Media Type          |\n|         416 | Range Not Satisfiable           |\n|         417 | Expectation Failed              |\n|         418 | I'm a Teapot                    |\n|         421 | Misdirected Request             |\n|         422 | Unprocessable Entity            |\n|         423 | Locked                          |\n|         424 | Failed Dependency               |\n|         425 | Too Early                       |\n|         426 | Upgrade Required                |\n|         428 | Precondition Required           |\n|         429 | Too Many Requests               |\n|         431 | Request Header Fields Too Large |\n|         451 | Unavailable For Legal Reasons   |\n\n#### Server error\n\n| Status Code | Status Text                     |\n| ----------: | ------------------------------- |\n|         500 | Internal Server Error           |\n|         501 | Not Implemented                 |\n|         502 | Bad Gateway                     |\n|         503 | Service Unavailable             |\n|         504 | Gateway Timeout                 |\n|         505 | HTTP Version Not Supported      |\n|         506 | Variant Also Negotiates         |\n|         507 | Insufficient Storage            |\n|         508 | Loop Detected                   |\n|         509 | Bandwidth Limit Exceeded        |\n|         510 | Not Extended                    |\n|         511 | Network Authentication Required |\n\n### WebSockets status codes\n\n| Status Code | Status Text         |\n| ----------: | ------------------- |\n|        1000 | Normal Closure      |\n|        1001 | Going Away          |\n|        1002 | Protocol error      |\n|        1003 | Unsupported Data    |\n|        1004 | Reserved            |\n|        1005 | No Status Rcvd      |\n|        1006 | Abnormal Closure    |\n|        1007 | Invalid Payload     |\n|        1008 | Policy Violation    |\n|        1009 | Message Too Big     |\n|        1010 | Mandatory Extension |\n|        1011 | Internal Error      |\n|        1012 | Service Restart     |\n|        1013 | Try Again Later     |\n|        1014 | Bad Gateway         |\n|        1015 | TLS Handshake       |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftvisio-node%2Fresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftvisio-node%2Fresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftvisio-node%2Fresult/lists"}