Replace text in the capture.
Replaces DOM text in the clone using strings or regular expressions. Stylesheet and script text are left unchanged.
npm install @zumer/snapdom@latest @zumer/snapdom-plugins@latestUsage
import { snapdom } from '@zumer/snapdom';
import { replaceText } from '@zumer/snapdom-plugins/replace-text';
const el = document.querySelector('#target');
const result = await snapdom(el, {
plugins: [replaceText({
replacements: [
{ find: 'DRAFT', replace: 'APPROVED' },
{ find: /\d{4}-\d{2}-\d{2}/, replace: '[REDACTED]' }
]
})]
});
const image = await result.toPng();
document.body.append(image);
Options
| Option | Type | Default | Description |
|---|---|---|---|
replacements | Array<{ find: string|RegExp, replace: string }> | [] | List of find/replace pairs |