/toUnicodeVariant

Small javascript function to convert a string into different kind of ๐’–๐’๐’Š๐’„๐’๐’…๐’† variants

Primary LanguageJavaScriptMIT LicenseMIT

toUnicodeVariant

Javascript function to convert a string into different kind of โ“คโ“โ“˜โ“’โ“žโ““โ“” variants. Originally created to show some "cool" styled text in the browsers built-in alert(), prompt() and confirm() dialogs.

Usage: toUnicodeVariant(string, variant, flags)

Variant Alias Description Example
monospace m Monospace ๐š–๐š˜๐š—๐š˜๐šœ๐š™๐šŠ๐šŒ๐šŽ
bold b Bold text ๐›๐จ๐ฅ๐
italic if Italic text ๐‘–๐‘ก๐‘Ž๐‘™๐‘–๐‘
bold italic bi bold+italic text ๐’ƒ๐’๐’๐’… ๐’Š๐’•๐’‚๐’๐’Š๐’„
script c Handwriting style ๐“ˆ๐’ธ๐“‡๐’พ๐“…๐“‰
bold script bc Bolder handwriting ๐“ซ๐“ธ๐“ต๐“ญ ๐“ผ๐“ฌ๐“ป๐“ฒ๐“น๐“ฝ
gothic g Gothic (fraktur) ๐”ค๐”ฌ๐”ฑ๐”ฅ๐”ฆ๐” 
gothic bold gb Gothic in bold ๐–Œ๐–”๐–™๐–๐–Ž๐–ˆ ๐–‡๐–”๐–‘๐–‰
doublestruck d Outlined text ๐••๐• ๐•ฆ๐•“๐•๐•–๐•ค๐•ฅ๐•ฃ๐•ฆ๐•”๐•œ
๐—Œ๐–บ๐—‡๐—Œ s Sans-serif style ๐—Œ๐–บ๐—‡๐—Œ
bold ๐—Œ๐–บ๐—‡๐—Œ bs Bold sans-serif ๐—ฏ๐—ผ๐—น๐—ฑ ๐˜€๐—ฎ๐—ป๐˜€
italic ๐—Œ๐–บ๐—‡๐—Œ is Italic sans-serif ๐˜ช๐˜ต๐˜ข๐˜ญ๐˜ช๐˜ค ๐˜ด๐˜ข๐˜ฏ๐˜ด
bold italic sans bis Bold italic sans-serif ๐™—๐™ค๐™ก๐™™ ๐™ž๐™ฉ๐™–๐™ก๐™ž๐™˜ ๐™จ๐™–๐™ฃ๐™จ
circled o Letters within circles โ“’โ“˜โ“กโ“’โ“›โ“”โ““
paranthesis p Letters within paranthesis โ’ซโ’œโ’ญโ’ โ’ฉโ’ฏโ’ฃโ’ โ’ฎโ’ค
fullwidth w Wider monospace font ๏ฝ†๏ฝ•๏ฝŒ๏ฝŒ๏ฝ—๏ฝ‰๏ฝ„๏ฝ”๏ฝˆ

Besides that, the text can be enriched with underline or strike (or both) through the flags param:

Variant Flags Example
gothic underline ๐”คฬฒ๐”ฌฬฒ๐”ฑฬฒ๐”ฅฬฒ๐”ฆฬฒ๐” ฬฒ
paranthesis strike ๐š™ฬถ๐šŠฬถ๐š›ฬถ๐šŠฬถ๐š—ฬถ๐šฬถ๐š‘ฬถ๐šŽฬถ๐šœฬถ๐š’ฬถ๐šœฬถ

Example

To show some underlined text in a standard alert() box :

alert('Really need to alert some '+toUnicodeVariant('underlined', 'bold sans', 'underline')+' text');

Would look like this in a browser (here Chrome on Ubuntu) :

alt text

Notes

  • There is no support for special chars such as &, % and so on (yet, could be implemented where unicode support it)
  • Not all combinations of variants and flags is guaranteed to work. It is try and error.
  • Some variants does not support numbers (or I have missed them) some variants does not support capital or small letters (fixed for some)

Raise an issue if you discover major flaws (or minor flaws as well). You are also more than welcome to suggest other cool unicode variants this function could support.

This work was triggered by the dare need of underlined text in browser dialogs. The Stack Overflow question https://stackoverflow.com/questions/17470817/format-the-text-in-javascript-alert-box pointed me to the right direction, even though none of the answers were actual useable.