This JavaScript code defines a comprehensive text transformation utility function called transformText
that can apply various transformations to a given text. The function supports a wide range of transformations, including case conversion, special character mapping, and formatting.
Here’s a high-level explanation of the main components:
Text Transformation Function:
transformText(text, transformType)
: This is the main function that takes a text
string and a transformType
string as inputs. Depending on the transformType
, the function applies a specific transformation to the text
.
Case Conversions:
sentence_case
: Converts the text to sentence case, where the first letter of each sentence is capitalized.
lower_case
: Converts all characters in the text to lower case.
upper_case
: Converts all characters in the text to upper case.
capitalized_case
: Capitalizes the first letter of each word in the text.
alternating_case
: Alternates the case of each character in the text.
title_case
: Capitalizes the first letter of each major word, while keeping common words in lower case.
inverse_case
: Inverts the case of each character in the text.
Special Case Conversions:
random_case
: Randomly changes the case of each character.
small_caps
, superscript
, wide_text
: These transformations use custom functions to convert text to small caps, superscript, or wide text formats, respectively.
Text Reversals and Flips:
reverse_text
: Reverses the order of characters in the text.
upside_down_text
: Flips the text upside down using a custom function.
Code Conversions:
morse_code_translate
and morse_code_reverse
: Convert text to Morse code and vice versa using custom functions.
binary_translate
and binary_reverse
: Convert text to binary and vice versa using custom functions.
Visual Effects:
mirror_text
: Converts text to a mirrored format using a custom function.
zalgo_text
: Adds Zalgo text effects, creating a glitchy appearance.
Formatting:
bold
, italic
, strikethrough
, underline
: Apply Markdown or HTML formatting to the text to make it bold, italicized, strikethrough, or underlined.
Special Script Conversions:
fraktur
, fraktur_bold
, squared
, squared_inverted
, circled
, circled_inverted
: These transformations use custom functions to convert text to various special scripts or character sets. << In Dev !!
Custom Mapping Functions:
Several custom functions are defined to handle specific transformations:
convertToSmallCaps
, convertToSuperscript
, convertToWideText
: Convert text to small caps, superscript, and wide text formats.
reverseText
, flipUpsideDown
, textToMorse
, morseToText
, textToBinary
, binaryToText
, mirrorText
, zalgoText
: Implement the respective transformations.
convertToSquared
, convertToSquaredInverted
, convertToCircled
, convertToCircledInverted
, convertToFraktur
, convertToFrakturBold
: Map characters to special Unicode ranges for visual effects.
Overall, this utility function provides a robust and versatile way to apply various text transformations, making it useful for web applications that require dynamic text manipulation.
The following custom functions are used to handle specific transformations. They are called internally by transformText
based on the transformType
.
convertToSmallCaps(text)
Converts text to small caps using Unicode small capital letters.
convertToSmallCaps
function: Maps each character to its small caps equivalent using a predefined map.
convertToSuperscript(text)
Converts text to superscript using Unicode superscript letters.
convertToSuperscript
function: Maps each character to its superscript equivalent using a predefined map.
convertToWideText(text)
Converts text to wide text using Unicode full-width characters.
convertToWideText
function: Maps each character to its wider equivalent using a predefined map (wideMap
).
reverseText(text)
Reverses the order of characters in the text.
reverseText
function: Reverses the order of characters in the input text.
flipUpsideDown(text)
Flips the text upside down using Unicode characters.
flipUpsideDown
function: Flips each character to its upside down equivalent using a predefined map (upsideDownMap
).
textToMorse(text)
Converts text to Morse code.
textToMorse
function: Converts text to Morse code using a predefined map (morseMap
).
morseToText(text)
Converts Morse code back to text.
morseToText
function: Converts Morse code back to text using a reverse map (morseReverseMap
).
textToBinary(text)
Converts text to binary representation.
textToBinary
function: Converts text to binary using JavaScript's charCodeAt
and toString(2)
methods.
binaryToText(text)
Converts binary representation back to text.
binaryToText
function: Converts binary back to text using JavaScript's parseInt
and fromCharCode
methods.
mirrorText(text)
Converts text to a mirrored format.
mirrorText
function: Converts text to its mirror image using a predefined mirrorMap
.
zalgoText(text)
Adds Zalgo text effects, creating a glitchy appearance.
zalgoText
function: Generates Zalgo text by appending random combining diacritical marks to each character.
convertToSquared(text)
Converts text to squared format using Unicode characters.
convertToSquared
function: Maps each alphanumeric character to its squared Unicode equivalent.
convertToSquaredInverted(text)
Converts text to squared inverted format using Unicode characters.
convertToSquaredInverted
function: Maps each alphanumeric character to its inverted squared Unicode equivalent.
convertToCircled(text)
Converts text to circled format using Unicode characters.
convertToCircledInverted
function: Maps each alphanumeric character to its circled Unicode equivalent.
convertToCircledInverted(text)
Converts text to circled inverted format using Unicode characters.
convertToSquaredInverted
function: Maps each alphanumeric character to its inverted squared Unicode equivalent.
convertToFraktur(text)
Converts text to Fraktur script using Unicode characters.
convertToFraktur
function: Converts regular Latin characters into Fraktur Unicode characters based on a mapping (frakturMap
).
transformText
function: Updated to include "Fraktur" as an option. When selected, it calls convertToFraktur
to transform the text accordingly.
TextMagiQ1.replaceText.Case_Capitalization
function: Updated to include "Fraktur" in the user prompt options.
convertToFrakturBold(text)
Converts text to bold Fraktur script using Unicode characters.
convertToFrakturBold
function: Converts regular Latin characters into Fraktur (Bold) Unicode characters based on a mapping (frakturBoldMap
).
transformText
function: Updated to include "Fraktur (Bold)" as an option. When selected, it calls convertToFrakturBold
to transform the text accordingly.
TextMagiQ1.replaceText.Case_Capitalization
function: Updated to include "Fraktur (Bold)" in the user prompt options.