Apply Sanity patches to a value
npm install @portabletext/patchesimport applyPatch, {applyAll} from '@portabletext/patches'
// Apply a single patch
const result = applyPatch(
{title: 'Hello'},
{
type: 'set',
path: ['title'],
value: 'Hello, world!',
},
)
// Apply multiple patches
const result = applyAll({count: 0}, [
{type: 'inc', path: ['count'], value: 1},
{type: 'inc', path: ['count'], value: 1},
])set- Set a value at a pathsetIfMissing- Set a value only if it doesn't existunset- Remove a value at a pathinsert- Insert items into an arrayinc/dec- Increment or decrement a numberdiffMatchPatch- Apply a diff-match-patch string