{"id":22025710,"url":"https://github.com/dwango-js/advice.js","last_synced_at":"2025-05-07T09:35:45.055Z","repository":{"id":28907152,"uuid":"32432018","full_name":"dwango-js/advice.js","owner":"dwango-js","description":"Simple AOP module","archived":false,"fork":false,"pushed_at":"2015-03-20T13:47:09.000Z","size":141,"stargazers_count":37,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T18:17:06.751Z","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/dwango-js.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":"2015-03-18T02:00:19.000Z","updated_at":"2024-04-17T09:34:40.000Z","dependencies_parsed_at":"2022-08-03T06:15:37.355Z","dependency_job_id":null,"html_url":"https://github.com/dwango-js/advice.js","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/dwango-js%2Fadvice.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwango-js%2Fadvice.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwango-js%2Fadvice.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwango-js%2Fadvice.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwango-js","download_url":"https://codeload.github.com/dwango-js/advice.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252851836,"owners_count":21814227,"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-30T07:19:06.393Z","updated_at":"2025-05-07T09:35:45.029Z","avatar_url":"https://github.com/dwango-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# advice.js\n\n[![Build Status](https://travis-ci.org/dwango-js/advice.js.svg)](https://travis-ci.org/dwango-js/advice.js)\n\nSimple AOP library for both Node.js and browsers.\n\n- [Aspect-oriented programming - Wikipedia](http://en.wikipedia.org/wiki/Aspect-oriented_programming \"Aspect-oriented programming - Wikipedia, the free encyclopedia\")\n\n```js\nfunction base() {}\n\n// compose a new function which calls a function after base returns\nvar fn = advice.after(base, function() {\n  console.log('base was called');\n});\n\n\nvar obj = {\n  foo: function() {}\n};\n\n// redefine a method which calls a function after obj.foo returns\nadvice.after(obj, 'foo', function() {\n  console.log('obj.foo was called');\n});\n```\n\n## Installation\n\n### Node\n\n```sh\n$ npm install advice.js\n```\n\n### Bower\n\n```sh\n$ bower install advice\n```\n\n## Documentation\n\n### advice.before(base, fn) : function\n\nReturn compose a new function which calls a `fn` before `base` returns.\n\nOrder: `fn` -\u003e `base`\n\n### advice.before(obj, method, fn) : void\n\nRedefine the `obj.method` which will be called a `fn` before the original `obj.method` is called.\n\nOrder: `fn` -\u003e `obj.method`\n\n### advice.after(base, fn) : function\n\nReturn compose a new function which calls a `fn` after `base` returns.\n\nOrder: `base` -\u003e `fn`\n\n### advice.after(obj, method, fn) : void\n\nRedefine the `obj.method`  which will be called a `fn` before `obj.method` is called.\n\nOrder: `obj.method` -\u003e  `fn`\n\n### advice.around(base, fn) : function\n\nReturn compose a new function which around the `base` by `fn`.\n\n```js\nfunction base() {}\nvar results = [];\nvar fn = advice.around(base, function(base, value) {\n  var result = 'around: ' + value;\n  // before\n  results.push('before: ' + value);\n  // base\n  base('base was called');\n  // after \n  results.push('after: ' + value);\n  return result;\n});\nfn('foo'); // 'around: foo'\nresults.join(', ');// 'before: foo, base: bar, after: foo'\n```\n\n### advice.around(obj, method, fn) : void\n\nRedefine the `obj.method`  which around `obj.method` by `fn`.\n\n## Tests\n\n```sh\nnpm test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwango-js%2Fadvice.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwango-js%2Fadvice.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwango-js%2Fadvice.js/lists"}