toUnicodeVariant

Javascript function to convert a string into different kind of โ“คโ“โ“˜โ“’โ“žโ““โ“” variants.

browser

<script src="path/to/toUnicodeVariant.js"></script>

nodejs

const toUnicodeVariant = require('path/to/toUnicodeVariant.js') 

usage

toUnicodeVariant(string, variant, flags)
...
toUnicodeVariant('monospace', 'm') //like first row below 
VariantAliasDescriptionExample
monospacemMonospace๐š–๐š˜๐š—๐š˜๐šœ๐š™๐šŠ๐šŒ๐šŽ
boldbBold text๐›๐จ๐ฅ๐
italiciItalic text๐‘–๐‘ก๐‘Ž๐‘™๐‘–๐‘
bold italicbibold+italic text๐’ƒ๐’๐’๐’… ๐’Š๐’•๐’‚๐’๐’Š๐’„
scriptcHandwriting style๐“ˆ๐’ธ๐“‡๐’พ๐“…๐“‰
bold scriptbcBolder handwriting๐“ซ๐“ธ๐“ต๐“ญ ๐“ผ๐“ฌ๐“ป๐“ฒ๐“น๐“ฝ
gothicgGothic (fraktur)๐”ค๐”ฌ๐”ฑ๐”ฅ๐”ฆ๐” 
gothic boldgbGothic in bold๐–Œ๐–”๐–™๐–๐–Ž๐–ˆ ๐–‡๐–”๐–‘๐–‰
doublestruckdOutlined text๐••๐• ๐•ฆ๐•“๐•๐•–๐•ค๐•ฅ๐•ฃ๐•ฆ๐•”๐•œ
๐—Œ๐–บ๐—‡๐—ŒsSans-serif style๐—Œ๐–บ๐—‡๐—Œ
bold ๐—Œ๐–บ๐—‡๐—ŒbsBold sans-serif๐—ฏ๐—ผ๐—น๐—ฑ ๐˜€๐—ฎ๐—ป๐˜€
italic ๐—Œ๐–บ๐—‡๐—ŒisItalic sans-serif๐˜ช๐˜ต๐˜ข๐˜ญ๐˜ช๐˜ค ๐˜ด๐˜ข๐˜ฏ๐˜ด
bold italic sansbisBold italic sans-serif๐™—๐™ค๐™ก๐™™ ๐™ž๐™ฉ๐™–๐™ก๐™ž๐™˜ ๐™จ๐™–๐™ฃ๐™จ
circledoLetters within circlesโ“’โ“˜โ“กโ“’โ“›โ“”โ““
circled negativeon-- negative๐Ÿ…’๐Ÿ…˜๐Ÿ…ก๐Ÿ…’๐Ÿ…›๐Ÿ…”๐Ÿ…“
squaredqLetters within squares๐Ÿ…‚๐Ÿ…€๐Ÿ…„๐Ÿ„ฐ๐Ÿ…๐Ÿ„ด๐Ÿ„ณ
squared negativeqn-- negative๐Ÿ†‚๐Ÿ†€๐Ÿ†„๐Ÿ…ฐ๐Ÿ†๐Ÿ…ด๐Ÿ…ณ
paranthesispLetters within paranthesisโ’ซโ’œโ’ญโ’ โ’ฉโ’ฏโ’ฃโ’ โ’ฎโ’ค
fullwidthwWider monospace font๏ฝ†๏ฝ•๏ฝŒ๏ฝŒ๏ฝ—๏ฝ‰๏ฝ„๏ฝ”๏ฝˆ

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

toUnicodeVariant('gothic', 'g', 'underline')
VariantFlagsExample
gothicunderline๐”คฬฒ๐”ฌฬฒ๐”ฑฬฒ๐”ฅฬฒ๐”ฆฬฒ๐” ฬฒ
doublestruckstrike๐”ธฬถ๐”นฬถโ„‚ฬถ๐”ปฬถ๐”ผฬถ๐”ฝฬถ๐”พฬถโ„ฬถ๐•€ฬถ๐•ฬถ๐•‚ฬถ๐•ƒฬถ
sansu,s๐Ÿขฬฒฬถ๐Ÿฃฬฒฬถ๐Ÿคฬฒฬถ๐Ÿฅฬฒฬถ๐Ÿฆฬฒฬถ๐Ÿงฬฒฬถ๐Ÿจฬฒฬถ๐Ÿฉฬฒฬถ

Test

Browser: test/browser.html Node: test$ node node.js

Those tests show all variants and their coverage a-Z, along with flags. For reference, in Chrome (Ubuntu, 100.0.4896) variants looks like this :

Expected output

There are really difference between browsers/readers, versions and support of unicode variants. I have not figured it all out yet. Still "script" is a really headache. Best browser for supporting both variants and flags are defently Firefox.

Example

Originally created to show some "cool" styled text in the browsers built-in alert(), prompt() and confirm() dialogs. 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 older Ubuntu 16.04) :

Note: Most browsers have stopped supporting unicode in their native dialogs!

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.