Skip to content

vesuva is a JavaScript library that uses dynamic proxies to reconstruct method chains as strings

License

Notifications You must be signed in to change notification settings

kanamone/vesuva

Repository files navigation

vesuva Build Status Version Downloads

vesuva

vesuva (/vɛˈsuːvə/) is a JavaScript library that uses dynamic proxies to reconstruct method chains as strings.

Installation

npm install vesuva

Usage

To use Vesuva, pass the name of the receiver to the recorder function:

import { recorder } from 'vesuva'

const obj = recorder('obj')
console.log(obj.method1().method2('arg').toString())
// Output: obj.method1().method2("arg")

NOTE:
vesuva does not consider the aesthetics of the resulting code.
If you need beauty code, please apply your preferred formatter to vesuva's output.

Type-safe Usage

recorder function uses generics to enable vesuva to act as a type-safe wrapper for existing library types:

import { recorder } from 'vesuva'
import type { z as _z } from 'zod'

const z = recorder<typeof _z>('z');

const BaseTeacher = z.object({
  students: z.array(z.string())
});

const HasID = z.object({
  id: z.string()
});

const Teacher = BaseTeacher.merge(HasID);

console.log(Teacher.toString())
// Output: z.object({students:z.array(z.string())}).merge(z.object({id:z.string()}))

How It Works

vesuva uses JavaScript's Proxy object to intercept method calls and other interactions, allowing it to record and construct a string representation of the entire method chain dynamically.

Contributing

Contributions to Vesuva are welcome! Please feel free to fork the repository, make your changes, and submit a pull request.

License

vesuva is released under the MIT License. See the LICENSE file in the repository for more details.

About

vesuva is a JavaScript library that uses dynamic proxies to reconstruct method chains as strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published