Class: Lodash

轻量 Lodash 工具集。 Lightweight Lodash-like utilities.

说明: Notes:

  • 这是 Lodash 的“部分方法”简化实现,不等价于完整 Lodash
  • This is a simplified subset, not a full Lodash implementation
  • 各方法语义可参考 Lodash 官方文档
  • Method semantics can be referenced from official Lodash docs
  • 导入时建议使用 Lodash as _,遵循 lodash 官方示例惯例
  • Use Lodash as _ when importing, following official lodash example convention

参考: Reference:

Constructors

Constructor

new Lodash(): Lodash

Returns

Lodash

Methods

escape()

static escape(string): string

HTML 特殊字符转义。 Escape HTML special characters.

Parameters

string

string

输入文本 / Input text.

Returns

string

See


get()

static get(object?, path?, defaultValue?): any

按路径读取对象值。 Get object value by path.

Parameters

object?

any = {}

目标对象 / Target object.

path?

string | string[]

路径 / Path.

defaultValue?

any = undefined

默认值 / Default value.

Returns

any

See


merge()

static merge(object, ...sources): any

递归合并源对象的自身可枚举属性到目标对象 Recursively merge source enumerable properties into target object.

Parameters

object

any

目标对象

sources

...any[]

源对象(可多个)

Returns

any

返回合并后的目标对象

Description

简化版 lodash.merge,用于合并配置对象

Description

A simplified lodash.merge for config merging.

适用情况:

  • 合并嵌套的配置/设置对象
  • 需要深度合并而非浅层覆盖的场景
  • 多个源对象依次合并到目标对象

限制:

  • 仅处理普通对象 (Plain Object),不处理 Date/RegExp 等特殊对象
  • Map/Set 仅支持同类型合并,不递归内部值
  • 数组会被直接覆盖,不会合并数组元素
  • 不处理循环引用,可能导致栈溢出
  • 不复制 Symbol 属性和不可枚举属性
  • 不保留原型链,仅处理自身属性
  • 会修改原始目标对象 (mutates target)

See

Example

const target = { a: { b: 1 }, c: 2 };
const source = { a: { d: 3 }, e: 4 };
Lodash.merge(target, source);
// => { a: { b: 1, d: 3 }, c: 2, e: 4 }

omit()

static omit(object?, paths?): any

删除对象指定路径并返回对象。 Omit paths from object and return the same object.

Parameters

object?

any = {}

目标对象 / Target object.

paths?

string | string[]

要删除的路径 / Paths to remove.

Returns

any

See


pick()

static pick(object?, paths?): any

仅保留对象指定键(第一层)。 Pick selected keys from object (top level only).

Parameters

object?

any = {}

目标对象 / Target object.

paths?

string | string[]

需要保留的键 / Keys to keep.

Returns

any

See


set()

static set(object, path, value): any

按路径写入对象值。 Set object value by path.

Parameters

object

any

目标对象 / Target object.

path

string | string[]

路径 / Path.

value

any

写入值 / Value.

Returns

any

See


toPath()

static toPath(value): string[]

将点路径或数组下标路径转换为数组。 Convert dot/array-index path string into path segments.

Parameters

value

string

路径字符串 / Path string.

Returns

string[]

See


unescape()

static unescape(string): string

HTML 实体反转义。 Unescape HTML entities.

Parameters

string

string

输入文本 / Input text.

Returns

string

See


unset()

static unset(object?, path?): boolean

删除对象路径对应的值。 Remove value by object path.

Parameters

object?

any = {}

目标对象 / Target object.

path?

string | string[]

路径 / Path.

Returns

boolean

See