Glin-Profanity Tool

    Getting Started with Glin-Profanity

    1

    Installation

    To install Glin-Profanity, run the following command in your project directory:

    npm install glin-profanity

    or

    yarn add glin-profanity
    2

    Basic Usage

    Once installed, you can use Glin-Profanity to filter text inputs across your application. Here's a simple example of how to set it up in a React component:

    import React, { useState } from 'react';
    import { useProfanityChecker } from 'glin-profanity';
    
    const MyComponent = () => {
      const [text, setText] = useState('');
      const { result, checkText } = useProfanityChecker();
    
      const handleCheck = () => {
        checkText(text);
      };
    
      return (
        <div>
          <input
            type="text"
            value={text}
            onChange={(e) => setText(e.target.value)}
            placeholder="Type your text here"
            className="p-2 border rounded"
          />
          <button onClick={handleCheck} className="ml-2 p-2 bg-blue-500 text-white rounded">Check Profanity</button>
          {result && (
            <div>
              <p>Contains Profanity: {result.containsProfanity ? 'Yes' : 'No'}</p>
              {result.containsProfanity && (
                <p>Profane Words: {result.profaneWords.join(', ')}</p>
              )}
            </div>
          )}
        </div>
      );
    };

    This example shows how to integrate the profanity checker into a basic React component.

    3

    Customization

    Glin-Profanity allows you to customize its behavior to match your platform's requirements. Below are some common customizations:

    • Define custom words to include in the profanity filter.
    • Adjust case sensitivity and word boundary checks.
    • Enable or disable specific language filters.
    const { result, checkText } = useProfanityChecker({
      allLanguages: true,
      caseSensitive: false,
      wordBoundaries: true,
      customWords: ['customword1', 'customword2']
    });

    In this example, Glin-Profanity is configured to check all languages, consider word boundaries, and include custom words.

    4

    Filter Class

    Constructor

    new Filter(config?: { 
      languages?: Language[]; 
      allLanguages?: boolean;
      caseSensitive?: boolean;
      wordBoundaries?: boolean;
      customWords?: string[];
      replaceWith?: string;
      severityLevels?: boolean; 
      ignoreWords?: string[];
      logProfanity?: boolean; 
    });

    The Filter class can be configured with an optional configuration object.

    • languages: An array of languages to check for profanities.
    • allLanguages: A boolean indicating whether to check for all languages.
    • caseSensitive: A boolean indicating whether the profanity check should be case-sensitive.
    • wordBoundaries: A boolean indicating whether to consider word boundaries when checking for profanities.
    • customWords: An array of custom words to include in the profanity check.
    • replaceWith: A string to replace profane words with.
    • severityLevels: A boolean indicating whether to include severity levels for profane words.
    • ignoreWords: An array of words to ignore in the profanity check.
    • logProfanity: A boolean indicating whether to log detected profane words.
    5

    useProfanityChecker Hook

    A custom React hook for using the profanity checker.

    Parameters

    • config: An optional configuration object.
      • languages: An array of languages to check for profanities.
      • allLanguages: A boolean indicating whether to check for all languages.
      • caseSensitive: A boolean indicating whether the profanity check should be case-sensitive.
      • wordBoundaries: A boolean indicating whether to consider word boundaries when checking for profanities.
      • customWords: An array of custom words to include in the profanity check.
      • replaceWith: A string to replace profane words with.
      • severityLevels: A boolean indicating whether to include severity levels for profane words.
      • ignoreWords: An array of words to ignore in the profanity check.
      • logProfanity: A boolean indicating whether to log detected profane words.
      • customActions: A function to execute custom actions when profanity is detected.

    Return Value

    • result: The result of the profanity check.
    • checkText: A function to check a given text for profanities.
    • checkTextAsync: A function to check a given text for profanities asynchronously.
    const { result, checkText, checkTextAsync } = useProfanityChecker(config);
    6

    Integration

    Integrating Glin-Profanity into your project is straightforward. Follow these steps:

    1. Import the necessary components and hooks from the library.
    2. Set up the profanity checker in your component or service.
    3. Use the checker in your input handlers to validate text for profanities.

    By following these steps, you can effectively prevent profane content from being submitted through your forms or real-time inputs.

    7

    Benefits

    By using Glin-Profanity, you ensure a respectful and clean environment on your platform:

    • Protect users from offensive language.
    • Improve the overall quality of user-generated content.
    • Enhance the user experience by preventing abuse.

    Useful Links