{"id":18583170,"url":"https://github.com/gaoding-inc/runtime-hooks","last_synced_at":"2025-10-05T00:59:08.178Z","repository":{"id":80193231,"uuid":"164798958","full_name":"gaoding-inc/runtime-hooks","owner":"gaoding-inc","description":"🔗 Utils for JS runtime hooking \u0026 injecting.","archived":false,"fork":false,"pushed_at":"2019-01-20T14:52:18.000Z","size":6,"stargazers_count":58,"open_issues_count":0,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-05T00:59:07.698Z","etag":null,"topics":["aop","hof","hook","inject","intercep","javascript","utils"],"latest_commit_sha":null,"homepage":"","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/gaoding-inc.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-09T06:04:44.000Z","updated_at":"2025-04-16T04:30:10.000Z","dependencies_parsed_at":"2023-07-03T20:15:20.606Z","dependency_job_id":null,"html_url":"https://github.com/gaoding-inc/runtime-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gaoding-inc/runtime-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaoding-inc%2Fruntime-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaoding-inc%2Fruntime-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaoding-inc%2Fruntime-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaoding-inc%2Fruntime-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gaoding-inc","download_url":"https://codeload.github.com/gaoding-inc/runtime-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaoding-inc%2Fruntime-hooks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278395909,"owners_count":25979690,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["aop","hof","hook","inject","intercep","javascript","utils"],"created_at":"2024-11-07T00:20:49.948Z","updated_at":"2025-10-05T00:59:08.174Z","avatar_url":"https://github.com/gaoding-inc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Runtime Hooks\n🔗 Utils for JS runtime hooking \u0026 injecting.\n\n\u003cp\u003e\n  \u003ca href=\"https://travis-ci.org/gaoding-inc/runtime-hooks\"\u003e\n    \u003cimg src=\"https://travis-ci.org/gaoding-inc/runtime-hooks.svg?branch=master\"/\u003e\n  \u003c/a\u003e\n  \u003ca href='https://coveralls.io/github/gaoding-inc/runtime-hooks?branch=master'\u003e\n    \u003cimg src='https://coveralls.io/repos/github/gaoding-inc/runtime-hooks/badge.svg?branch=master' alt='Coverage Status'/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://unpkg.com/runtime-hooks/hooks.js\"\u003e\n    \u003cimg src=\"https://img.badgesize.io/https://unpkg.com/runtime-hooks/hooks.js?compression=gzip\u0026amp;label=size\u0026amp;maxAge=300\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://standardjs.com\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/code_style-standard-brightgreen.svg\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"./package.json\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/runtime-hooks.svg?maxAge=300\u0026label=version\u0026colorB=007ec6\u0026maxAge=300\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n## What's This?\nAdding hooks to any function you need!\n\n[中文介绍](https://zhuanlan.zhihu.com/p/54460682)\n\n\n## Usage\n\nInstall via NPM:\n\n``` bash\nnpm install runtime-hooks\n```\n\nBasic usage:\n\n``` js\nimport { withHookBefore } from 'runtime-hooks'\n\nwindow.alert = withHookBefore(window.alert, console.log)\n```\n\n\u003e These utils are mainly designed for advanced usage (logging / testing / debugging...), don't abusing them in business code.\n\n### withHookBefore\n`(originalFn: function, hookFn: function): function`\n\nGiven original function, return a new high-order function that:\n\n1. Calls your customs hook function beforehand.\n2. Calls the original function.\n\nIf your hook function returns `false`, the original function will not be executed. You can replace the reference to original function with the generated function, which makes sense for function hooking:\n\n``` js\nwindow.alert = withHookBefore(window.alert, console.log)\n```\n\n### withHookAfter\n`(originalFn: function, hookFn: function): function`\n\nGiven original function, return a new high-order function that:\n\n1. Calls the original function.\n2. Calls your customs hook function afterwards.\n\n### hookArgs\n`(originalFn: function, argsGetter: function): function`\n\nGiven original function, runs a new high-order function that:\n\n1. Calls `argsGetter` with args of original function.\n2. If `argsGetter` returns an array, replace original args with it, or else keep the args.\n3. Calls original function with these args, returning what it returns.\n\n### hookOutput\n`(originalFn: function, outputGetter: function): function`\n\nGiven original function, runs a new high-order function that:\n\n1. Calls original function and get its output.\n2. Calls `outputGetter` with output, returning what it returns.\n\n\u003e Both `hookOutput` and `withHookAfter` runs after original function. `hookOutput` replaces the output, but `withHookAfter` won't. \n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaoding-inc%2Fruntime-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaoding-inc%2Fruntime-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaoding-inc%2Fruntime-hooks/lists"}