How do i add filters to replication as I don't want to transfer all documents from source to target?

So for now I have setup the replication for my app as

setupReplications(options) {
const sgUrl = http://${SG_HOST};
const source = options || sgUrl;

return this.manager.server.post_replicate({body: {source, target: DB_NAME, continuous: true}})
  .then(res => this.manager.server.post_replicate({body: {source: DB_NAME, target: source, continuous: true}}))
  .catch(e => console.warn('setup replications', e));

},

but now I want to stop some of the docs with specific type to not to be replicated from local to remote.

I have found one solution for this Filtered Replication

and I am confused how to add the following filter function to design_doc

function(doc, req) {
if (doc.type && doc.type == “foo”) {
return false;
} else {
return true;
}
}

So that it will stop replication of docs with type foo?