-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from GLINCKER/develop
Release v1.1.0
- Loading branch information
Showing
11 changed files
with
213 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
import { useState } from 'react'; | ||
import { Filter, CheckProfanityResult } from '../filters/Filter'; | ||
import { Language } from '../types/Language'; | ||
import { Filter } from '../filters/Filter'; | ||
import { CheckProfanityResult, Language } from '../types/types'; | ||
|
||
interface ProfanityCheckerConfig { | ||
languages?: Language[]; | ||
allLanguages?: boolean; | ||
caseSensitive?: boolean; | ||
wordBoundaries?: boolean; | ||
customWords?: string[]; | ||
replaceWith?: string; | ||
severityLevels?: boolean; | ||
customActions?: (result: CheckProfanityResult) => void; | ||
} | ||
|
||
export const useProfanityChecker = (config?: ProfanityCheckerConfig) => { | ||
const [result, setResult] = useState<CheckProfanityResult | null>(null); | ||
const filter = new Filter(config); | ||
|
||
const checkText = (text: string) => { | ||
setResult(filter.checkProfanity(text)); | ||
const checkResult = filter.checkProfanity(text); | ||
setResult(checkResult); | ||
if (config?.customActions) { | ||
config.customActions(checkResult); | ||
} | ||
}; | ||
|
||
const checkTextAsync = async (text: string) => { | ||
return new Promise<CheckProfanityResult>((resolve) => { | ||
const checkResult = filter.checkProfanity(text); | ||
setResult(checkResult); | ||
if (config?.customActions) { | ||
config.customActions(checkResult); | ||
} | ||
resolve(checkResult); | ||
}); | ||
}; | ||
|
||
return { | ||
result, | ||
checkText | ||
checkText, | ||
checkTextAsync, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { Filter, CheckProfanityResult } from './filters/Filter'; | ||
export { Filter } from './filters/Filter'; | ||
export { useProfanityChecker } from './hooks/useProfanityChecker'; | ||
export type { Language } from './types/Language'; | ||
export type { Language, CheckProfanityResult } from './types/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// src/types/types.ts | ||
export interface CheckProfanityResult { | ||
containsProfanity: boolean; | ||
profaneWords: string[]; | ||
processedText?: string; | ||
severityMap?: { [word: string]: number }; | ||
} | ||
export type Language = | ||
| 'arabic' | ||
| 'chinese' | ||
| 'czech' | ||
| 'danish' | ||
| 'english' | ||
| 'esperanto' | ||
| 'finnish' | ||
| 'french' | ||
| 'german' | ||
| 'hindi' | ||
| 'hungarian' | ||
| 'italian' | ||
| 'japanese' | ||
| 'korean' | ||
| 'norwegian' | ||
| 'persian' | ||
| 'polish' | ||
| 'portuguese' | ||
| 'russian' | ||
| 'turkish' | ||
| 'swedish' | ||
| 'thai'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.