object-chronicler
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Object Chronicler

npm version Deploy Coverage Status

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

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.

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.

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.

Keywords

object, chronicler, spy, testing, history, tracking

Readme

Keywords

Package Sidebar

Install

npm i object-chronicler

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

16.7 kB

Total Files

18

Last publish

Collaborators

  • vvscode