Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seleb/kitsy
Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags
https://github.com/seleb/kitsy
hack hacking kitsy monkey-patching
Last synced: 3 days ago
JSON representation
Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags
- Host: GitHub
- URL: https://github.com/seleb/kitsy
- Owner: seleb
- Created: 2021-06-13T04:31:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-17T14:07:19.000Z (5 months ago)
- Last Synced: 2024-06-17T15:47:30.211Z (5 months ago)
- Topics: hack, hacking, kitsy, monkey-patching
- Language: TypeScript
- Homepage: https://seleb.github.io/kitsy/
- Size: 317 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# `kitsy`
Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags
Based on work by [@mildmojo](https://github.com/mildmojo) in [bitsy-hacks](https://github.com/seleb/bitsy-hacks)
## How to use
```sh
npm i kitsy
```Example:
```ts
import { kitsy } from "kitsy";// set up hooks/injections
kitsy.before('someGlobal.someFn', () => { console.log('before someGlobal.someFn') });
kitsy.after('someGlobal.someFn', () => { console.log('after someGlobal.someFn') });
kitsy.inject(/(some code)/, 'injected before some code $1 injected after some code');// call
kitsy.applyInjects();
// between applying injections and hooks,
// reinitialize any globals that referred to injected code
kitsy.applyHooks();
```