Home > scrubbr > Scrubbr > clone
Scrubbr.clone() method¶
Create a duplicate version of this scrubbr with all the same serializers, global context, and options.
This is useful to create a global scrubbr with serializer that should be used on all data, and all other scrubbrs are created from it for more specific use-cases.
Signature:
clone(options?: ScrubbrOptions): Scrubbr;
Parameters¶
Parameter | Type | Description |
---|---|---|
options | ScrubbrOptions |
Returns:
Scrubbr
Example¶
// Global config
const scrubbr = new Scrubbr('./schema.ts');
scrubbr.addTypeSerializer('User', userSerializer);
// API endpoint
function commentListApi() {
const commentScrubbr = scrubbr.clone();
commentScrubbr.addTypeSerializer('Comment', commentSerializer);
return scrubbr.serialize('CommentList', data);
}