@00rez/form-runner 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -405,6 +405,73 @@ import { transformErrors } from '@00rez/form-runner';
|
|
|
405
405
|
const errors = transformErrors(rawErrors, schema, uiSchema);
|
|
406
406
|
```
|
|
407
407
|
|
|
408
|
+
### Interpolation Utilities
|
|
409
|
+
|
|
410
|
+
The library provides utilities for dynamic text interpolation with support for multiple interpolation styles:
|
|
411
|
+
|
|
412
|
+
#### interpolate
|
|
413
|
+
|
|
414
|
+
The original interpolation function supporting `{{key}}` patterns for language dictionaries and `[[key]]` patterns for global data:
|
|
415
|
+
|
|
416
|
+
```tsx
|
|
417
|
+
import { interpolate } from '@00rez/form-runner';
|
|
418
|
+
|
|
419
|
+
// Replace {{key}} with language data and [[key]] with global data
|
|
420
|
+
const result = interpolate(
|
|
421
|
+
{ label: 'Hello {{name}}', value: '[[globalVar]]' },
|
|
422
|
+
{ name: 'John' }, // Language/data dictionary
|
|
423
|
+
{ globalVar: 'Global!' } // Global data (optional)
|
|
424
|
+
);
|
|
425
|
+
// Result: { label: 'Hello John', value: 'Global!' }
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
#### interpolateWithI18next
|
|
429
|
+
|
|
430
|
+
A string-focused function with i18next-compatible format. Supports `{{variable}}` patterns with fallback to global data:
|
|
431
|
+
|
|
432
|
+
```tsx
|
|
433
|
+
import { interpolateWithI18next } from '@00rez/form-runner';
|
|
434
|
+
|
|
435
|
+
const result = interpolateWithI18next(
|
|
436
|
+
'Hello {{name}}, you have {{count}} messages',
|
|
437
|
+
{ name: 'John', count: 5 },
|
|
438
|
+
{ count: 10 } // Fallback global data (optional)
|
|
439
|
+
);
|
|
440
|
+
// Result: 'Hello John, you have 5 messages'
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
**Features:**
|
|
444
|
+
- Supports nested object access with dot notation: `{{user.profile.name}}`
|
|
445
|
+
- Returns numeric values as strings
|
|
446
|
+
- Falls back to `globalData` if value not found in primary values
|
|
447
|
+
- Returns unmatched patterns unchanged
|
|
448
|
+
|
|
449
|
+
#### interpolateObjectWithI18next
|
|
450
|
+
|
|
451
|
+
Recursively interpolates all strings in objects and arrays using i18next format:
|
|
452
|
+
|
|
453
|
+
```tsx
|
|
454
|
+
import { interpolateObjectWithI18next } from '@00rez/form-runner';
|
|
455
|
+
|
|
456
|
+
const schema = {
|
|
457
|
+
title: 'Welcome {{userName}}',
|
|
458
|
+
properties: {
|
|
459
|
+
message: { type: 'string', title: 'Message: {{itemCount}} items' },
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
const result = interpolateObjectWithI18next(
|
|
464
|
+
schema,
|
|
465
|
+
{ userName: 'Alice', itemCount: 42 }
|
|
466
|
+
);
|
|
467
|
+
// Result: { title: 'Welcome Alice', properties: { message: { ... title: 'Message: 42 items' } } }
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Use cases:**
|
|
471
|
+
- Interpolating entire form schemas
|
|
472
|
+
- Dynamic form configuration with i18next
|
|
473
|
+
- Maintaining structure while replacing text values
|
|
474
|
+
|
|
408
475
|
## Custom Validation
|
|
409
476
|
|
|
410
477
|
Use the validator's composition to add custom keywords:
|
|
@@ -585,7 +652,7 @@ export default function App() {
|
|
|
585
652
|
|
|
586
653
|
## Contributing
|
|
587
654
|
|
|
588
|
-
|
|
655
|
+
n/a
|
|
589
656
|
|
|
590
657
|
## License
|
|
591
658
|
|