介绍
@silver-formily/path 是 Formily 路径系统的独立实现。它同时解决了三类问题:
- 把字符串、数组、正则、matcher 函数统一成同一种路径抽象。
- 在对象和数组中安全地
getIn/setIn/deleteIn。 - 用一套更强的模式语法描述字段匹配规则。
提示
这是一个 formily 框架内部使用的依赖,对普通用户来说只要熟悉Pattern 语法即可。
安装
提示
大部分情况下这个包不用单独安装,他是 core 的依赖,会跟随core一起安装。
bash
pnpm add @silver-formily/pathbash
npm install @silver-formily/path例子
ts
import { Path } from '@silver-formily/path'
const values = {
user: {
profile: {
nickname: 'silver',
},
},
}
Path.getIn(values, 'user.profile.nickname')
// 'silver'
Path.setIn(values, 'user.profile.city', 'Shanghai')
// values.user.profile.city === 'Shanghai'