# class-proxy

> The Class Proxy is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).

Latest version **2.0.0** (published 2022-10-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install class-proxy
pnpm add class-proxy
yarn add class-proxy
bun add class-proxy
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-10-15 |
| First published | 2018-02-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 39.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | bluelovers |
| Maintainers | bluelovers |
| Keywords | apply, built-in, class, global, handler, method, npm, object, prop, prototype, proxify, proxy, receiver, reference, reflect, standard, create-by-yarn-tool, create-by-tsdx |

## Links

- npm: https://www.npmjs.com/package/class-proxy
- Repository: https://github.com/bluelovers/class-proxy
- Homepage: https://github.com/bluelovers/class-proxy#readme
- Issues: https://github.com/bluelovers/class-proxy/issues
- npm.io page: https://npm.io/package/class-proxy

## Recent versions

- 2.0.0 (latest) — 2022-10-15
- 1.1.2 — 2019-05-27
- 1.1.1 — 2018-02-19
- 1.1.0 — 2018-02-11
- 1.0.1 — 2018-02-11
- 1.0.0 — 2018-02-11

## README

# class-proxy

> The Class Proxy is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).

`npm install class-proxy`

## api

* [MDN: Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
* [index.d.ts](index.d.ts)

## demo

```ts
import createClassProxy from 'class-proxy';
import { createClassProxy } from 'class-proxy';

var createClassProxy = require("class-proxy/node");
```

```ts
import { implementation as URLImpl } from 'whatwg-url/lib/URL-impl';

let URLImplProxy2 = createClassProxy(URLImpl, {
	get(target, name)
	{
		return target[name];
	},
	set(target, prop, value, receiver)
	{
		if (prop == '_query')
		{
			value._url = target;

			console.log(value);
		}

		target[prop] = value;
		return true;
	},
	ownKeys(target): string[]
	{
		return [
			'href',
			'origin',
			'protocol',
			'username',
			'password',
			'host',
			'hostname',
			'port',
			'pathname',
			'search',
			'hash',
			'searchParams',
		];
	},
	getOwnPropertyDescriptor(target, prop)
	{
		return {
			value: target[prop],
			enumerable: this.ownKeys(target).includes(prop),
			configurable: true,
		};
	},
	construct(target, args)
	{
		if (typeof args[0] == 'string')
		{
			return new target([args[0]]);
		}

		return new target(...args);
	}
});
```

---
_Source: https://npm.io/package/class-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
