{"id":18429440,"url":"https://github.com/bigpipe/supply","last_synced_at":"2025-04-07T17:33:03.932Z","repository":{"id":20424090,"uuid":"23700603","full_name":"bigpipe/supply","owner":"bigpipe","description":"Supply your library with plugin and middleware management.","archived":false,"fork":false,"pushed_at":"2020-10-26T13:11:17.000Z","size":47,"stargazers_count":4,"open_issues_count":4,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T17:44:46.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/bigpipe.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":"2014-09-05T11:25:49.000Z","updated_at":"2022-12-18T04:09:50.000Z","dependencies_parsed_at":"2022-09-05T13:21:01.734Z","dependency_job_id":null,"html_url":"https://github.com/bigpipe/supply","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fsupply","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fsupply/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fsupply/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fsupply/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigpipe","download_url":"https://codeload.github.com/bigpipe/supply/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247697989,"owners_count":20981282,"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-11-06T05:17:11.032Z","updated_at":"2025-04-07T17:33:03.659Z","avatar_url":"https://github.com/bigpipe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Supply\n\n[![Version npm][version]](http://browsenpm.org/package/supply)[![Build Status][build]](https://travis-ci.org/bigpipe/supply)[![Dependencies][david]](https://david-dm.org/bigpipe/supply)[![Coverage Status][cover]](https://coveralls.io/r/bigpipe/supply?branch=master)\n\n[from]: https://img.shields.io/badge/from-bigpipe.io-9d8dff.svg?style=flat-square\n[version]: http://img.shields.io/npm/v/supply.svg?style=flat-square\n[build]: http://img.shields.io/travis/bigpipe/supply/master.svg?style=flat-square\n[david]: https://img.shields.io/david/bigpipe/supply.svg?style=flat-square\n[cover]: http://img.shields.io/coveralls/bigpipe/supply/master.svg?style=flat-square\n\nSupply is a minimal but high performance middleware system for Node.js. It's\nextremely flexible in term of usage.\n\n## Installation\n\n```\nnpm install --save supply\n```\n\n## Usage\n\nIn all examples we assume that you've already required and created your first\n`supply` instance using:\n\n```js\n'use strict';\n\nvar Supply = require('supply')\n  , supply = new Supply();\n```\n\nExtending the `Supply` instance can be done using the `extend` method which is\nexposed on the `Supply` constructor:\n\n```js\nvar MySupply = Supply.extend({\n  another: function method() {\n    // do stuff\n  }\n});\n```\n\nSo you could use this pattern to build your own framework or module on top of a\nmiddleware system. Or override methods.\n\n#### length\n\nTo see how many layers are in your middleware system, you can check the\n`.length` property.\n\n```js\nsupply.length; // 0\nsupply.use(function foo() {});\nsupply.length; // 1\n```\n\n#### use\n\nAdd a new middleware layer to the stack. This method accepts 3 arguments:\n\n1. `name`, Name of the middleware layer so we can easily remove it again if\n   needed. If no name is provided we attempt to extract it from the supplied\n   function. So if you have `function foobar() {}` as middleware we will use\n   `foobar` as name.\n2. `fn`, Function which should be executed every. Please note that the callbacks\n   will not have their `this` value set to `supply`.\n3. `opts`, Optional object which allows you to further configure the middleware\n   handling. The following options are currently supported:\n   - **at** Specify the index or name where this layer should be added at. If a\n   name is supplied we will resolve it back to the it's current index.\n\nWhen you add a new middleware layer it will always be added as last item unless\nyou've specified the `at` option.\n\n```js\nsupply.use('foo', function (arg) {\n  console.log('arg', arg, 'foo');\n});\n\nsupply.use('bar', function (arg, next) {\n  console.log('arg', arg, 'bar');\n  next();\n});\n\nsupply.each('pez', function () {\n  console.log('done');\n});\n```\n\nIn the example above you can see that we support async and sync execution of the\nmiddleware. This is decided based on the amount of arguments supplied in the\n`each` method (excluding it's optional callback). If you call `each` with 2\narguments e.g. `supply.each(1,2)` then your async middleware layer needs 3\narguments where the last argument is the callback function.\n\nThe supplied middleware layers are also able to stop the execution of the rest\nof the middleware layers. In async mode you can supply the truthy value as second\nargument to the callback:\n\n```js\nsupply.use(function example(arg, next) {\n  next(undefined, true);\n});\n```\n\nIf you have a sync function you can just return true:\n\n```js\nsupply.use(function example(arg) {\n  return true;\n});\n```\n\nError handling also build in. The async middleware layers can just call the\nsupplied callback with an error as first argument while the sync layers can just\nthrow errors as they are wrapped in a `try {} catch (e) {}` statement.\n\n#### before\n\nSame as the `use` method, but it automatically sets the `at` option to `0` so it\nwill be inserted at the beginning of the stack instead of the end. It also\naccepts all the same arguments, except for the `at` option as that will\nforcefully be overridden.\n\n```js\nsupply.before('xxx', function yyy() {});\n```\n\n#### remove\n\nRemove a middleware layer from the stack based on the name. The method will\nreturn a boolean as indication if the layer was found and removed successfully.\n\n```js\nsupply.use('foo', function bar() {});\nsupply.remove('foo');\n```\n\n#### each\n\nCall all layers in the middleware stack with the supplied arguments. There is no\nfixed limit to the amount of arguments that can be supplied. If the last\nargument is a function we automatically assume that this should be the callback\nfor when all middleware layers are executed. The callback should follow the\nerror first callback pattern.\n\n```js\nsupply.each('foo', 'bar'); // No callback\nsupply.each('beep', 'boop', function done(err, early) {\n\n});\n```\n\nAs you can see from the example above the callback receives two arguments. The\nerror and an boolean which will indicate the callback was called early so one of\nthe layers stopped the iteration.\n\n#### indexOf\n\nFind the location of a middleware layer in the stack based on the name. This is\nused internally but might be useful for you in some use cases as well.\n\n```js\nsupply.use('bar', function banana() {});\nsupply.use('foo', function bar() {});\n\nvar index = supply.indexOf('foo'); // 1 (it's zero based)\n```\n\n#### destroy\n\nDestroy the middleware instance which removes all middleware layers, internal\nreferences and object we've setup. Don't call this if you still have a `each`\nrunning.\n\n```js\nsupply.destroy();\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Fsupply","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigpipe%2Fsupply","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Fsupply/lists"}