mimic-fn

中文文档
5.0.0发布于 2023/11/06MITTypeScriptES Module零依赖近 30 天下载 6.3亿

Make a function mimic another one

此软件包已被标记为弃用

Renamed to mimic-function

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. API
  4. mimicFunction(to, from, options?)
  5. Related
mimic-fn

Make a function mimic another one

Useful when you wrap a function in another function and like to preserve the original name and other properties.

Install

$ npm install mimic-fn

Usage

import mimicFunction from 'mimic-fn';

function foo() {}
foo.unicorn = '🦄';

function wrapper() {
    return foo();
}

console.log(wrapper.name);
//=> 'wrapper'

mimicFunction(wrapper, foo);

console.log(wrapper.name);
//=> 'foo'

console.log(wrapper.unicorn);
//=> '🦄'

console.log(String(wrapper));
//=> '/* Wrapped with wrapper() */\nfunction foo() {}'

API

mimicFunction(to, from, options?)

Modifies the to function to mimic the from function. Returns the to function.

name, displayName, and any other properties of from are copied. The length property is not copied. Prototype, class, and inherited properties are copied.

to.toString() will return the same as from.toString() but prepended with a Wrapped with to() comment.

to

Type: Function

Mimicking function.

from

Type: Function

Function to mimic.

options

Type: object

ignoreNonConfigurable

Type: boolean
Default: false

Skip modifying non-configurable properties instead of throwing an error.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

版本与发布记录

mimic-fn 共发布 9 个版本,首次发布于 2016/10/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2023/11/063 年前
4.0.02021/04/085 年前
3.1.02020/07/246 年前
3.0.02019/06/147 年前
2.1.02019/04/017 年前
2.0.02019/03/087 年前

关于 mimic-fn 的常见问题

mimic-fn 是什么?

Make a function mimic another one注意:该包已被作者标记为弃用——Renamed to mimic-function

如何安装 mimic-fn?

在项目目录运行 npm install mimic-fn,或使用 pnpm add / yarn add / bun add。

mimic-fn 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

mimic-fn 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

mimic-fn 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

mimic-fn 可以商用吗?

mimic-fn 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

mimic-fn 的下载量有多少?

根据 npm 官方下载统计,mimic-fn 在 2026/10/06 – 2026/11/04 这 30 天内被下载 626,891,981 次,日均约 20,896,399 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

mimic-fn 还在维护吗?

最新版本 5.0.0 发布于 2023/11/06(3 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2016/10/20。作者已将其标记为弃用,新项目建议寻找替代方案。