JSPM

special-character-transliteration

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 1
    • Score
      100M100P100Q33051F
    • License ISC

    This package sanitizes user input for creating slugs, URLs, or standard English text by converting special characters from 31 languages into English equivalents and removing emojis.

    Package Exports

      This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (special-character-transliteration) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

      Readme

      SpecialCharacterTransliteration

      Package Name: special-character-transliteration
      Version: 1.0.0 Author: Saif ur Rahman

      Functionality

      The special-character-transliteration package provides utility functions to:

      1. Normalize special characters: Convert special characters such as Æ, Ŧ, etc., to their simple English transliterations.
      2. Remove emojis: Automatically detect and remove emojis from any string input😎❌.

      This package is useful for sanitizing user input, especially for creating slugs, URLs, or handling input that requires standard English text.

      How to Install

      You can install the package via npm by running:

      npm install special-character-transliteration
      
      
      Step-by-Step Guide to Use the Package
      
        Step 1: Install the Package
          Copy the following command in your terminal to install the special-character-transliteration package in your project:
       
            npm install special-character-transliteration
      
        Step 2: Import the Package
          In your .ts or .js file, import the SpecialCharTransliterator class from the package like this:
      
            import { SpecialCharacterTransliterator } from 'special-character-transliteration';
      
      
        Step 3: Initialize the Transliterator
          Create an instance of SpecialCharacterTransliterator to access its methods.
      
            const transliterator = new SpecialCharacterTransliterator();
      
      
        Step 4: Normalize Special Characters
          To replace special characters with their English transliterations, use the normalizeString method.
      
            const input = "Æ Ŧ special characters";
            const result = transliterator.normalizeString(input);
            console.log(result);  // Output: "AE T special characters"
      
      
        Step 5: Remove Emojis from Text
          To remove emojis from a string, use the removeEmojis method.
      
            const emojiText = "Hello 😊 world 🌍";
            const noEmojis = transliterator.removeEmojis(emojiText);
            console.log(noEmojis);  // Output: "Hello world"
      
      
        Step 6: Use It in a Real Scenario (Example: Slug Sanitization)
          If you're working with form fields or user input that needs to be sanitized, such as a URL slug, here’s how you can integrate it:
      
            setSlug(event: Event) {
              const slug = (event.target as HTMLInputElement).value;
      
              // Normalize the slug to remove special characters
              const normalizedSlug = transliterator.normalizeString(slug);
      
              // Remove emojis from the slug
              const sanitizedSlug = transliterator.removeEmojis(normalizedSlug);
      
              // Set the sanitized value in your form control
              this.form?.controls['url'].setValue(sanitizedSlug.trim().toLowerCase());
            }