npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kuankuan/deep-proxy

v0.1.0

Published

Recursively proxy some object

Downloads

2

Readme

@kuankuan/deep-proxy

@kuankuan/deep-proxy 是一个工具库,可以代理一个对象及其所有嵌套对象。它提供了一种灵活且可定制的方式,用于拦截和修改对象属性和方法的行为。

安装

你可以通过 npm 安装 @kuankuan/deep-proxy

npm install @kuankuan/deep-proxy

使用方法

要使用 @kuankuan/deep-proxy,你需要从库中导入 getDeepProxy 函数:

import { getDeepProxy } from '@kuankuan/deep-proxy';

代理对象

要代理一个对象,只需将对象和一个选项对象传递给 getDeepProxy 函数:

const target = { foo: 'bar' };
const options = {
  // 在这里定义你的自定义处理程序
};

const proxy = getDeepProxy(target, options);

选项

选项对象允许你为代理对象上的各种操作定义自定义处理程序。每个处理程序都是一个函数,当在对象上执行相应的操作时,该函数将被调用。

以下是可用的处理程序:

  • set:当在对象上设置属性时调用。
  • get:当访问对象上的属性时调用。
  • apply:当在对象上调用函数时调用。
  • construct:当对象被用作构造函数时调用。
  • defineProperty:当在对象上定义属性时调用。
  • deleteProperty:当从对象中删除属性时调用。
  • getOwnPropertyDescriptor:当访问属性的描述符时调用。
  • getPrototypeOf:当访问对象的原型时调用。
  • has:当检查属性是否存在时调用。
  • isExtensible:当检查对象是否可扩展时调用。
  • ownKeys:当访问对象的键时调用。
  • preventExtensions:当使对象不可扩展时调用。
  • setPrototypeOf:当设置对象的原型时调用。

每个处理程序函数接收以下参数:

  • target:被代理的目标对象。
  • keys:表示当前属性路径的键数组。
  • ...其他参数:特定于每个处理程序的额外参数。

示例

下面是一个示例,演示如何使用 @kuankuan/deep-proxy 拦截对象上的属性访问:

const target = { foo: 'bar' };
const options = {
  get(target, keys, p, value, receiverTarget) {
    console.log(`访问了属性 ${p.toString()}。`);
    return value;
  },
};

const proxy = getDeepProxy(target, options);

console.log(proxy.foo); // 输出:"访问了属性 foo。"

贡献

欢迎贡献!如果你发现任何问题或有改进建议,请在 GitHub 仓库上开启一个 issue 或提交一个 pull 请求。

许可证

该项目基于 MulanPSL-2.0 许可证。详细信息请参阅 LICENSE 文件。