Prop-Proxy allows you to intercept getters and setters of class attributes through decorators

Overview

Prop-Proxy

Proxy for class properties

npm version unpkg install size

Prop-Proxy allows you to intercept getters and setters of class attributes through decorators

Installation

This package need to be used with Typescript

npm install prop-proxy --save
yarn add prop-proxy

Configuration

You need to enable in tsconfig.json:

{
    "experimentalDecorators": true, 
    "emitDecoratorMetadata": true
}

Usage

import { usePropertyProxy } from 'prop-proxy'

type PartialPick<T, K extends keyof T> = Partial<T> & Pick<T, K>

interface Struct {
    title: string;
    isActive: boolean;
}

type Params = PartialPick<Struct, 'title'> //isActive is optional param in constructor

const { Property, proxy } = usePropertyProxy<Struct>();

class Category implements Struct {
    @Property()
    title!: string;

    @Property()
    isActive!: boolean;

    constructor({title, isActive}: Params){
        Object.assign(this, {title, isActive})
    }
}

//getter intercept
proxy.getTitle((value) => `other_${value}`)

//setter intercept
proxy.setIsActive(({setValue, value}) => value ? setValue(value) : setValue(true));

const category = new Category({title: 'title'})

console.log(category.title) // output: other_title

console.log(category.isActive) // output: true

License

MIT Free Software, Yeah!

You might also like...

Group together Tailwind CSS modifiers like focus, peer-checked, dark:hover and more with HTML attributes ๐Ÿ‘ฉโ€๐Ÿš€

Tailwind CSS Group Classes Group together Tailwind CSS modifiers like focus, peer-checked, dark:hover and more with HTML attributes ๐Ÿ‘ฉโ€๐Ÿš€ Using with a

Sep 15, 2022

"To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. You will build a simple website that allows for doing that, and you will do it using ES6 and Webpack!

To-do-list Description "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark t

Oct 18, 2022

WordPress Gutenberg plugin to display the attributes for the currently selected block in the Document sidebar.

WordPress Gutenberg plugin to display the attributes for the currently selected block in the Document sidebar.

Block X-ray Attributes Stable Tag: 1.2.0 Requires at least: 5.5 Tested up to: 5.9 Requires PHP: 7.2 License: GPL v2 or later Tags: block attributes, g

Mar 18, 2022

Using a RPI 3b+ to create a PT camera accessible through Windows browser and controllable through MQTT

web-camera_PT A Web flask server converts the MJPEG stream from RPI to JPG img using opencv, then display in browser. Controls added to move Camera in

Dec 20, 2022

PublisherConnector is a class object that allows you to interact with the CHILI Publisher editorObject via postMessage without the complexity of postMessage.

PublisherConnector is a class object that allows you to interact with the CHILI Editor editorObject via postMessage without the complexity of postMessage.

Nov 24, 2022

An easy-to-use jQuery plugin that allows the user to pick an icon from a responsive icon browser and shows the corresponding icon class in an input element.

Font Awesome Browser An easy-to-use jQuery plugin that allows the user to pick an icon from a responsive icon browser and shows the corresponding icon

May 1, 2021

To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. I build a simple website that allows for doing that, and I do it using ES6 and Webpack!

To-do list

Project Name : TO-Do list "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mar

Aug 22, 2022
Owner
Leonardo Kaynan
Leonardo Kaynan
๐Ÿ™ˆ Intercept stdout for Next.js

next-intercept-stdout Next.js plugin to intercept stdout Justification ?? This module wraps intercept-stdout as the form of the Next.js plugin. ???? W

Junho Yeo 12 Nov 9, 2022
An example web extension, using MockRTC to intercept & debug your own WebRTC traffic

MockRTC WebExtension Example Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S), WebRTC, and more This is an example web e

HTTP Toolkit 3 Oct 14, 2022
Project implements decorators for oak like Nest.js.

oak decorators Project implements decorators like implementation of Nest.js for Deno's web framework oak. Usage The following are the core files that

akihiro tanaka 5 Dec 5, 2022
Journeys is a django based community-focused website that allows users to bookmark URLs (through chrome extension) and share their journeys through timelines.

Journeys is a django based community-focused website that allows users to bookmark URLs (through chrome extension) and share their journeys through timelines. A timeline is a collection of links that share a common topic or a journey of building and learning something new. Users can create timelines, share them publicly, and explore resources.

Students' Web Committee 14 Jun 13, 2022
proxy ๐Ÿฆ„ yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy ?? yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner. Batteries are included, Content Spinning and Caching Engine, all housed within a stunning web GUI. A unique high-performance, plug-and-play, multi-threaded website mirror and article spinner

4D/าต.com Dashboards 13 Dec 30, 2022
Proxy but misspelled -- closed proxy for the internet

pyrox Proxy that runs on Cloudflare Workers. Setup Install wrangler2. npm install wrangler. Generate a public Ed25519 key, exported under SPKI mode wi

bots.gg 10 Sep 9, 2022
A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes!

(jQuery) Uniform A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes! Works well with jQuery 1.6+, but we

Audith Softworks 2.2k Jan 2, 2023
A pure javascript class for paginating through any number of DOM elements

PurePajinate A pure javascript class for paginating through any number of DOM elements. Inspired by Pajinate, a plugin for jQuery. Options Option Type

Olivier Buisard 3 Nov 21, 2022
๐Ÿ„โ€โ™‚๏ธ Proxy POST/PUT/PATCH requests through a GET request

??โ€โ™‚๏ธ to-GET Proxy POST/PUT/PATCH requests through a GET request Usage Base URL: https://toget.mihir.ch Endpoint: /:method Supported methods (case ins

Mihir Chaturvedi 4 Oct 2, 2022
Serialize an HTML Form to a JavaScript Object, supporting nested attributes and arrays.

jquery.serializeJSON Adds the method .serializeJSON() to jQuery to serializes a form into a JavaScript Object. Supports the same format for nested par

Mario Izquierdo 1.7k Dec 12, 2022