From 775deffedfd7aa806e0f66dabfb08d47c3fb3893 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 3 Feb 2026 13:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=B3=E4=BA=8E=20merge=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E8=AF=A6=E7=BB=86=E8=AF=B4=E6=98=8E=E5=92=8C?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f6f511b..d0c4d00 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,54 @@ # test-estoolkit-merge -To install dependencies: +这是一个测试 [es-toolkit](https://es-toolkit.sugarat.top/) 库中 `merge` 函数功能的项目。 + +## 安装依赖 ```bash bun install ``` -To run: +## 运行测试 ```bash -bun run index.ts +bun run src/index.ts ``` -This project was created using `bun init` in bun v1.3.6. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. +## 关于 merge + +`merge` 函数用于深度合并多个对象或数组。 + +### 数组合并 + +将多个数组合并成一个新数组: + +```typescript +import { merge } from 'es-toolkit'; + +const arr1 = [1, 2, 3]; +const arr2 = [4, 5, 6]; +const merged = merge(arr1, arr2); // [1, 2, 3, 4, 5, 6] +``` + +### 对象合并 + +深度合并多个对象,后者的属性会覆盖前者: + +```typescript +const obj1 = { a: 1, b: 2, f: { g: { b: 1 } } }; +const obj2 = { b: 3, c: 4, f: { g: { d: 5 }, d: '1' } }; + +const merged = merge(obj1, obj2); +// 结果: { a: 1, b: 3, c: 4, f: { g: { b: 1, d: 5 }, d: '1' } } +``` + +### 特性 + +- **深度合并**:嵌套对象也会被深度合并 +- **多参数**:支持合并多个对象/数组 +- **不可变性**:返回新对象/数组,不修改原数据 + +## 相关链接 + +- [es-toolkit 官方文档](https://es-toolkit.sugarat.top/) +- [Bun](https://bun.sh)