{"id":14676812,"url":"https://github.com/sharkcore/tweenz","last_synced_at":"2025-04-29T06:30:45.052Z","repository":{"id":57382596,"uuid":"112552635","full_name":"sharkcore/tweenz","owner":"sharkcore","description":"Tweens for Express","archived":false,"fork":false,"pushed_at":"2020-06-02T23:46:55.000Z","size":121,"stargazers_count":7,"open_issues_count":10,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-26T03:21:21.006Z","etag":null,"topics":["express","middleware","node","nodejs","pyramid","tween"],"latest_commit_sha":null,"homepage":null,"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/sharkcore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-30T02:13:49.000Z","updated_at":"2024-01-14T09:24:32.000Z","dependencies_parsed_at":"2022-09-01T04:40:39.112Z","dependency_job_id":null,"html_url":"https://github.com/sharkcore/tweenz","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkcore%2Ftweenz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkcore%2Ftweenz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkcore%2Ftweenz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkcore%2Ftweenz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sharkcore","download_url":"https://codeload.github.com/sharkcore/tweenz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224152511,"owners_count":17264718,"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":["express","middleware","node","nodejs","pyramid","tween"],"created_at":"2024-09-12T09:00:56.699Z","updated_at":"2024-11-11T18:22:29.772Z","avatar_url":"https://github.com/sharkcore.png","language":"JavaScript","funding_links":[],"categories":["Middleware"],"sub_categories":[],"readme":"# tweenz\n\n[![npm (scoped)](https://img.shields.io/npm/v/tweenz.svg)](https://yarn.pm/tweenz)\n[![Build Status](https://travis-ci.org/sharkcore/tweenz.svg?branch=master)](https://travis-ci.org/sharkcore/tweenz)\n[![Greenkeeper badge](https://badges.greenkeeper.io/sharkcore/tweenz.svg)](https://greenkeeper.io/)\n\nA small library for writing [Express](https://expressjs.com/) middleware, inspired by\n[Pyramid tweens](https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hooks.html#registering-tweens).\n\n### Why?\n\nThis library does the following:\n\n-   Exposes the response body to the middleware (as part of `requestDetails`)\n-   Provides a first class API to allow middleware to safely execute code after the request has finished\n\n_**Please Note!** This middleware stores the whole response body in memory. If you are returning particularly large responses, you should be aware of this._\n\n## Getting started\n\n```bash\nyarn add tweenz\n```\n\nA tween in `tweenz` looks like this:\n\n```js\nexport default () =\u003e {\n    // one-time configuration code goes here\n\n    return async (requestDetails, req, res) =\u003e {\n        // code to be executed for each request before\n        // the actual application code goes here\n\n        const details = await requestDetails;\n\n        // code to be executed for each request after\n        // the actual application code goes here\n    };\n};\n```\n\n### Example\n\nHere's a tween to calculate the time taken for a request to complete:\n\n#### time-logger.js\n\n```js\nexport default () =\u003e {\n    return async (requestDetails, req, res) =\u003e {\n        const startAt = process.hrtime();\n\n        // wait for request to complete\n        await requestDetails;\n\n        // calculate time taken for request\n        const [seconds, nanoseconds] = process.hrtime(startAt);\n        const miliseconds = seconds * 1e3 + nanoseconds * 1e-6;\n        console.log(`Request took ${miliseconds}ms to complete!`);\n    };\n};\n```\n\n#### app.js\n\n```js\nimport express from 'express';\nimport tweenz from 'tweenz';\nimport timeLogger from './time-logger';\n\nconst app = express();\napp.use(tweenz(timeLogger()));\n\n...\n```\n\n## API\n\n### Registering tweens\n\n```\ntweenz(tween [, tween ...])\n```\n\n### Tween Callback\n\nA tween is a callback, which will get executed with the following arguments\n\n-   **`requestDetails`**\n\n    An object of the following type:\n\n    ```js\n    {\n        responseBody: string;\n    }\n    ```\n\n-   **`req`**\n\n    [Express request object](http://expressjs.com/en/api.html#req)\n\n-   **`res`**\n\n    [Express response object](http://expressjs.com/en/api.html#res)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharkcore%2Ftweenz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsharkcore%2Ftweenz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharkcore%2Ftweenz/lists"}