{"id":13411374,"url":"https://github.com/BackendStack21/middleware-if-unless","last_synced_at":"2025-03-14T17:30:40.687Z","repository":{"id":41890936,"uuid":"164021531","full_name":"BackendStack21/middleware-if-unless","owner":"BackendStack21","description":"Invokes connect-like middleware if / unless routing criteria matches. Inspired on express-unless module.","archived":false,"fork":false,"pushed_at":"2024-01-17T16:35:33.000Z","size":127,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-20T03:19:52.192Z","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/BackendStack21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"custom":"https://www.paypal.me/kyberneees"}},"created_at":"2019-01-03T20:49:35.000Z","updated_at":"2024-06-19T00:24:42.285Z","dependencies_parsed_at":"2024-01-17T18:39:15.213Z","dependency_job_id":null,"html_url":"https://github.com/BackendStack21/middleware-if-unless","commit_stats":{"total_commits":29,"total_committers":3,"mean_commits":9.666666666666666,"dds":0.1724137931034483,"last_synced_commit":"5a245438f31243b314003a8d60eba860659c51ab"},"previous_names":["jkyberneees/middleware-if-unless"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackendStack21%2Fmiddleware-if-unless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackendStack21%2Fmiddleware-if-unless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackendStack21%2Fmiddleware-if-unless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackendStack21%2Fmiddleware-if-unless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BackendStack21","download_url":"https://codeload.github.com/BackendStack21/middleware-if-unless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243551282,"owners_count":20309296,"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-07-30T20:01:13.239Z","updated_at":"2025-03-14T17:30:40.425Z","avatar_url":"https://github.com/BackendStack21.png","language":"JavaScript","funding_links":["https://www.paypal.me/kyberneees"],"categories":["Web Development"],"sub_categories":["Javascript"],"readme":"# Introduction\n[![NPM version](https://badgen.net/npm/v/middleware-if-unless)](https://www.npmjs.com/package/middleware-if-unless)\n[![NPM Total Downloads](https://badgen.net/npm/dt/middleware-if-unless)](https://www.npmjs.com/package/middleware-if-unless)\n[![License](https://badgen.net/npm/license/middleware-if-unless)](https://www.npmjs.com/package/middleware-if-unless)\n[![TypeScript support](https://badgen.net/npm/types/middleware-if-unless)](https://www.npmjs.com/package/middleware-if-unless)\n[![Github stars](https://img.shields.io/github/stars/BackendStack21/middleware-if-unless?style=flat)](https://github.com/BackendStack21/middleware-if-unless)\n\n\u003cimg src=\"docs/logo.svg\" width=\"400\"\u003e  \n\nInvokes connect-like middleware if / unless routing criteria match. \n\u003e Inspired by the [express-unless](https://www.npmjs.com/package/express-unless) module. But a lot faster ;)\n\n## Main features\n- Advanced routes matching capabilities. Uses [find-my-way](https://www.npmjs.com/package/find-my-way) or any compatible router to match the routes. \n- `iff`: execute middleware only if routing criteria is a match. Ideal use case: API gateways (see: [fast-gateway](https://www.npmjs.com/package/fast-gateway))\n- `unless`: execute middleware unless routing criteria is a match.\n- Arbitraty chaining of `iff -\u003e unless` of vice-versa.\n- Low overhead, blazing fast implementation. \n\n# Usage \nInstall\n```bash\nnpm i middleware-if-unless\n```\n\nExtending middleware\n```js \nconst iu = require('middleware-if-unless')()\n\nconst middleware = function (req, res, next) {\n  res.body = 'hit'\n\n  return next()\n}\n\n// extend middleware with iff/unless capabilities\niu(middleware)\n```\n## unless\nExecute middleware unless routing criteria is a match:\n```js\nconst app = require('express')()\napp.use(middleware.unless([\n  '/not/allowed/to/hit'\n]))\n\n...\n```\nIn this example, all requests except `[GET] /not/allowed/to/hit` will cause the middleware to be executed.\n\n## iff\nExecute middleware only if routing criteria is a match:\n```js\nconst app = require('express')()\napp.use(middleware.iff([\n  {\n    methods: ['POST', 'DELETE', 'PUT', 'PATCH'],\n    url: '/tasks/:id'\n  }\n]))\n\n...\n```\nIn this example, only a `[POST|DELETE|PUT|PATCH] /tasks/:id` request will cause the middleware to be executed.\n\n# More\n- Website and documentation: https://iff-unless.21no.de","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBackendStack21%2Fmiddleware-if-unless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBackendStack21%2Fmiddleware-if-unless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBackendStack21%2Fmiddleware-if-unless/lists"}