Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Censoring everything except the first and last char #144

Open
buckydroid opened this issue Mar 31, 2022 · 1 comment
Open

Censoring everything except the first and last char #144

buckydroid opened this issue Mar 31, 2022 · 1 comment

Comments

@buckydroid
Copy link

Let's say the word is fook,

I wanna censor it to f**k not ****.

Is it possible through this?

I mean if not is there any way to get the filtered word. So I can replace that substring manually in javascript?

@ozair-dev
Copy link

You can pass custom replaceRegex and placeHolder arguments to the constructor to get the desired result. Here is your solution

import Filter from "bad-words";

const replaceRegex = /(?<=.).+(?=.)/
const placeHolder = (str)=>("*".repeat(str.length))

var filter = new Filter({replaceRegex, placeHolder});

console.log(filter.clean("This is sh!t"))

output: This is s**t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants