Skip to content

panduankani/toUnicodeVariant

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

45 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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 
Variant Alias Description Example
monospace m Monospace ๐š–๐š˜๐š—๐š˜๐šœ๐š™๐šŠ๐šŒ๐šŽ
bold b Bold text ๐›๐จ๐ฅ๐
italic i 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 โ“’โ“˜โ“กโ“’โ“›โ“”โ““
circled negative on -- negative ๐Ÿ…’๐Ÿ…˜๐Ÿ…ก๐Ÿ…’๐Ÿ…›๐Ÿ…”๐Ÿ…“
squared q Letters within squares ๐Ÿ…‚๐Ÿ…€๐Ÿ…„๐Ÿ„ฐ๐Ÿ…๐Ÿ„ด๐Ÿ„ณ
squared negative qn -- negative ๐Ÿ†‚๐Ÿ†€๐Ÿ†„๐Ÿ…ฐ๐Ÿ†๐Ÿ…ด๐Ÿ…ณ
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 :

toUnicodeVariant('gothic', 'g', 'underline')
Variant Flags Example
gothic underline ๐”คฬฒ๐”ฌฬฒ๐”ฑฬฒ๐”ฅฬฒ๐”ฆฬฒ๐” ฬฒ
doublestruck strike ๐”ธฬถ๐”นฬถโ„‚ฬถ๐”ปฬถ๐”ผฬถ๐”ฝฬถ๐”พฬถโ„ฬถ๐•€ฬถ๐•ฬถ๐•‚ฬถ๐•ƒฬถ
sans u,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) :

alt text

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 72.9%
  • HTML 25.5%
  • Shell 1.6%