https://github.com/vvscode/object-chronicler
Object usage observer
https://github.com/vvscode/object-chronicler
monitoring observer spy testing
Last synced: 4 months ago
JSON representation
Object usage observer
- Host: GitHub
- URL: https://github.com/vvscode/object-chronicler
- Owner: vvscode
- License: mit
- Created: 2023-11-23T21:13:51.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-18T23:28:41.000Z (over 1 year ago)
- Last Synced: 2025-10-11T02:08:44.771Z (9 months ago)
- Topics: monitoring, observer, spy, testing
- Language: TypeScript
- Homepage: https://vvscode.github.io/object-chronicler/
- Size: 622 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Object Chronicler
[](https://www.npmjs.com/package/object-chronicler)
[](https://github.com/vvscode/object-chronicler/actions)
[](https://coveralls.io/github/vvscode/object-chronicler?branch=master)
Object Chronicler empowers developers to gain unprecedented insights into the behavior of their JavaScript objects and functions. Acting as a meticulous observer, this utility allows you to effortlessly create spies that diligently record every interaction within your complex data structures.
### Key Features
- **Observation Made Easy:** Utilize createSpy to seamlessly spy on objects and functions, generating proxies with built-in history tracking.
- **Detailed Histories:** `BasicHistory` provides a simple yet powerful implementation of the History interface, enabling the storage of detailed records about property accesses, method calls, and more.
- **Flexible Testing:** Perfect for unit testing, debugging, and gaining a deeper understanding of your code's runtime behavior.
#### Why Object Chronicler?
Object Chronicler is your ally in navigating the intricacies of JavaScript objects and functions. Whether you're debugging, testing, or simply seeking a deeper understanding of your code's runtime behavior, this library empowers you to chronicle every interaction, ensuring you have the insights needed for confident and effective development.
> Explore new possibilities with Object Chronicler today!
### Installation
```bash
npm install object-chronicler
```
## Usage
### createSpy
`createSpy` is the main function for creating spies on objects or functions. It returns a proxied object with a history property to retrieve the recorded interactions.
```ts
import { createSpy, BasicHistory } from 'object-chronicler';
const obj = {
method1: (x: unknown) => 'result1',
method2: (y: unknown) => 'result2',
};
const history = new BasicHistory();
const spiedObj = createSpy(obj, history);
console.log(spiedObj.method1(1)); // Output: 'result1'
console.log(spiedObj.method2({ b: [] })); // Output: 'result2'
console.log(history.getAll());
````
### BasicHistory
`BasicHistory` is a simple implementation of the `History` interface. It records interactions in a key-value store.
```ts
import { BasicHistory } from 'object-chronicler';
const history = new BasicHistory();
history.put({ type: 'get', key: 'key1' });
history.put({ type: 'set', key: 'key2', value: 'value2' });
console.log(history.getAll());
```
### Contributing
Feel free to contribute by opening issues or pull requests on [the GitHub repository](https://github.com/vvscode/object-chronicler).
#### Keywords
object, chronicler, spy, testing, history, tracking