{"id":15817067,"url":"https://github.com/numminorihsf/response-formatter","last_synced_at":"2025-04-01T04:32:51.413Z","repository":{"id":57354766,"uuid":"51726356","full_name":"NumminorihSF/response-formatter","owner":"NumminorihSF","description":"express.js middleware to format response","archived":false,"fork":false,"pushed_at":"2023-04-09T14:37:56.000Z","size":56,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T05:21:52.898Z","etag":null,"topics":[],"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/NumminorihSF.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-15T02:44:44.000Z","updated_at":"2016-02-15T03:42:37.000Z","dependencies_parsed_at":"2024-10-26T11:20:41.210Z","dependency_job_id":"057ec695-dd02-4fd4-a6e6-b2e7ac051122","html_url":"https://github.com/NumminorihSF/response-formatter","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/NumminorihSF%2Fresponse-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fresponse-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fresponse-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fresponse-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NumminorihSF","download_url":"https://codeload.github.com/NumminorihSF/response-formatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246586105,"owners_count":20801026,"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-10-05T05:21:57.727Z","updated_at":"2025-04-01T04:32:51.392Z","avatar_url":"https://github.com/NumminorihSF.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/NumminorihSF/response-formatter.svg?branch=master)](https://travis-ci.org/NumminorihSF/response-formatter)\n[![Coverage Status](https://coveralls.io/repos/github/NumminorihSF/response-formatter/badge.svg?branch=master)](https://coveralls.io/github/NumminorihSF/response-formatter?branch=master)\n\n# Response formatter\n\nThis is an express.js middleware to format your response from server to format, that client waits.\n\nBasic, it can returns json, plain text, xml and html.\n\nOn recursive objects it will return `next(errorObject)`.\n \n## Install\n\n```sh\nnpm install --save response-formatter\n```\n\n## Usage\n\nSimple example:\n\n```js\n  //app - instance on express application\n  var resForm = require('response-formatter');\n  \n  app.use(resForm());\n```\n\n### Options\n\nYou can pass options into `resForm()` call.\n\nOptions is an Object with unnecessary fields:\n\n* `.human` _Boolean_ - Need prettify result or not. Default: calc by `process.env.NODE_ENV===\"production\"`.\n* `.dataSource` _String_ - Path on object, were output data exist. Default: `'res.locals'`. It means, \nthat module will get `res.locals` and try to returning it as result after some work.\n  * You can use `'req'` or `'request'` as request object link.\n  * You can use `'res'` or `'response'` as response object link.\n  * If no such route in object, module will return error to express.\n* `.dataDestination` _String_ - Path on object, to put result data. Default `'res.sentData'`.\n  * Linking to object is like on `.dataSource`\n  * If no such route in object, module will create it.\n* `.formatDestination` _String_ - Path on object, to put format that data has. Default `'res.sentFormatType'`.\n  * Linking to object is like on `.dataSource`\n  * If no such route in object, module will create it.\n* `.formats` _String[]_ - Available formats to returning response. Default `['application/json', 'text/xml', 'text/html', 'text/plain']`.\nIf is empty array, use default. First format is also used as fallback if client want unexpected format.\n* `.userFormatters` _Object_ - Object with user functions to format response data. Default `{}`.\n  * First argument is an data, that module got from data source.\n  * Second arguments is an callback function. Callback wait error object on 1st, and result on 2nd argument.\n\n\n## Test\n\nRun tests\n```sh\nnpm test\n```\n\nTo check code coverage:\n  * Install [istanbul](https://github.com/gotwarlost/istanbul) global\n```sh\nsudo npm install -g istanbul\n```\n\n  * Run npm script\n```sh\nnpm run coverage\n```\n  \n  * Look into `path/to/project/coverage/lcov-report/index.html`\n\n\n## LICENSE - \"MIT License\"\n\nCopyright (c) 2016 Konstantine Petryaev\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumminorihsf%2Fresponse-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumminorihsf%2Fresponse-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumminorihsf%2Fresponse-formatter/lists"}