Skip to content

Commit 5d62ae9

Browse files
committed
Docs: Describe extensions
1 parent 9e83a9c commit 5d62ae9

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Declarative Mapper is a JSON data transformation and object mapping library for
2626
- [Tuple Arrays](#tuple-arrays)
2727
- [Context Switching](#context-switching)
2828
- [Dynamic Output Keys](#dynamic-output-keys)
29+
- [Extensions](#extensions)
2930
- [Complex Mapping Example](#complex-mapping-example)
3031

3132
### Reasoning
@@ -357,6 +358,27 @@ To keep `${...}` as a literal key (without interpolation), escape it with a lead
357358
}
358359
```
359360

361+
## Extensions
362+
363+
Use `extensions` to pass helper functions and lookup data into mapping expressions:
364+
365+
```ts
366+
const mapper = createMapper({
367+
code: 'catalog[itemId]',
368+
normalizedName: 'normalize(name)'
369+
}, {
370+
extensions: {
371+
catalog: { A1: 'SKU-001' },
372+
normalize: (s: string) => s.trim().toUpperCase()
373+
}
374+
});
375+
```
376+
377+
Extension keys are available as globals in expressions.
378+
379+
If an extension key conflicts with an input field name, mapper throws an error.
380+
381+
360382

361383
## Complex Mapping Example
362384

0 commit comments

Comments
 (0)