Scrubber
Cannot get the child of a text node: {"text": "This is my text node."}import { Scrubber } from 'slate'
Scrubber.setScrubber((key, value) => {
if (key === 'text') return '... scrubbed ...'
return value
})Cannot get the child of a text node: {"text": "... scrubbed ..."}Text Randomizer Example
import { Scrubber } from 'slate'
const textRandomizer = (fieldNames: string[]) => (key, value) => {
if (fieldNames.includes(key)) {
if (typeof value === 'string') {
return value.split('').map(generateRandomCharacter).join('')
} else {
return '... scrubbed ...'
}
}
return value
}
const generateRandomCharacter = (): string => {
const chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ1234567890'
return chars.charAt(Math.floor(Math.random() * chars.length))
}
// randomize the 'text' and 'src' fields of any Node that is included in an
// exception thrown by Slate
Scrubber.setScrubber(Scrubber.textRandomizer(['text', 'src']))Last updated