Introduction
@silver-formily/path is the standalone path system used by Formily. It solves three related problems in one place:
- Normalize strings, arrays, regular expressions, and matcher functions into one path abstraction.
- Read and write nested data safely with
getIn,setIn, anddeleteIn. - Express field matching rules with a richer pattern language.
Installation
bash
pnpm add @silver-formily/pathbash
npm install @silver-formily/pathExample
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'